supports-color 5.2.0 → 6.0.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.
Files changed (3) hide show
  1. package/index.js +22 -14
  2. package/package.json +51 -51
  3. package/readme.md +15 -1
package/index.js CHANGED
@@ -2,21 +2,27 @@
2
2
  const os = require('os');
3
3
  const hasFlag = require('has-flag');
4
4
 
5
- const env = process.env;
5
+ const {env} = process;
6
6
 
7
7
  let forceColor;
8
8
  if (hasFlag('no-color') ||
9
9
  hasFlag('no-colors') ||
10
10
  hasFlag('color=false')) {
11
- forceColor = false;
11
+ forceColor = 0;
12
12
  } else if (hasFlag('color') ||
13
13
  hasFlag('colors') ||
14
14
  hasFlag('color=true') ||
15
15
  hasFlag('color=always')) {
16
- forceColor = true;
16
+ forceColor = 1;
17
17
  }
18
18
  if ('FORCE_COLOR' in env) {
19
- forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
19
+ if (env.FORCE_COLOR === true || env.FORCE_COLOR === 'true') {
20
+ forceColor = 1;
21
+ } else if (env.FORCE_COLOR === false || env.FORCE_COLOR === 'false') {
22
+ forceColor = 0;
23
+ } else {
24
+ forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
25
+ }
20
26
  }
21
27
 
22
28
  function translateLevel(level) {
@@ -33,7 +39,7 @@ function translateLevel(level) {
33
39
  }
34
40
 
35
41
  function supportsColor(stream) {
36
- if (forceColor === false) {
42
+ if (forceColor === 0) {
37
43
  return 0;
38
44
  }
39
45
 
@@ -47,11 +53,15 @@ function supportsColor(stream) {
47
53
  return 2;
48
54
  }
49
55
 
50
- if (stream && !stream.isTTY && forceColor !== true) {
56
+ if (stream && !stream.isTTY && forceColor === undefined) {
51
57
  return 0;
52
58
  }
53
59
 
54
- const min = forceColor ? 1 : 0;
60
+ const min = forceColor || 0;
61
+
62
+ if (env.TERM === 'dumb') {
63
+ return min;
64
+ }
55
65
 
56
66
  if (process.platform === 'win32') {
57
67
  // Node.js 7.5.0 is the first version of Node.js to include a patch to
@@ -84,14 +94,16 @@ function supportsColor(stream) {
84
94
  return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
85
95
  }
86
96
 
97
+ if (env.COLORTERM === 'truecolor') {
98
+ return 3;
99
+ }
100
+
87
101
  if ('TERM_PROGRAM' in env) {
88
102
  const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
89
103
 
90
104
  switch (env.TERM_PROGRAM) {
91
105
  case 'iTerm.app':
92
106
  return version >= 3 ? 3 : 2;
93
- case 'Hyper':
94
- return 3;
95
107
  case 'Apple_Terminal':
96
108
  return 2;
97
109
  // No default
@@ -102,7 +114,7 @@ function supportsColor(stream) {
102
114
  return 2;
103
115
  }
104
116
 
105
- if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
117
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
106
118
  return 1;
107
119
  }
108
120
 
@@ -110,10 +122,6 @@ function supportsColor(stream) {
110
122
  return 1;
111
123
  }
112
124
 
113
- if (env.TERM === 'dumb') {
114
- return min;
115
- }
116
-
117
125
  return min;
118
126
  }
119
127
 
package/package.json CHANGED
@@ -1,53 +1,53 @@
1
1
  {
2
- "name": "supports-color",
3
- "version": "5.2.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": "*",
49
- "import-fresh": "^2.0.0",
50
- "xo": "*"
51
- },
52
- "browser": "browser.js"
2
+ "name": "supports-color",
3
+ "version": "6.0.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": ">=6"
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.23.0"
51
+ },
52
+ "browser": "browser.js"
53
53
  }
package/readme.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  > Detect whether a terminal supports color
4
4
 
5
+ ---
6
+
7
+ <div align="center">
8
+ <b>
9
+ <a href="https://tidelift.com/subscription/pkg/npm-supports-color?utm_source=npm-supports-color&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
10
+ </b>
11
+ <br>
12
+ <sub>
13
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
14
+ </sub>
15
+ </div>
16
+
17
+ ---
18
+
5
19
 
6
20
  ## Install
7
21
 
@@ -44,7 +58,7 @@ The `stdout`/`stderr` objects specifies a level of support for color through a `
44
58
 
45
59
  It obeys the `--color` and `--no-color` CLI flags.
46
60
 
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.
61
+ For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1), `FORCE_COLOR=2` (level 2), or `FORCE_COLOR=3` (level 3) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
48
62
 
49
63
  Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
50
64