Skip to content

Commit

Permalink
support 256 colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Qix- committed Aug 8, 2017
1 parent 659ac02 commit 3297168
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/node.js
Expand Up @@ -25,6 +25,23 @@ exports.useColors = useColors;

exports.colors = [6, 2, 3, 4, 5, 1];

try {
var supportsColor = require('supports-color');
if (supportsColor && supportsColor.level >= 2) {
exports.colors = [
20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, 56, 57, 62, 63, 68, 69, 74, 75, 76, 77, 78, 79, 80, 81,
82, 83, 84, 85, 86, 87, 92, 93, 98, 99, 112, 113, 118, 119, 128, 129,
134, 135, 148, 149, 154, 155, 160, 161, 162, 163, 164, 165, 166, 167,
168, 169, 170, 171, 172, 173, 178, 179, 184, 185, 190, 191, 196, 197,
198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 214, 215,
220, 221, 226, 227
];
}
} catch (err) {
// swallow - we only care if `supports-color` is available; it doesn't have to be.
}

/**
* Build up the default `inspectOpts` object from the environment variables.
*
Expand Down Expand Up @@ -109,10 +126,11 @@ function formatArgs(args) {

if (useColors) {
var c = this.color;
var prefix = ' \u001b[3' + c + ';1m' + name + ' ' + '\u001b[0m';
var colorCode = '\u001b[3' + (c < 8 ? c : '8;5;' + c);
var prefix = ' ' + colorCode + ';1m' + name + ' ' + '\u001b[0m';

args[0] = prefix + args[0].split('\n').join('\n' + prefix);
args.push('\u001b[3' + c + 'm+' + exports.humanize(this.diff) + '\u001b[0m');
args.push(colorCode + 'm+' + exports.humanize(this.diff) + '\u001b[0m');
} else {
args[0] = new Date().toUTCString()
+ ' ' + name + ' ' + args[0];
Expand Down

0 comments on commit 3297168

Please sign in to comment.