supports-color 5.1.0 → 5.5.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 +28 -23
- package/package.json +51 -51
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,17 +47,12 @@ 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
|
|
@@ -69,21 +77,23 @@ function supportsColor(stream) {
|
|
|
69
77
|
return 1;
|
|
70
78
|
}
|
|
71
79
|
|
|
72
|
-
return
|
|
80
|
+
return min;
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
if ('TEAMCITY_VERSION' in env) {
|
|
76
84
|
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
77
85
|
}
|
|
78
86
|
|
|
87
|
+
if (env.COLORTERM === 'truecolor') {
|
|
88
|
+
return 3;
|
|
89
|
+
}
|
|
90
|
+
|
|
79
91
|
if ('TERM_PROGRAM' in env) {
|
|
80
92
|
const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
81
93
|
|
|
82
94
|
switch (env.TERM_PROGRAM) {
|
|
83
95
|
case 'iTerm.app':
|
|
84
96
|
return version >= 3 ? 3 : 2;
|
|
85
|
-
case 'Hyper':
|
|
86
|
-
return 3;
|
|
87
97
|
case 'Apple_Terminal':
|
|
88
98
|
return 2;
|
|
89
99
|
// No default
|
|
@@ -94,7 +104,7 @@ function supportsColor(stream) {
|
|
|
94
104
|
return 2;
|
|
95
105
|
}
|
|
96
106
|
|
|
97
|
-
if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
107
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
98
108
|
return 1;
|
|
99
109
|
}
|
|
100
110
|
|
|
@@ -103,19 +113,14 @@ function supportsColor(stream) {
|
|
|
103
113
|
}
|
|
104
114
|
|
|
105
115
|
if (env.TERM === 'dumb') {
|
|
106
|
-
return
|
|
116
|
+
return min;
|
|
107
117
|
}
|
|
108
118
|
|
|
109
|
-
return
|
|
119
|
+
return min;
|
|
110
120
|
}
|
|
111
121
|
|
|
112
122
|
function getSupportLevel(stream) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if ('FORCE_COLOR' in env) {
|
|
116
|
-
level = (env.FORCE_COLOR.length > 0 && parseInt(env.FORCE_COLOR, 10) === 0) ? 0 : (level || 1);
|
|
117
|
-
}
|
|
118
|
-
|
|
123
|
+
const level = supportsColor(stream);
|
|
119
124
|
return translateLevel(level);
|
|
120
125
|
}
|
|
121
126
|
|
package/package.json
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
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
|
-
|
|
2
|
+
"name": "supports-color",
|
|
3
|
+
"version": "5.5.0",
|
|
4
|
+
"description": "Detect whether a terminal supports color",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "chalk/supports-color",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Sindre Sorhus",
|
|
9
|
+
"email": "sindresorhus@gmail.com",
|
|
10
|
+
"url": "sindresorhus.com"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=4"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "xo && ava"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.js",
|
|
20
|
+
"browser.js"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"color",
|
|
24
|
+
"colour",
|
|
25
|
+
"colors",
|
|
26
|
+
"terminal",
|
|
27
|
+
"console",
|
|
28
|
+
"cli",
|
|
29
|
+
"ansi",
|
|
30
|
+
"styles",
|
|
31
|
+
"tty",
|
|
32
|
+
"rgb",
|
|
33
|
+
"256",
|
|
34
|
+
"shell",
|
|
35
|
+
"xterm",
|
|
36
|
+
"command-line",
|
|
37
|
+
"support",
|
|
38
|
+
"supports",
|
|
39
|
+
"capability",
|
|
40
|
+
"detect",
|
|
41
|
+
"truecolor",
|
|
42
|
+
"16m"
|
|
43
|
+
],
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"has-flag": "^3.0.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"ava": "^0.25.0",
|
|
49
|
+
"import-fresh": "^2.0.0",
|
|
50
|
+
"xo": "^0.20.0"
|
|
51
|
+
},
|
|
52
|
+
"browser": "browser.js"
|
|
53
53
|
}
|