supports-color 3.2.3 → 4.2.1
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 +45 -14
- package/license +4 -16
- package/package.json +8 -21
- package/readme.md +13 -7
package/index.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
const os = require('os');
|
|
3
|
+
const hasFlag = require('has-flag');
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
const env = process.env;
|
|
6
|
+
|
|
7
|
+
const support = level => {
|
|
5
8
|
if (level === 0) {
|
|
6
9
|
return false;
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
return {
|
|
10
|
-
level
|
|
13
|
+
level,
|
|
11
14
|
hasBasic: true,
|
|
12
15
|
has256: level >= 2,
|
|
13
16
|
has16m: level >= 3
|
|
14
17
|
};
|
|
15
18
|
};
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
let supportLevel = (() => {
|
|
18
21
|
if (hasFlag('no-color') ||
|
|
19
22
|
hasFlag('no-colors') ||
|
|
20
23
|
hasFlag('color=false')) {
|
|
@@ -43,42 +46,70 @@ var supportLevel = (function () {
|
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
if (process.platform === 'win32') {
|
|
49
|
+
// Node.js 7.5.0 is the first version of Node.js to include a patch to
|
|
50
|
+
// libuv that enables 256 color output on Windows. Anything earlier and it
|
|
51
|
+
// won't work. However, here we target Node.js 8 at minimum as it is an LTS
|
|
52
|
+
// release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
|
|
53
|
+
// release that supports 256 colors.
|
|
54
|
+
const osRelease = os.release().split('.');
|
|
55
|
+
if (
|
|
56
|
+
Number(process.versions.node.split('.')[0]) >= 8 &&
|
|
57
|
+
Number(osRelease[0]) >= 10 &&
|
|
58
|
+
Number(osRelease[2]) >= 10586
|
|
59
|
+
) {
|
|
60
|
+
return 2;
|
|
61
|
+
}
|
|
62
|
+
|
|
46
63
|
return 1;
|
|
47
64
|
}
|
|
48
65
|
|
|
49
|
-
if ('CI' in
|
|
50
|
-
if ('TRAVIS' in
|
|
66
|
+
if ('CI' in env) {
|
|
67
|
+
if ('TRAVIS' in env || env.CI === 'Travis' || 'CIRCLECI' in env) {
|
|
51
68
|
return 1;
|
|
52
69
|
}
|
|
53
70
|
|
|
54
71
|
return 0;
|
|
55
72
|
}
|
|
56
73
|
|
|
57
|
-
if ('TEAMCITY_VERSION' in
|
|
58
|
-
return
|
|
74
|
+
if ('TEAMCITY_VERSION' in env) {
|
|
75
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if ('TERM_PROGRAM' in env) {
|
|
79
|
+
const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
80
|
+
|
|
81
|
+
switch (env.TERM_PROGRAM) {
|
|
82
|
+
case 'iTerm.app':
|
|
83
|
+
return version >= 3 ? 3 : 2;
|
|
84
|
+
case 'Hyper':
|
|
85
|
+
return 3;
|
|
86
|
+
case 'Apple_Terminal':
|
|
87
|
+
return 2;
|
|
88
|
+
// No default
|
|
89
|
+
}
|
|
59
90
|
}
|
|
60
91
|
|
|
61
|
-
if (/^(screen|xterm)-256(?:color)?/.test(
|
|
92
|
+
if (/^(screen|xterm)-256(?:color)?/.test(env.TERM)) {
|
|
62
93
|
return 2;
|
|
63
94
|
}
|
|
64
95
|
|
|
65
|
-
if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(
|
|
96
|
+
if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
66
97
|
return 1;
|
|
67
98
|
}
|
|
68
99
|
|
|
69
|
-
if ('COLORTERM' in
|
|
100
|
+
if ('COLORTERM' in env) {
|
|
70
101
|
return 1;
|
|
71
102
|
}
|
|
72
103
|
|
|
73
|
-
if (
|
|
104
|
+
if (env.TERM === 'dumb') {
|
|
74
105
|
return 0;
|
|
75
106
|
}
|
|
76
107
|
|
|
77
108
|
return 0;
|
|
78
109
|
})();
|
|
79
110
|
|
|
80
|
-
if (
|
|
81
|
-
supportLevel = 1;
|
|
111
|
+
if ('FORCE_COLOR' in env) {
|
|
112
|
+
supportLevel = parseInt(env.FORCE_COLOR, 10) === 0 ? 0 : (supportLevel || 1);
|
|
82
113
|
}
|
|
83
114
|
|
|
84
115
|
module.exports = process && support(supportLevel);
|
package/license
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
3
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
4
4
|
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
11
6
|
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
14
8
|
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "supports-color",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "Detect whether a terminal supports color",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "chalk/supports-color",
|
|
@@ -9,18 +9,11 @@
|
|
|
9
9
|
"email": "sindresorhus@gmail.com",
|
|
10
10
|
"url": "sindresorhus.com"
|
|
11
11
|
},
|
|
12
|
-
"maintainers": [
|
|
13
|
-
"Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)",
|
|
14
|
-
"Joshua Boy Nicolai Appelman <joshua@jbna.nl> (jbna.nl)",
|
|
15
|
-
"JD Ballard <i.am.qix@gmail.com> (github.com/qix-)"
|
|
16
|
-
],
|
|
17
|
-
"browser": "browser.js",
|
|
18
12
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
13
|
+
"node": ">=4"
|
|
20
14
|
},
|
|
21
15
|
"scripts": {
|
|
22
|
-
"test": "xo &&
|
|
23
|
-
"travis": "mocha"
|
|
16
|
+
"test": "xo && ava"
|
|
24
17
|
},
|
|
25
18
|
"files": [
|
|
26
19
|
"index.js",
|
|
@@ -46,21 +39,15 @@
|
|
|
46
39
|
"capability",
|
|
47
40
|
"detect",
|
|
48
41
|
"truecolor",
|
|
49
|
-
"16m"
|
|
50
|
-
"million"
|
|
42
|
+
"16m"
|
|
51
43
|
],
|
|
52
44
|
"dependencies": {
|
|
53
|
-
"has-flag": "^
|
|
45
|
+
"has-flag": "^2.0.0"
|
|
54
46
|
},
|
|
55
47
|
"devDependencies": {
|
|
56
|
-
"
|
|
57
|
-
"
|
|
48
|
+
"ava": "*",
|
|
49
|
+
"import-fresh": "^2.0.0",
|
|
58
50
|
"xo": "*"
|
|
59
51
|
},
|
|
60
|
-
"
|
|
61
|
-
"envs": [
|
|
62
|
-
"node",
|
|
63
|
-
"mocha"
|
|
64
|
-
]
|
|
65
|
-
}
|
|
52
|
+
"browser": "browser.js"
|
|
66
53
|
}
|
package/readme.md
CHANGED
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
## Install
|
|
7
7
|
|
|
8
8
|
```
|
|
9
|
-
$ npm install
|
|
9
|
+
$ npm install supports-color
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
15
|
```js
|
|
16
|
-
|
|
16
|
+
const supportsColor = require('supports-color');
|
|
17
17
|
|
|
18
18
|
if (supportsColor) {
|
|
19
19
|
console.log('Terminal supports color');
|
|
@@ -31,22 +31,22 @@ if (supportsColor.has16m) {
|
|
|
31
31
|
|
|
32
32
|
## API
|
|
33
33
|
|
|
34
|
-
Returns an `
|
|
34
|
+
Returns an `Object`, or `false` if color is not supported.
|
|
35
35
|
|
|
36
36
|
The returned object 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
|
|
40
|
-
- `.level = 3` and `.has16m = true`: 16 million
|
|
40
|
+
- `.level = 3` and `.has16m = true`: Truecolor support (16 million colors)
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
## Info
|
|
44
44
|
|
|
45
45
|
It obeys the `--color` and `--no-color` CLI flags.
|
|
46
46
|
|
|
47
|
-
For situations where using `--color` is not possible, add
|
|
47
|
+
Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, add the environment variable `FORCE_COLOR=1` to forcefully enable color or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
|
|
48
48
|
|
|
49
|
-
Explicit 256/
|
|
49
|
+
Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
## Related
|
|
@@ -55,6 +55,12 @@ Explicit 256/truecolor mode can be enabled using the `--color=256` and `--color=
|
|
|
55
55
|
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
|
|
56
56
|
|
|
57
57
|
|
|
58
|
+
## Maintainers
|
|
59
|
+
|
|
60
|
+
- [Sindre Sorhus](https://github.com/sindresorhus)
|
|
61
|
+
- [Josh Junon](https://github.com/qix-)
|
|
62
|
+
|
|
63
|
+
|
|
58
64
|
## License
|
|
59
65
|
|
|
60
|
-
MIT
|
|
66
|
+
MIT
|