Skip to content

Commit

Permalink
repl: check colors with .getColorDepth()
Browse files Browse the repository at this point in the history
PR-URL: nodejs#26261
Fixes: nodejs#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]>
  • Loading branch information
wlodzislav authored and BridgeAR committed Mar 21, 2019
1 parent d3a62fe commit 82b3ee7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ function REPLServer(prompt,
self.writer = options.writer || exports.writer;

if (options.useColors === undefined) {
options.useColors = self.terminal;
options.useColors = self.terminal && (
typeof self.outputStream.getColorDepth === 'function' ?
self.outputStream.getColorDepth() > 1 : true);
}
self.useColors = !!options.useColors;

Expand Down
15 changes: 15 additions & 0 deletions test/pseudo-tty/repl-dumb-tty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
require('../common');

process.env.TERM = 'dumb';

const repl = require('repl');

repl.start('> ');
process.stdin.push('console.log("foo")\n');
process.stdin.push('1 + 2\n');
process.stdin.push('"str"\n');
process.stdin.push('console.dir({ a: 1 })\n');
process.stdin.push('{ a: 1 }\n');
process.stdin.push('\n');
process.stdin.push('.exit\n');
14 changes: 14 additions & 0 deletions test/pseudo-tty/repl-dumb-tty.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
> console.log("foo")
foo
undefined
> 1 + 2
3
> "str"
'str'
> console.dir({ a: 1 })
{ a: 1 }
undefined
> { a: 1 }
{ a: 1 }
>
> .exit

0 comments on commit 82b3ee7

Please sign in to comment.