Skip to content

Commit 1ee539a

Browse files
aduh95targos
authored andcommitted
tty: treat empty NO_COLOR same as absent NO_COLOR
PR-URL: #58074 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 049c838 commit 1ee539a

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/internal/tty.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ function warnOnDeactivatedColors(env) {
9999
if (warned)
100100
return;
101101
let name = '';
102-
if (env.NODE_DISABLE_COLORS !== undefined)
102+
if (env.NODE_DISABLE_COLORS !== undefined && env.NODE_DISABLE_COLORS !== '')
103103
name = 'NODE_DISABLE_COLORS';
104-
if (env.NO_COLOR !== undefined) {
104+
if (env.NO_COLOR !== undefined && env.NO_COLOR !== '') {
105105
if (name !== '') {
106106
name += "' and '";
107107
}
@@ -141,9 +141,9 @@ function getColorDepth(env = process.env) {
141141
}
142142
}
143143

144-
if (env.NODE_DISABLE_COLORS !== undefined ||
144+
if ((env.NODE_DISABLE_COLORS !== undefined && env.NODE_DISABLE_COLORS !== '') ||
145145
// See https://no-color.org/
146-
env.NO_COLOR !== undefined ||
146+
(env.NO_COLOR !== undefined && env.NO_COLOR !== '') ||
147147
// The "dumb" special terminal, as defined by terminfo, doesn't support
148148
// ANSI color control codes.
149149
// See https://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ const writeStream = new WriteStream(fd);
6161
[{ TERM: 'ansi' }, 4],
6262
[{ TERM: 'ANSI' }, 4],
6363
[{ TERM: 'color' }, 4],
64+
[{ TERM: 'linux' }, 4],
65+
[{ TERM: 'fail' }, 1],
66+
[{ TERM: 'color', NO_COLOR: '' }, 4],
67+
[{ TERM: 'color', NODE_DISABLE_COLORS: '' }, 4],
6468
[{ TERM: 'color', NODE_DISABLE_COLORS: '1' }, 1],
69+
[{ TERM: 'color', NODE_DISABLE_COLORS: 0 }, 1],
70+
[{ TERM: 'color', NODE_DISABLE_COLORS: null }, 1],
6571
[{ TERM: 'console' }, 4],
6672
[{ TERM: 'direct' }, 4],
6773
[{ TERM: 'dumb' }, 1],
@@ -78,7 +84,9 @@ const writeStream = new WriteStream(fd);
7884
[{ NO_COLOR: '1', FORCE_COLOR: '2' }, 8],
7985
[{ NODE_DISABLE_COLORS: '1', FORCE_COLOR: '3' }, 24],
8086
[{ NO_COLOR: '1', COLORTERM: '24bit' }, 1],
81-
[{ NO_COLOR: '', COLORTERM: '24bit' }, 1],
87+
[{ NO_COLOR: '', COLORTERM: '24bit' }, 24],
88+
[{ NO_COLOR: null, COLORTERM: '24bit' }, 1],
89+
[{ NO_COLOR: 0, COLORTERM: '24bit' }, 1],
8290
[{ TMUX: '1', FORCE_COLOR: 0 }, 1],
8391
[{ NO_COLOR: 'true', FORCE_COLOR: 0, COLORTERM: 'truecolor' }, 1],
8492
[{ TERM: 'xterm-256color', COLORTERM: 'truecolor' }, 24],

0 commit comments

Comments
 (0)