supports-color 5.0.1 → 5.4.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/index.js +30 -24
- package/package.json +2 -2
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,26 @@ function supportsColor(stream) {
|
|
|
34
47
|
return 2;
|
|
35
48
|
}
|
|
36
49
|
|
|
37
|
-
if (
|
|
38
|
-
hasFlag('colors') ||
|
|
39
|
-
hasFlag('color=true') ||
|
|
40
|
-
hasFlag('color=always')) {
|
|
41
|
-
return 1;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (stream && !stream.isTTY) {
|
|
50
|
+
if (stream && !stream.isTTY && forceColor !== true) {
|
|
45
51
|
return 0;
|
|
46
52
|
}
|
|
47
53
|
|
|
54
|
+
const min = forceColor ? 1 : 0;
|
|
55
|
+
|
|
48
56
|
if (process.platform === 'win32') {
|
|
49
57
|
// Node.js 7.5.0 is the first version of Node.js to include a patch to
|
|
50
58
|
// libuv that enables 256 color output on Windows. Anything earlier and it
|
|
51
59
|
// won't work. However, here we target Node.js 8 at minimum as it is an LTS
|
|
52
60
|
// release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
|
|
53
|
-
// release that supports 256 colors.
|
|
61
|
+
// release that supports 256 colors. Windows 10 build 14931 is the first release
|
|
62
|
+
// that supports 16m/TrueColor.
|
|
54
63
|
const osRelease = os.release().split('.');
|
|
55
64
|
if (
|
|
56
65
|
Number(process.versions.node.split('.')[0]) >= 8 &&
|
|
57
66
|
Number(osRelease[0]) >= 10 &&
|
|
58
67
|
Number(osRelease[2]) >= 10586
|
|
59
68
|
) {
|
|
60
|
-
return 2;
|
|
69
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
return 1;
|
|
@@ -68,21 +77,23 @@ function supportsColor(stream) {
|
|
|
68
77
|
return 1;
|
|
69
78
|
}
|
|
70
79
|
|
|
71
|
-
return
|
|
80
|
+
return min;
|
|
72
81
|
}
|
|
73
82
|
|
|
74
83
|
if ('TEAMCITY_VERSION' in env) {
|
|
75
84
|
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
76
85
|
}
|
|
77
86
|
|
|
87
|
+
if (env.COLORTERM === 'truecolor') {
|
|
88
|
+
return 3;
|
|
89
|
+
}
|
|
90
|
+
|
|
78
91
|
if ('TERM_PROGRAM' in env) {
|
|
79
92
|
const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
80
93
|
|
|
81
94
|
switch (env.TERM_PROGRAM) {
|
|
82
95
|
case 'iTerm.app':
|
|
83
96
|
return version >= 3 ? 3 : 2;
|
|
84
|
-
case 'Hyper':
|
|
85
|
-
return 3;
|
|
86
97
|
case 'Apple_Terminal':
|
|
87
98
|
return 2;
|
|
88
99
|
// No default
|
|
@@ -102,19 +113,14 @@ function supportsColor(stream) {
|
|
|
102
113
|
}
|
|
103
114
|
|
|
104
115
|
if (env.TERM === 'dumb') {
|
|
105
|
-
return
|
|
116
|
+
return min;
|
|
106
117
|
}
|
|
107
118
|
|
|
108
|
-
return
|
|
119
|
+
return min;
|
|
109
120
|
}
|
|
110
121
|
|
|
111
122
|
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
|
-
|
|
123
|
+
const level = supportsColor(stream);
|
|
118
124
|
return translateLevel(level);
|
|
119
125
|
}
|
|
120
126
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "supports-color",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.4.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": "*",
|