From 82d435551799e05069a00fc7c3248e17ad98284c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 22 Jul 2015 08:32:22 -0700 Subject: [PATCH] reduce color in program._attr. --- lib/colors.js | 11 +++++++++++ lib/program.js | 2 ++ lib/widgets/screen.js | 11 ++--------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/colors.js b/lib/colors.js index 226bf55..f8a7439 100644 --- a/lib/colors.js +++ b/lib/colors.js @@ -203,6 +203,17 @@ exports.blend._cache = {}; exports._cache = {}; +exports.reduce = function(color, total) { + if (color >= 16 && total <= 16) { + color = exports.ccolors[color]; + } else if (color >= 8 && total <= 8) { + color -= 8; + } else if (color >= 2 && total <= 2) { + color %= 2; + } + return color; +}; + // XTerm Colors // These were actually tough to track down. The xterm source only uses color // keywords. The X11 source needed to be examined to find the actual values. diff --git a/lib/program.js b/lib/program.js index 48dd7ff..c61fcc8 100644 --- a/lib/program.js +++ b/lib/program.js @@ -2686,6 +2686,8 @@ Program.prototype._attr = function(param, val) { return this._attr('default ' + m[2]); } + color = colors.reduce(color, this.tput.colors); + if (color < 16 || (this.tput && this.tput.colors <= 16)) { if (m[2] === 'fg') { if (color < 8) { diff --git a/lib/widgets/screen.js b/lib/widgets/screen.js index 57532ac..ee71512 100644 --- a/lib/widgets/screen.js +++ b/lib/widgets/screen.js @@ -1336,15 +1336,8 @@ Screen.prototype.draw = function(start, end) { // this.emit('draw'); }; -Screen.prototype._reduceColor = function(col) { - if (col >= 16 && this.tput.colors <= 16) { - col = colors.ccolors[col]; - } else if (col >= 8 && this.tput.colors <= 8) { - col -= 8; - } else if (col >= 2 && this.tput.colors <= 2) { - col %= 2; - } - return col; +Screen.prototype._reduceColor = function(color) { + return colors.reduce(color, this.tput.colors); }; // Convert an SGR string to our own attribute format.