minor changes to sgr handling.

This commit is contained in:
Christopher Jeffrey 2013-06-14 00:38:36 -05:00
parent 9eaf45acab
commit 268fbfef6a
1 changed files with 16 additions and 5 deletions

View File

@ -562,7 +562,6 @@ function Element(options) {
// this.position.padding = options.padding || 0;
// this.position.margin = options.margin || 0;
this.hidden = options.hidden || false;
this.fg = convert(options.fg);
this.bg = convert(options.bg);
this.bold = options.bold ? 1 : 0;
@ -571,10 +570,12 @@ function Element(options) {
this.inverse = options.inverse ? 8 : 0;
this.invisible = options.invisible ? 16 : 0;
this.hidden = options.hidden || false;
this.fixed = options.fixed || false;
this.align = options.align || 'left';
this.shrink = options.shrink;
this.padding = options.padding || 0;
this.border = options.border;
if (this.border) {
this.border.type = this.border.type || 'bg';
@ -1082,7 +1083,7 @@ Box.prototype.render = function(stop) {
var cci = ci - (this._clines[this.childBase - 1].length + 1);
for (; cci < ci; cci++) {
if (content[cci] === '\x1b') {
if (c = /^\x1b\[(?:\d+(?:;\d+)*)?m/.exec(content.substring(cci))) {
if (c = /^\x1b\[[\d;]*m/.exec(content.substring(cci))) {
attr = attrCode(c[0], attr);
cci += c[0].length - 1;
}
@ -1114,11 +1115,13 @@ outer:
// Handle escape codes.
while (ch === '\x1b') {
if (c = /^\x1b\[(?:\d+(?:;\d+)*)?m/.exec(content.substring(ci - 1))) {
if (c = /^\x1b\[[\d;]*m/.exec(content.substring(ci - 1))) {
ci += c[0].length - 1;
attr = attrCode(c[0], attr);
ch = content[ci] || ' ';
ci++;
} else {
break;
}
}
@ -1324,11 +1327,13 @@ Text.prototype.render = function(stop) {
// Handle escape codes.
while (ch === '\x1b') {
if (c = /^\x1b\[(?:\d+(?:;\d+)*)?m/.exec(content.substring(ci - 1))) {
if (c = /^\x1b\[[\d;]*m/.exec(content.substring(ci - 1))) {
ci += c[0].length - 1;
attr = attrCode(c[0], attr);
ch = content[ci];
ci++;
} else {
break;
}
}
@ -1880,7 +1885,10 @@ function attrCode(code, cur) {
var bg = cur & 0x1ff;
var c, i;
code = /^\x1b\[([^m]*)m$/.exec(code)[1].split(';');
code = /^\x1b\[([\d;]*)m$/.exec(code);
if (!code) return cur;
code = code[1].split(';');
if (!code[0]) code[0] = '0';
for (i = 0; i < code.length; i++) {
@ -2012,6 +2020,9 @@ function wrapContent(content, width) {
while (line.length > width) {
for (i = 0, total = 0; i < line.length; i++) {
while (line[i] === '\x1b') {
//var c = /^\x1b\[[\d;]*m/.exec(line.substring(i));
//if (!c) { i++; break; }
//i += c[0].length;
while (line[i] && line[i++] !== 'm');
}
if (!line[i]) break;