Skip to content

Commit 0e68f55

Browse files
duncanhealyMylesBorins
authored andcommitted
tty: truecolor check moved before 256 check
256 color would be return instead of 16m if both env variables were set * tty: improve color check order highest spec first * tty: add test for TERM and COLORTERM set * tty: move COLORTERM check outside TERM closure * tty: remove extra if check for COLORTERM Refs: #27609 PR-URL: #30474 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent bea2069 commit 0e68f55

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎lib/internal/tty.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ function getColorDepth(env = process.env) {
173173
returnCOLORS_256;
174174
}
175175

176+
if(env.COLORTERM==='truecolor'||env.COLORTERM==='24bit'){
177+
returnCOLORS_16m;
178+
}
179+
176180
if(env.TERM){
177181
if(/^xterm-256/.test(env.TERM))
178182
returnCOLORS_256;
@@ -188,13 +192,10 @@ function getColorDepth(env = process.env) {
188192
}
189193
}
190194
}
191-
195+
// Move 16 color COLORTERM below 16m and 256
192196
if(env.COLORTERM){
193-
if(env.COLORTERM==='truecolor'||env.COLORTERM==='24bit')
194-
returnCOLORS_16m;
195197
returnCOLORS_16;
196198
}
197-
198199
returnCOLORS_2;
199200
}
200201

‎test/pseudo-tty/test-tty-color-support.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const writeStream = new WriteStream(fd);
7171
[{NO_COLOR: '',COLORTERM: '24bit'},1],
7272
[{TMUX: '1',FORCE_COLOR: 0},1],
7373
[{NO_COLOR: 'true',FORCE_COLOR: 0,COLORTERM: 'truecolor'},1],
74+
[{TERM: 'xterm-256color',COLORTERM: 'truecolor'},24],
7475
].forEach(([env,depth],i)=>{
7576
constactual=writeStream.getColorDepth(env);
7677
assert.strictEqual(

0 commit comments

Comments
 (0)