Skip to content

Commit

Permalink
tty: truecolor check moved before 256 check
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
duncanhealy authored and MylesBorins committed Dec 17, 2019
1 parent bea2069 commit 0e68f55
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/internal/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions test/pseudo-tty/test-tty-color-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0e68f55

Please sign in to comment.