File tree Expand file tree Collapse file tree 1 file changed +48
-2
lines changed
Expand file tree Collapse file tree 1 file changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,41 @@ const COLORS_16 = 4;
3131const COLORS_256 = 8 ;
3232const COLORS_16m = 24 ;
3333
34+ // Some entries were taken from `dircolors`
35+ // (https://linux.die.net/man/1/dircolors). The corresponding terminals might
36+ // support more than 16 colors, but this was not tested for.
37+ //
38+ // Copyright (C) 1996-2016 Free Software Foundation, Inc. Copying and
39+ // distribution of this file, with or without modification, are permitted
40+ // provided the copyright notice and this notice are preserved.
41+ const TERM_ENVS = [
42+ 'Eterm' ,
43+ 'cons25' ,
44+ 'console' ,
45+ 'cygwin' ,
46+ 'dtterm' ,
47+ 'gnome' ,
48+ 'hurd' ,
49+ 'jfbterm' ,
50+ 'konsole' ,
51+ 'kterm' ,
52+ 'mlterm' ,
53+ 'putty' ,
54+ 'st' ,
55+ 'terminator'
56+ ] ;
57+
58+ const TERM_ENVS_REG_EXP = [
59+ / a n s i / ,
60+ / c o l o r / ,
61+ / l i n u x / ,
62+ / ^ c o n [ 0 - 9 ] * x [ 0 - 9 ] / ,
63+ / ^ r x v t / ,
64+ / ^ s c r e e n / ,
65+ / ^ x t e r m / ,
66+ / ^ v t 1 0 0 /
67+ ] ;
68+
3469// The `getColorDepth` API got inspired by multiple sources such as
3570// https://github.com/chalk/supports-color,
3671// https://github.com/isaacs/color-support.
@@ -89,8 +124,19 @@ function getColorDepth(env = process.env) {
89124 if ( env . TERM ) {
90125 if ( / ^ x t e r m - 2 5 6 / . test ( env . TERM ) )
91126 return COLORS_256 ;
92- if ( / ^ s c r e e n | ^ x t e r m | ^ v t 1 0 0 | c o l o r | a n s i | c y g w i n | l i n u x / i. test ( env . TERM ) )
93- return COLORS_16 ;
127+
128+ const termEnv = env . TERM . toLowerCase ( ) ;
129+
130+ for ( const term of TERM_ENVS ) {
131+ if ( termEnv === term ) {
132+ return COLORS_16 ;
133+ }
134+ }
135+ for ( const term of TERM_ENVS_REG_EXP ) {
136+ if ( term . test ( termEnv ) ) {
137+ return COLORS_16 ;
138+ }
139+ }
94140 }
95141
96142 if ( env . COLORTERM )
You can’t perform that action at this time.
0 commit comments