Skip to content

Commit 1269f1d

Browse files
committed
support 256 colors
1 parent 659ac02 commit 1269f1d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/node.js

Lines changed: 18 additions & 1 deletion
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
*
@@ -109,7 +126,7 @@ function formatArgs(args) {
109126

110127
if (useColors) {
111128
var c = this.color;
112-
var prefix = ' \u001b[3' + c + ';1m' + name + ' ' + '\u001b[0m';
129+
var prefix = ' \u001b[3' + (c <= 16 ? c : '8;5;' + c) + ';1m' + name + ' ' + '\u001b[0m';
113130

114131
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
115132
args.push('\u001b[3' + c + 'm+' + exports.humanize(this.diff) + '\u001b[0m');

0 commit comments

Comments
 (0)