add test content.

This commit is contained in:
Christopher Jeffrey 2013-06-09 20:41:25 -05:00
parent 07351bdcb0
commit c9d09547ac
2 changed files with 144 additions and 1 deletions

143
test/git.diff Normal file
View File

@ -0,0 +1,143 @@
diff --git a/lib/widget.js b/lib/widget.js
index 8785046..4bfefd3 100644
--- a/lib/widget.js
+++ b/lib/widget.js
@@ -511,6 +511,9 @@ Element.prototype.__defineGetter__('left', function() {
});

Element.prototype.__defineGetter__('right', function() {
+ //if (this.options.right == null && this.options.left != null) {
+ // return this.screen.cols - (this.left + this.width);
+ //}
return (this.parent.right || 0) + this.position.right;
});

@@ -532,6 +535,9 @@ Element.prototype.__defineGetter__('top', function() {
});

Element.prototype.__defineGetter__('bottom', function() {
+ //if (this.options.bottom == null && this.options.top != null) {
+ // return this.screen.rows - (this.top + this.height);
+ //}
return (this.parent.bottom || 0) + this.position.bottom;
});

@@ -671,7 +677,20 @@ Box.prototype.render = function(stop) {
var cb = this.childBase
, xxl = xl - (this.border ? 1 : 0)
, xxi;
- while (cb--) for (xxi = xi + (this.border ? 1 : 0); xxi < xxl; xxi++) ci++;
+ while (cb--) {
+ for (xxi = xi + (this.border ? 1 : 0); xxi < xxl; xxi++) {
+ if (this.content[ci] === '\n' || this.content[ci] === '\r') {
+ ci++;
+ if (!cb) break;
+ cb--;
+ } else if (this.content[ci] === '\x1b') {
+ for (; ci < this.content.length; ci++) {
+ if (this.content[ci] === 'm') break;
+ }
+ }
+ ci++;
+ }
+ }
}

var ret = {
@@ -683,6 +702,8 @@ Box.prototype.render = function(stop) {

if (stop) return ret;

+ var lastEscape, hasEscapes, c;
+
for (; yi < yl; yi++) {
if (!lines[yi]) break;
for (xi = this.left; xi < xl; xi++) {
@@ -708,22 +729,52 @@ Box.prototype.render = function(stop) {
} else {
attr = ((this.bold << 18) + (this.underline << 18)) | (this.fg << 9) | this.bg;
ch = this.content[ci++] || ' ';
+
+ // Handle escape codes.
+ // NOTE: We could also change around `attr`, that might be cleaner.
+ // NOTE: Currently, this will not work with newline handling.
+ if (lastEscape) {
+ ch = lastEscape + ch;
+ lastEscape = '';
+ }
+ if (ch === '\x1b') {
+ hasEscapes = true;
+ if (c = /^\x1b\[\d+(?:;\d+)*m/.exec(this.content.substring(ci - 1))) {
+ ci += c[0].length - 1;
+ if (!this.content[c[0].length]) {
+ // Problem: No character to put here
+ // needs to wrap around below.
+ lastEscape = c[0];
+ ch = ' ';
+ } else {
+ ch = c[0] + this.content[ci];
+ }
+ ci++;
+ }
+ }
+ if (hasEscapes && xi === xl - 1) {
+ ch += '\x1b[m';
+ }
}

- // TODO: Allow newlines.
- //if (ch === '\n' || ch === '\r') {
- // ch = ' ';
- // xl = xl - 1 - (this.border ? 1 : 0);
- // for (; xi < xl; xi++) {
- // cell = lines[yi][xi];
- // if (!cell) break;
- // if (attr !== cell[0] || ch !== cell[1]) {
- // lines[yi][xi][0] = attr;
- // lines[yi][xi][1] = ch;
- // lines[yi].dirty = true;
- // }
- // }
- //}
+ // Handle newlines.
+ if (ch === '\n' || ch === '\r') {
+ ch = ' ';
+ if (hasEscapes) ch += '\x1b[m';
+ var xxl = xl - (this.border ? 1 : 0);
+ for (; xi < xxl; xi++) {
+ attr = ((this.bold << 18) + (this.underline << 18)) | (this.fg << 9) | this.bg;
+ cell = lines[yi][xi];
+ if (!cell) break;
+ if (attr !== cell[0] || ch !== cell[1]) {
+ lines[yi][xi][0] = attr;
+ lines[yi][xi][1] = ch;
+ lines[yi].dirty = true;
+ }
+ }
+ if (this.border) xi--;
+ continue;
+ }

if (attr !== cell[0] || ch !== cell[1]) {
lines[yi][xi][0] = attr;
@@ -958,6 +1009,7 @@ List.prototype.__proto__ = ScrollableBox.prototype;
List.prototype.add = function(item) {
var self = this;

+ // TODO: Use box here and get rid of text.
var item = new Text({
screen: this.screen,
parent: this,
diff --git a/test/widget.js b/test/widget.js
index a392a0e..1e62e8c 100644
--- a/test/widget.js
+++ b/test/widget.js
@@ -136,7 +136,7 @@ var progress = new blessed.ProgressBar({

screen.append(progress);

-var lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
+var lorem = 'Lorem ipsum \x1b[41mdolor sit amet, \nconsectetur adipisicing elit, \x1b[43msed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';

var stext = new blessed.ScrollableText({
screen: screen,

View File

@ -125,7 +125,7 @@ screen.append(progress);
var lorem = 'Lorem ipsum \x1b[41mdolor sit amet, \nconsectetur adipisicing elit, \x1b[43msed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
var lorem = require('fs').readFileSync(__dirname + '/../t.log', 'utf8');
var lorem = require('fs').readFileSync(__dirname + '/git.diff', 'utf8');
//lorem = lorem.replace(/\x1b[^m]*m/g, '');