tty: treat empty NO_COLOR same as absent NO_COLOR

PR-URL: https://github.com/nodejs/node/pull/58074
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Antoine du Hamel 2025-06-28 15:26:22 +02:00 committed by GitHub
parent 98da424ac4
commit afbf2f385a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 5 deletions

View File

@ -99,9 +99,9 @@ function warnOnDeactivatedColors(env) {
if (warned)
return;
let name = '';
if (env.NODE_DISABLE_COLORS !== undefined)
if (env.NODE_DISABLE_COLORS !== undefined && env.NODE_DISABLE_COLORS !== '')
name = 'NODE_DISABLE_COLORS';
if (env.NO_COLOR !== undefined) {
if (env.NO_COLOR !== undefined && env.NO_COLOR !== '') {
if (name !== '') {
name += "' and '";
}
@ -141,9 +141,9 @@ function getColorDepth(env = process.env) {
}
}
if (env.NODE_DISABLE_COLORS !== undefined ||
if ((env.NODE_DISABLE_COLORS !== undefined && env.NODE_DISABLE_COLORS !== '') ||
// See https://no-color.org/
env.NO_COLOR !== undefined ||
(env.NO_COLOR !== undefined && env.NO_COLOR !== '') ||
// The "dumb" special terminal, as defined by terminfo, doesn't support
// ANSI color control codes.
// See https://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials

View File

@ -61,7 +61,13 @@ const writeStream = new WriteStream(fd);
[{ TERM: 'ansi' }, 4],
[{ TERM: 'ANSI' }, 4],
[{ TERM: 'color' }, 4],
[{ TERM: 'linux' }, 4],
[{ TERM: 'fail' }, 1],
[{ TERM: 'color', NO_COLOR: '' }, 4],
[{ TERM: 'color', NODE_DISABLE_COLORS: '' }, 4],
[{ TERM: 'color', NODE_DISABLE_COLORS: '1' }, 1],
[{ TERM: 'color', NODE_DISABLE_COLORS: 0 }, 1],
[{ TERM: 'color', NODE_DISABLE_COLORS: null }, 1],
[{ TERM: 'console' }, 4],
[{ TERM: 'direct' }, 4],
[{ TERM: 'dumb' }, 1],
@ -78,7 +84,9 @@ const writeStream = new WriteStream(fd);
[{ NO_COLOR: '1', FORCE_COLOR: '2' }, 8],
[{ NODE_DISABLE_COLORS: '1', FORCE_COLOR: '3' }, 24],
[{ NO_COLOR: '1', COLORTERM: '24bit' }, 1],
[{ NO_COLOR: '', COLORTERM: '24bit' }, 1],
[{ NO_COLOR: '', COLORTERM: '24bit' }, 24],
[{ NO_COLOR: null, COLORTERM: '24bit' }, 1],
[{ NO_COLOR: 0, COLORTERM: '24bit' }, 1],
[{ TMUX: '1', FORCE_COLOR: 0 }, 1],
[{ NO_COLOR: 'true', FORCE_COLOR: 0, COLORTERM: 'truecolor' }, 1],
[{ TERM: 'xterm-256color', COLORTERM: 'truecolor' }, 24],