Skip to content

Commit

Permalink
repl: fix NO_COLORS env var is ignored
Browse files Browse the repository at this point in the history
PR-URL: #51568
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
MoLow authored and targos committed Feb 15, 2024
1 parent 8c0a257 commit 3e579ab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function REPLServer(prompt,

if (options.terminal && options.useColors === undefined) {
// If possible, check if stdout supports colors or not.
options.useColors = shouldColorize(options.output) || process.env.NODE_DISABLE_COLORS === undefined;
options.useColors = shouldColorize(options.output);
}

// TODO(devsnek): Add a test case for custom eval functions.
Expand Down
10 changes: 5 additions & 5 deletions test/parallel/test-repl-envvars.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { REPL_MODE_SLOPPY, REPL_MODE_STRICT } = require('repl');
const tests = [
{
env: {},
expected: { terminal: true, useColors: true }
expected: { terminal: true, useColors: false }
},
{
env: { NODE_DISABLE_COLORS: '1' },
Expand All @@ -29,7 +29,7 @@ const tests = [
},
{
env: { TERM: 'dumb' },
expected: { terminal: true, useColors: true }
expected: { terminal: true, useColors: false }
},
{
env: { TERM: 'dumb', FORCE_COLOR: '1' },
Expand All @@ -41,15 +41,15 @@ const tests = [
},
{
env: { NODE_NO_READLINE: '0' },
expected: { terminal: true, useColors: true }
expected: { terminal: true, useColors: false }
},
{
env: { NODE_REPL_MODE: 'sloppy' },
expected: { terminal: true, useColors: true, replMode: REPL_MODE_SLOPPY }
expected: { terminal: true, useColors: false, replMode: REPL_MODE_SLOPPY }
},
{
env: { NODE_REPL_MODE: 'strict' },
expected: { terminal: true, useColors: true, replMode: REPL_MODE_STRICT }
expected: { terminal: true, useColors: false, replMode: REPL_MODE_STRICT }
},
];

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ assert.strictEqual(r1.output, stream);
assert.strictEqual(r1.input, r1.inputStream);
assert.strictEqual(r1.output, r1.outputStream);
assert.strictEqual(r1.terminal, true);
assert.strictEqual(r1.useColors, r1.terminal);
assert.strictEqual(r1.useColors, false);
assert.strictEqual(r1.useGlobal, false);
assert.strictEqual(r1.ignoreUndefined, false);
assert.strictEqual(r1.replMode, repl.REPL_MODE_SLOPPY);
Expand Down

0 comments on commit 3e579ab

Please sign in to comment.