repl: check colors with .getColorDepth() · nodejs/node@82b3ee7 (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Commit 82b3ee7

wlodzislavBridgeAR

authored and

committed

repl: check colors with .getColorDepth()

PR-URL: #26261 Fixes: #26187Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Roman Reiss me@silverwind.io Reviewed-By: Rich Trott rtrott@gmail.com Reviewed-By: Jeremiah Senkpiel fishrock123@rocketmail.com

File tree

3 files changed

lines changed

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -504,7 +504,9 @@ function REPLServer(prompt,
504 504 self.writer = options.writer |
505 505
506 506 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);
508 510 }
509 511 self.useColors = !!options.useColors;
510 512
Original file line number Diff line number Diff 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');
Original file line number Diff line number Diff 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