Skip to content

Commit dcbe376

Browse files
duncanhealytargos
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 <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 74e8902 commit dcbe376

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/internal/tty.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ function getColorDepth(env = process.env) {
173173
return COLORS_256;
174174
}
175175

176+
if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit') {
177+
return COLORS_16m;
178+
}
179+
176180
if (env.TERM) {
177181
if (/^xterm-256/.test(env.TERM))
178182
return COLORS_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-
return COLORS_16m;
195197
return COLORS_16;
196198
}
197-
198199
return COLORS_2;
199200
}
200201

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

+1
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
const actual = writeStream.getColorDepth(env);
7677
assert.strictEqual(

0 commit comments

Comments
 (0)