From 927c40d2f35c5603fffe8425a95ab26278e24733 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 28 Jul 2013 10:51:43 -0500 Subject: [PATCH] fix mwidth. minor. --- lib/widget.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 0a24860..822b367 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -1903,6 +1903,7 @@ Element.prototype.parseContent = function() { return true; } + // Need to calculate this every time because the default fg/bg may change. this._clines.attr = this._parseAttr(this._clines) || this._clines.attr; return false; @@ -1939,10 +1940,6 @@ Element.prototype._parseAttr = function(lines) { return; } - if (!this.scrollable) { - //return; - } - for (j = 0; j < lines.length; j++) { line = lines[j]; attrs[j] = attr; @@ -1989,7 +1986,6 @@ Element.prototype._wrapContent = function(content, width) { , fake = [] , out = [] , no = 0 - , mwidth = 0 , line , align , cap @@ -2068,7 +2064,6 @@ main: out.push(this._align(part, width, align)); ftor[no].push(out.length - 1); rtof.push(no); - if (part.length > mwidth) mwidth = part.length; // Make sure we didn't wrap the line to the very end, otherwise // we get a pointless empty line after a newline. @@ -2084,14 +2079,19 @@ main: out.push(this._align(line, width, align)); ftor[no].push(out.length - 1); rtof.push(no); - if (line.length > mwidth) mwidth = line.length; } out.rtof = rtof; out.ftor = ftor; out.fake = lines; out.real = out; - out.mwidth = mwidth; + + out.mwidth = out.reduce(function(current, line) { + line = line.replace(/\x1b\[[\d;]*m/g, ''); + return line.length > current + ? line.length + : current; + }, 0); return out; };