From ac10c408e3f93558eab20dc5c3533b692f4166a7 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 6 Jun 2013 05:19:52 -0500 Subject: [PATCH] optimize rendering even more. --- lib/widget.js | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index b0bdec7..b15da95 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -197,10 +197,16 @@ Screen.prototype.alloc = function() { this.lines[y] = []; for (x = 0; x < this.cols; x++) { this.lines[y][x] = [this.dattr, ' ']; - //this.lines[y][x].dirty = true; } this.lines[y].dirty = true; } + this.olines = []; + for (y = 0; y < this.rows; y++) { + this.olines[y] = []; + for (x = 0; x < this.cols; x++) { + this.olines[y][x] = []; + } + } }; Screen.prototype.render = function() { @@ -222,11 +228,18 @@ Screen.prototype.draw = function(start, end) { , bgColor , flags; + var lx = -1 + , ly = -1 + , o; + this.program.saveCursor(); + //this.program.write('\x1b[1;1H'); for (y = start; y <= end; y++) { line = this.lines[y]; + o = this.olines[y]; + // TODO: Possibly get rid of .dirty altogether. if (!line.dirty) continue; line.dirty = false; @@ -237,6 +250,21 @@ Screen.prototype.draw = function(start, end) { data = line[x][0]; ch = line[x][1]; + if (data === o[x][0] && ch === o[x][1]) { + if (lx === -1) { + lx = x; + ly = y; + } + continue; + } else if (lx !== -1) { + out += y === ly + ? '\x1b[' + (x - lx) + 'C' + : '\x1b[' + (y + 1) + ';' + (x + 1) + 'H'; + lx = -1, ly = -1; + } + o[x][0] = data; + o[x][1] = ch; + if (data !== attr) { if (attr !== this.dattr) { out += '\x1b[m'; @@ -315,7 +343,8 @@ Screen.prototype.draw = function(start, end) { //this.program.move(y + 1, 1); //this.program.write(out); - this.program.write('\x1b[' + (y + 1) + ';1H' + out); + if (out) this.program.write('\x1b[' + (y + 1) + ';1H' + out); + //if (out) this.program.write(lx !== -1 ? out : '\x1b[' + (y + 1) + ';1H' + out); } this.program.restoreCursor(); @@ -651,7 +680,6 @@ Box.prototype.render = function() { // lines[yi][xi][0] = attr; // lines[yi][xi][1] = ch; // lines[yi].dirty = true; - // //lines[yi][xi].dirty = true; // } // } //} @@ -660,7 +688,6 @@ Box.prototype.render = function() { lines[yi][xi][0] = attr; lines[yi][xi][1] = ch; lines[yi].dirty = true; - //lines[yi][xi].dirty = true; } } } @@ -764,7 +791,6 @@ Text.prototype.render = function() { // lines[yi][xi][0] = attr; // lines[yi][xi][1] = ch; // lines[yi].dirty = true; - // //lines[yi][xi].dirty = true; // } // } //} @@ -773,7 +799,6 @@ Text.prototype.render = function() { lines[yi][xi][0] = attr; lines[yi][xi][1] = ch; lines[yi].dirty = true; - //lines[yi][xi].dirty = true; } } } @@ -1086,7 +1111,6 @@ ProgressBar.prototype.render = function() { lines[y][x][0] = attr; lines[y][x][1] = ch; lines[y].dirty = true; - //lines[y][x].dirty = true; } } }