more efficient content scrolling.

This commit is contained in:
Christopher Jeffrey 2013-06-07 05:58:00 -05:00
parent 7fb6b2cc3b
commit 3eee2599b7

View File

@ -650,7 +650,7 @@ Box.prototype.render = function(stop) {
, cell , cell
, attr , attr
, ch , ch
, ci = 0 , ci = this.contentIndex || 0
, cl = this.content.length , cl = this.content.length
, battr , battr
, dattr , dattr
@ -681,26 +681,6 @@ Box.prototype.render = function(stop) {
} }
} }
// Scroll the content
if (this.childBase != null) {
var cb = this.childBase
, xxl = xl - (this.border ? 1 : 0)
, xxi;
while (cb--) {
for (xxi = xi + (this.border ? 1 : 0); xxi < xxl; xxi++) {
if (this.content[ci] === '\n' || this.content[ci] === '\r') {
ci++;
break;
} else if (this.content[ci] === '\x1b') {
for (; ci < this.content.length; ci++) {
if (this.content[ci] === 'm') break;
}
}
ci++;
}
}
}
var ret = { var ret = {
xi: xi, xi: xi,
xl: xl, xl: xl,
@ -819,7 +799,7 @@ Text.prototype.render = function(stop) {
, cell , cell
, attr , attr
, ch , ch
, ci = 0 , ci = this.contentIndex || 0
, cl = this.content.length , cl = this.content.length
, ended = -1 , ended = -1
, dattr , dattr
@ -1163,10 +1143,44 @@ function ScrollableText(options) {
self.screen.render(); self.screen.render();
}); });
} }
this.contentIndex = 0;
} }
ScrollableText.prototype.__proto__ = ScrollableBox.prototype; ScrollableText.prototype.__proto__ = ScrollableBox.prototype;
ScrollableText.prototype._scroll = ScrollableText.prototype.scroll;
ScrollableText.prototype.scroll = function(offset) {
var ret = this._scroll(offset);
if (this.content != null) {
var cb = this.childBase
, data = this.render(true)
, xi = data.xi
, xl = data.xl
, xxl = xl - (this.border ? 1 : 0)
, xxi
, ci = 0;
while (cb--) {
for (xxi = xi + (this.border ? 1 : 0); xxi < xxl; xxi++) {
if (this.content[ci] === '\n' || this.content[ci] === '\r') {
ci++;
break;
} else if (this.content[ci] === '\x1b') {
for (; ci < this.content.length; ci++) {
if (this.content[ci] === 'm') break;
}
}
ci++;
}
}
this.contentIndex = ci;
}
return ret;
};
/** /**
* Input * Input
*/ */