Skip to content
Permalink
Browse files

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>
  • Loading branch information
duncanhealy authored and MylesBorins committed Nov 13, 2019
1 parent bea2069 commit 0e68f550e57881e23519b7f48f8ebe8b3504637d
Showing with 6 additions and 4 deletions.
  1. +5 −4 lib/internal/tty.js
  2. +1 −0 test/pseudo-tty/test-tty-color-support.js
@@ -173,6 +173,10 @@ function getColorDepth(env = process.env) {
return COLORS_256;
}

if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit') {
return COLORS_16m;
}

if (env.TERM) {
if (/^xterm-256/.test(env.TERM))
return COLORS_256;
@@ -188,13 +192,10 @@ function getColorDepth(env = process.env) {
}
}
}

// Move 16 color COLORTERM below 16m and 256
if (env.COLORTERM) {
if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit')
return COLORS_16m;
return COLORS_16;
}

return COLORS_2;
}

@@ -71,6 +71,7 @@ const writeStream = new WriteStream(fd);
[{ NO_COLOR: '', COLORTERM: '24bit' }, 1],
[{ TMUX: '1', FORCE_COLOR: 0 }, 1],
[{ NO_COLOR: 'true', FORCE_COLOR: 0, COLORTERM: 'truecolor' }, 1],
[{ TERM: 'xterm-256color', COLORTERM: 'truecolor' }, 24],
].forEach(([env, depth], i) => {
const actual = writeStream.getColorDepth(env);
assert.strictEqual(

0 comments on commit 0e68f55

Please sign in to comment.
You can’t perform that action at this time.