supports-color 5.0.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser.js +4 -1
- package/index.js +34 -24
- package/package.json +2 -2
package/browser.js
CHANGED
package/index.js
CHANGED
|
@@ -4,6 +4,21 @@ const hasFlag = require('has-flag');
|
|
|
4
4
|
|
|
5
5
|
const env = process.env;
|
|
6
6
|
|
|
7
|
+
let forceColor;
|
|
8
|
+
if (hasFlag('no-color') ||
|
|
9
|
+
hasFlag('no-colors') ||
|
|
10
|
+
hasFlag('color=false')) {
|
|
11
|
+
forceColor = false;
|
|
12
|
+
} else if (hasFlag('color') ||
|
|
13
|
+
hasFlag('colors') ||
|
|
14
|
+
hasFlag('color=true') ||
|
|
15
|
+
hasFlag('color=always')) {
|
|
16
|
+
forceColor = true;
|
|
17
|
+
}
|
|
18
|
+
if ('FORCE_COLOR' in env) {
|
|
19
|
+
forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
7
22
|
function translateLevel(level) {
|
|
8
23
|
if (level === 0) {
|
|
9
24
|
return false;
|
|
@@ -18,9 +33,7 @@ function translateLevel(level) {
|
|
|
18
33
|
}
|
|
19
34
|
|
|
20
35
|
function supportsColor(stream) {
|
|
21
|
-
if (
|
|
22
|
-
hasFlag('no-colors') ||
|
|
23
|
-
hasFlag('color=false')) {
|
|
36
|
+
if (forceColor === false) {
|
|
24
37
|
return 0;
|
|
25
38
|
}
|
|
26
39
|
|
|
@@ -34,30 +47,30 @@ function supportsColor(stream) {
|
|
|
34
47
|
return 2;
|
|
35
48
|
}
|
|
36
49
|
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (stream && !stream.isTTY) {
|
|
50
|
+
if (stream && !stream.isTTY && forceColor !== true) {
|
|
51
|
+
// VS code debugger doesn't have isTTY set
|
|
52
|
+
if (env.VSCODE_PID) {
|
|
53
|
+
return 1;
|
|
54
|
+
}
|
|
45
55
|
return 0;
|
|
46
56
|
}
|
|
47
57
|
|
|
58
|
+
const min = forceColor ? 1 : 0;
|
|
59
|
+
|
|
48
60
|
if (process.platform === 'win32') {
|
|
49
61
|
// Node.js 7.5.0 is the first version of Node.js to include a patch to
|
|
50
62
|
// libuv that enables 256 color output on Windows. Anything earlier and it
|
|
51
63
|
// won't work. However, here we target Node.js 8 at minimum as it is an LTS
|
|
52
64
|
// release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
|
|
53
|
-
// release that supports 256 colors.
|
|
65
|
+
// release that supports 256 colors. Windows 10 build 14931 is the first release
|
|
66
|
+
// that supports 16m/TrueColor.
|
|
54
67
|
const osRelease = os.release().split('.');
|
|
55
68
|
if (
|
|
56
69
|
Number(process.versions.node.split('.')[0]) >= 8 &&
|
|
57
70
|
Number(osRelease[0]) >= 10 &&
|
|
58
71
|
Number(osRelease[2]) >= 10586
|
|
59
72
|
) {
|
|
60
|
-
return 2;
|
|
73
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
61
74
|
}
|
|
62
75
|
|
|
63
76
|
return 1;
|
|
@@ -68,21 +81,23 @@ function supportsColor(stream) {
|
|
|
68
81
|
return 1;
|
|
69
82
|
}
|
|
70
83
|
|
|
71
|
-
return
|
|
84
|
+
return min;
|
|
72
85
|
}
|
|
73
86
|
|
|
74
87
|
if ('TEAMCITY_VERSION' in env) {
|
|
75
88
|
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
76
89
|
}
|
|
77
90
|
|
|
91
|
+
if (env.COLORTERM === 'truecolor') {
|
|
92
|
+
return 3;
|
|
93
|
+
}
|
|
94
|
+
|
|
78
95
|
if ('TERM_PROGRAM' in env) {
|
|
79
96
|
const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
80
97
|
|
|
81
98
|
switch (env.TERM_PROGRAM) {
|
|
82
99
|
case 'iTerm.app':
|
|
83
100
|
return version >= 3 ? 3 : 2;
|
|
84
|
-
case 'Hyper':
|
|
85
|
-
return 3;
|
|
86
101
|
case 'Apple_Terminal':
|
|
87
102
|
return 2;
|
|
88
103
|
// No default
|
|
@@ -102,19 +117,14 @@ function supportsColor(stream) {
|
|
|
102
117
|
}
|
|
103
118
|
|
|
104
119
|
if (env.TERM === 'dumb') {
|
|
105
|
-
return
|
|
120
|
+
return min;
|
|
106
121
|
}
|
|
107
122
|
|
|
108
|
-
return
|
|
123
|
+
return min;
|
|
109
124
|
}
|
|
110
125
|
|
|
111
126
|
function getSupportLevel(stream) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if ('FORCE_COLOR' in env) {
|
|
115
|
-
level = (env.FORCE_COLOR.length > 0 && parseInt(env.FORCE_COLOR, 10) === 0) ? 0 : (level || 1);
|
|
116
|
-
}
|
|
117
|
-
|
|
127
|
+
const level = supportsColor(stream);
|
|
118
128
|
return translateLevel(level);
|
|
119
129
|
}
|
|
120
130
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "supports-color",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Detect whether a terminal supports color",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "chalk/supports-color",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"16m"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"has-flag": "^
|
|
45
|
+
"has-flag": "^3.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"ava": "*",
|