From 761e2a2aafb02445fa15f62973aa10df199a6ebd Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 13 Jun 2013 01:33:10 -0500 Subject: [PATCH] insert and delete line functions utilizing csr. --- lib/program.js | 1 + lib/widget.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/lib/program.js b/lib/program.js index c2fc488..c792386 100644 --- a/lib/program.js +++ b/lib/program.js @@ -2031,6 +2031,7 @@ Program.prototype.setMouse = function(opt) { // dow) (DECSTBM). // CSI ? Pm r Program.prototype.decstbm = +Program.prototype.csr = Program.prototype.setScrollRegion = function(top, bottom) { this.scrollTop = (top || 1) - 1; this.scrollBottom = (bottom || this.rows) - 1; diff --git a/lib/widget.js b/lib/widget.js index e024548..e2c1a8a 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -270,6 +270,66 @@ Screen.prototype.render = function() { this.emit('draw'); }; +Screen.prototype.blankLine = function(ch, dirty) { + var out = []; + for (var y = 0; y < this.rows; y++) { + out[y] = []; + for (var x = 0; x < this.cols; x++) { + out[y][x] = [this.dattr, ch || ' ']; + } + out[y].dirty = dirty; + } + return out; +}; + +Screen.prototype.insertLine = function(n, y, top, bottom) { + this.program.csr(top + 1, bottom + 1); + this.program.cup(y + 1, 1); + this.program.il(1); + this.program.csr(1, this.height - 1 + 1); + this.program.cup(y + 1, 1); + + if (n < 1) n = 1; + + var j = this.rows - 1 - bottom; + j = this.rows - 1 - j + 1; + + while (n--) { + this.lines.splice(y, 0, this.blankLine()); + this.lines.splice(j, 1); + this.olines.splice(y, 0, this.blankLine()); + this.olines.splice(j, 1); + } +}; + +Screen.prototype.deleteLine = function(n, y, top, bottom) { + this.program.csr(top + 1, bottom + 1); + this.program.cup(y + 1, 1); + this.program.dl(1); + this.program.csr(1, this.height - 1 + 1); + this.program.cup(y + 1, 1); + + if (n < 1) n = 1; + + var j = this.rows - 1 - bottom; + j = this.rows - 1 - j + 1; + + while (n--) { + this.lines.splice(j, 0, this.blankLine()); + this.lines.splice(y, 1); + this.olines.splice(j, 0, this.blankLine()); + this.olines.splice(y, 1); + } +}; + +Screen.prototype.insertBottom = function(top, bottom) { + return this.deleteLine(1, top, top, bottom); +}; + +Screen.prototype.insertTop = function(top, bottom) { + return this.insertLine(1, top, top, bottom); +}; + Screen.prototype.draw = function(start, end) { var x , y