Skip to content

Commit d5854f4

Browse files
Qix-TooTallNate
authored andcommitted
support 256 colors
Closes #481.
1 parent bf88540 commit d5854f4

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/node.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ exports.useColors = useColors;
2525

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

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

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

97115
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
98-
args.push('\u001b[3' + c + 'm+' + exports.humanize(this.diff) + '\u001b[0m');
116+
args.push(colorCode + 'm+' + exports.humanize(this.diff) + '\u001b[0m');
99117
} else {
100118
args[0] = new Date().toUTCString()
101119
+ ' ' + name + ' ' + args[0];

0 commit comments

Comments
 (0)