Skip to content
Permalink
Browse files

repl: check colors with .getColorDepth()

PR-URL: #26261
Fixes: #26187
Reviewed-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>
  • Loading branch information...
wlodzislav authored and BridgeAR committed Feb 22, 2019
1 parent d3a62fe commit 82b3ee776ba87481b5fa3d00cbe7f3c4f32c3ec3
Showing with 32 additions and 1 deletion.
  1. +3 −1 lib/repl.js
  2. +15 −0 test/pseudo-tty/repl-dumb-tty.js
  3. +14 −0 test/pseudo-tty/repl-dumb-tty.out
@@ -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;

@@ -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');
@@ -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.
You can’t perform that action at this time.