Skip to content

Commit 82b3ee7

Browse files
wlodzislavBridgeAR
authored andcommitted
repl: check colors with .getColorDepth()
PR-URL: #26261 Fixes: #26187 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent d3a62fe commit 82b3ee7

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

lib/repl.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,9 @@ function REPLServer(prompt,
504504
self.writer = options.writer || exports.writer;
505505

506506
if (options.useColors === undefined) {
507-
options.useColors = self.terminal;
507+
options.useColors = self.terminal && (
508+
typeof self.outputStream.getColorDepth === 'function' ?
509+
self.outputStream.getColorDepth() > 1 : true);
508510
}
509511
self.useColors = !!options.useColors;
510512

test/pseudo-tty/repl-dumb-tty.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
require('../common');
3+
4+
process.env.TERM = 'dumb';
5+
6+
const repl = require('repl');
7+
8+
repl.start('> ');
9+
process.stdin.push('console.log("foo")\n');
10+
process.stdin.push('1 + 2\n');
11+
process.stdin.push('"str"\n');
12+
process.stdin.push('console.dir({ a: 1 })\n');
13+
process.stdin.push('{ a: 1 }\n');
14+
process.stdin.push('\n');
15+
process.stdin.push('.exit\n');

test/pseudo-tty/repl-dumb-tty.out

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
> console.log("foo")
2+
foo
3+
undefined
4+
> 1 + 2
5+
3
6+
> "str"
7+
'str'
8+
> console.dir({ a: 1 })
9+
{ a: 1 }
10+
undefined
11+
> { a: 1 }
12+
{ a: 1 }
13+
>
14+
> .exit

0 commit comments

Comments
 (0)