-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
/
Copy pathcolors.js
54 lines (51 loc) · 1.46 KB
/
colors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
let internalTTy;
function lazyInternalTTY() {
internalTTy ??= require('internal/tty');
return internalTTy;
}
module.exports = {
blue: '',
green: '',
white: '',
red: '',
gray: '',
clear: '',
reset: '',
hasColors: false,
shouldColorize(stream, ignoreTestContext = false) {
if (!ignoreTestContext && process.env.NODE_TEST_CONTEXT === 'child-v8-test-colorize') {
return lazyInternalTTY().getColorDepth() > 2;
}
if (process.env.FORCE_COLOR !== undefined) {
return lazyInternalTTY().getColorDepth() > 2;
}
return stream?.isTTY && (
typeof stream.getColorDepth === 'function' ?
stream.getColorDepth() > 2 : true);
},
refresh() {
if (module.exports.shouldColorize(process.stderr)) {
module.exports.blue = '\u001b[34m';
module.exports.green = '\u001b[32m';
module.exports.white = '\u001b[39m';
module.exports.yellow = '\u001b[33m';
module.exports.red = '\u001b[31m';
module.exports.gray = '\u001b[90m';
module.exports.clear = '\u001bc';
module.exports.reset = '\u001b[0m';
module.exports.hasColors = true;
} else {
module.exports.blue = '';
module.exports.green = '';
module.exports.white = '';
module.exports.yellow = '';
module.exports.red = '';
module.exports.gray = '';
module.exports.clear = '';
module.exports.reset = '';
module.exports.hasColors = false;
}
},
};
module.exports.refresh();