supports-color 4.3.0 → 5.0.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/browser.js CHANGED
@@ -1,2 +1,5 @@
1
1
  'use strict';
2
- module.exports = false;
2
+ module.exports = {
3
+ stdout: false,
4
+ stderr: false
5
+ };
package/index.js CHANGED
@@ -4,7 +4,7 @@ const hasFlag = require('has-flag');
4
4
 
5
5
  const env = process.env;
6
6
 
7
- const support = level => {
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
- let supportLevel = (() => {
20
+ function supportsColor(stream) {
21
21
  if (hasFlag('no-color') ||
22
22
  hasFlag('no-colors') ||
23
23
  hasFlag('color=false')) {
@@ -41,15 +41,7 @@ let supportLevel = (() => {
41
41
  return 1;
42
42
  }
43
43
 
44
- if ('CI' in env) {
45
- if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env)) {
46
- return 1;
47
- }
48
-
49
- return 0;
50
- }
51
-
52
- if (process.stdout && !process.stdout.isTTY) {
44
+ if (stream && !stream.isTTY) {
53
45
  return 0;
54
46
  }
55
47
 
@@ -71,6 +63,14 @@ let supportLevel = (() => {
71
63
  return 1;
72
64
  }
73
65
 
66
+ if ('CI' in env) {
67
+ if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
68
+ return 1;
69
+ }
70
+
71
+ return 0;
72
+ }
73
+
74
74
  if ('TEAMCITY_VERSION' in env) {
75
75
  return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
76
76
  }
@@ -89,11 +89,11 @@ let supportLevel = (() => {
89
89
  }
90
90
  }
91
91
 
92
- if (/^(screen|xterm)-256(?:color)?/.test(env.TERM)) {
92
+ if (/-256(color)?$/i.test(env.TERM)) {
93
93
  return 2;
94
94
  }
95
95
 
96
- if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(env.TERM)) {
96
+ if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
97
97
  return 1;
98
98
  }
99
99
 
@@ -106,10 +106,20 @@ let supportLevel = (() => {
106
106
  }
107
107
 
108
108
  return 0;
109
- })();
109
+ }
110
+
111
+ function getSupportLevel(stream) {
112
+ let level = supportsColor(stream);
110
113
 
111
- if ('FORCE_COLOR' in env) {
112
- supportLevel = parseInt(env.FORCE_COLOR, 10) === 0 ? 0 : (supportLevel || 1);
114
+ if ('FORCE_COLOR' in env) {
115
+ level = (env.FORCE_COLOR.length > 0 && parseInt(env.FORCE_COLOR, 10) === 0) ? 0 : (level || 1);
116
+ }
117
+
118
+ return translateLevel(level);
113
119
  }
114
120
 
115
- module.exports = process && support(supportLevel);
121
+ module.exports = {
122
+ supportsColor: getSupportLevel,
123
+ stdout: getSupportLevel(process.stdout),
124
+ stderr: getSupportLevel(process.stderr)
125
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supports-color",
3
- "version": "4.3.0",
3
+ "version": "5.0.1",
4
4
  "description": "Detect whether a terminal supports color",
5
5
  "license": "MIT",
6
6
  "repository": "chalk/supports-color",
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 returned object specifies a level of support for color through a `.level` property and a corresponding flag:
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