supports-color 4.4.0 → 5.1.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 +22 -11
- package/package.json +1 -1
- package/readme.md +8 -8
package/browser.js
CHANGED
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ const hasFlag = require('has-flag');
|
|
|
4
4
|
|
|
5
5
|
const env = process.env;
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
function translateLevel(level) {
|
|
8
8
|
if (level === 0) {
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
@@ -15,9 +15,9 @@ const support = level => {
|
|
|
15
15
|
has256: level >= 2,
|
|
16
16
|
has16m: level >= 3
|
|
17
17
|
};
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
function supportsColor(stream) {
|
|
21
21
|
if (hasFlag('no-color') ||
|
|
22
22
|
hasFlag('no-colors') ||
|
|
23
23
|
hasFlag('color=false')) {
|
|
@@ -41,7 +41,7 @@ let supportLevel = (() => {
|
|
|
41
41
|
return 1;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
if (
|
|
44
|
+
if (stream && !stream.isTTY) {
|
|
45
45
|
return 0;
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -50,14 +50,15 @@ let supportLevel = (() => {
|
|
|
50
50
|
// libuv that enables 256 color output on Windows. Anything earlier and it
|
|
51
51
|
// won't work. However, here we target Node.js 8 at minimum as it is an LTS
|
|
52
52
|
// release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
|
|
53
|
-
// release that supports 256 colors.
|
|
53
|
+
// release that supports 256 colors. Windows 10 build 14931 is the first release
|
|
54
|
+
// that supports 16m/TrueColor.
|
|
54
55
|
const osRelease = os.release().split('.');
|
|
55
56
|
if (
|
|
56
57
|
Number(process.versions.node.split('.')[0]) >= 8 &&
|
|
57
58
|
Number(osRelease[0]) >= 10 &&
|
|
58
59
|
Number(osRelease[2]) >= 10586
|
|
59
60
|
) {
|
|
60
|
-
return 2;
|
|
61
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
return 1;
|
|
@@ -93,7 +94,7 @@ let supportLevel = (() => {
|
|
|
93
94
|
return 2;
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
97
|
+
if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
97
98
|
return 1;
|
|
98
99
|
}
|
|
99
100
|
|
|
@@ -106,10 +107,20 @@ let supportLevel = (() => {
|
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
return 0;
|
|
109
|
-
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function getSupportLevel(stream) {
|
|
113
|
+
let level = supportsColor(stream);
|
|
110
114
|
|
|
111
|
-
if ('FORCE_COLOR' in env) {
|
|
112
|
-
|
|
115
|
+
if ('FORCE_COLOR' in env) {
|
|
116
|
+
level = (env.FORCE_COLOR.length > 0 && parseInt(env.FORCE_COLOR, 10) === 0) ? 0 : (level || 1);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return translateLevel(level);
|
|
113
120
|
}
|
|
114
121
|
|
|
115
|
-
module.exports =
|
|
122
|
+
module.exports = {
|
|
123
|
+
supportsColor: getSupportLevel,
|
|
124
|
+
stdout: getSupportLevel(process.stdout),
|
|
125
|
+
stderr: getSupportLevel(process.stderr)
|
|
126
|
+
};
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -15,25 +15,25 @@ $ npm install supports-color
|
|
|
15
15
|
```js
|
|
16
16
|
const supportsColor = require('supports-color');
|
|
17
17
|
|
|
18
|
-
if (supportsColor) {
|
|
19
|
-
console.log('Terminal supports color');
|
|
18
|
+
if (supportsColor.stdout) {
|
|
19
|
+
console.log('Terminal stdout supports color');
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
if (supportsColor.has256) {
|
|
23
|
-
console.log('Terminal supports 256 colors');
|
|
22
|
+
if (supportsColor.stdout.has256) {
|
|
23
|
+
console.log('Terminal stdout supports 256 colors');
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
if (supportsColor.has16m) {
|
|
27
|
-
console.log('Terminal supports 16 million colors (truecolor)');
|
|
26
|
+
if (supportsColor.stderr.has16m) {
|
|
27
|
+
console.log('Terminal stderr supports 16 million colors (truecolor)');
|
|
28
28
|
}
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
## API
|
|
33
33
|
|
|
34
|
-
Returns an `Object`, or `false` if color is not supported.
|
|
34
|
+
Returns an `Object` with a `stdout` and `stderr` property for testing either streams. Each property is an `Object`, or `false` if color is not supported.
|
|
35
35
|
|
|
36
|
-
The
|
|
36
|
+
The `stdout`/`stderr` objects specifies a level of support for color through a `.level` property and a corresponding flag:
|
|
37
37
|
|
|
38
38
|
- `.level = 1` and `.hasBasic = true`: Basic color support (16 colors)
|
|
39
39
|
- `.level = 2` and `.has256 = true`: 256 color support
|