8
8
import ReadableStream = NodeJS . ReadableStream ;
9
9
import WriteStream = NodeJS . WriteStream ;
10
10
import Socket = NodeJS . Socket ;
11
-
11
+ const supportsColor = require ( '../../third_party/github.com/chalk/supports-color' ) ;
12
12
13
13
/**
14
14
* Node specific stuff.
@@ -29,11 +29,6 @@ declare const os: {
29
29
} ;
30
30
31
31
32
- const _env = ( typeof process == 'object' && process . env ) || { } ;
33
- const _platform = ( typeof process == 'object' && process . platform ) || '' ;
34
- const _versions = ( typeof process == 'object' && process . versions ) || { node : '' } ;
35
- const _os = ( typeof os == 'object' && os ) || { release : ( ) => '' } ;
36
-
37
32
const streamMap = new WeakMap < { } , StreamCapabilities > ( ) ;
38
33
39
34
@@ -72,85 +67,6 @@ export interface StreamCapabilities {
72
67
columns : number | null ;
73
68
}
74
69
75
-
76
- const ciVars = [ 'TRAVIS' , 'CIRCLECI' , 'APPVEYOR' , 'GITLAB_CI' ] ;
77
-
78
- function _getColorLevel ( stream : Socket ) : 0 | 1 | 2 | 3 {
79
- if ( 'FORCE_COLOR' in _env ) {
80
- if ( _env . FORCE_COLOR === '1' ) {
81
- return 3 ;
82
- } else if ( _env . FORCE_COLOR === '0' ) {
83
- return 0 ;
84
- }
85
- }
86
-
87
- if ( stream && ! stream . isTTY && ! _env . MSYSTEM ) {
88
- return 0 ;
89
- }
90
-
91
- if ( _platform . startsWith ( 'win32' ) && ! _env . MSYSTEM ) {
92
- // Node.js 7.5.0 is the first version of Node.js to include a patch to
93
- // libuv that enables 256 color output on Windows. Anything earlier and it
94
- // won't work. However, here we target Node.js 8 at minimum as it is an LTS
95
- // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
96
- // release that supports 256 colors.
97
- const osRelease = _os . release ( ) . split ( '.' ) ;
98
- if ( Number ( _versions . node . split ( '.' ) [ 0 ] ) >= 8
99
- && Number ( osRelease [ 0 ] ) >= 10
100
- && Number ( osRelease [ 2 ] ) >= 10586 ) {
101
- return 2 ;
102
- }
103
-
104
- return 1 ;
105
- }
106
-
107
- if ( 'CI' in _env ) {
108
- if ( ciVars . some ( sign => sign in _env ) || _env . CI_NAME === 'codeship' ) {
109
- return 1 ;
110
- }
111
-
112
- return 0 ;
113
- }
114
-
115
- if ( 'TEAMCITY_VERSION' in _env ) {
116
- return / ^ ( 9 \. ( 0 * [ 1 - 9 ] \d * ) \. | \d { 2 , } \. ) / . test ( _env . TEAMCITY_VERSION ) ? 1 : 0 ;
117
- }
118
-
119
- if ( 'TERM_PROGRAM' in _env ) {
120
- const version = parseInt ( ( _env . TERM_PROGRAM_VERSION || '' ) . split ( '.' ) [ 0 ] , 10 ) ;
121
-
122
- switch ( _env . TERM_PROGRAM ) {
123
- case 'iTerm.app' :
124
- return version >= 3 ? 3 : 2 ;
125
- case 'Hyper' :
126
- return 3 ;
127
- case 'Apple_Terminal' :
128
- return 2 ;
129
-
130
- // No default
131
- }
132
- }
133
-
134
- if ( / - 2 5 6 ( c o l o r ) ? $ / i. test ( _env . TERM ) ) {
135
- return 2 ;
136
- }
137
-
138
- if ( / ^ s c r e e n | ^ x t e r m | ^ v t 1 0 0 | ^ r x v t | c o l o r | a n s i | c y g w i n | l i n u x / i. test ( _env . TERM ) ) {
139
- return 1 ;
140
- }
141
-
142
- if ( 'COLORTERM' in _env ) {
143
- return 1 ;
144
- }
145
-
146
- if ( _env . TERM === 'dumb' ) {
147
- return 0 ;
148
- }
149
-
150
- return 0 ;
151
- }
152
-
153
-
154
70
function _getRows ( ) {
155
71
return typeof process == 'object' && process . stdout . rows || null ;
156
72
}
@@ -159,9 +75,11 @@ function _getColumns() {
159
75
}
160
76
161
77
162
- function _createCapabilities ( stream : Socket , isTerminalStream : boolean ) : StreamCapabilities {
163
- const level = _getColorLevel ( stream ) ;
164
-
78
+ function _createCapabilities (
79
+ stream : Socket ,
80
+ isTerminalStream : boolean ,
81
+ level : 0 | 1 | 2 | 3 = supportsColor . stdout . level ,
82
+ ) : StreamCapabilities {
165
83
return {
166
84
readable : stream . readable ,
167
85
writable : stream . writable ,
0 commit comments