repl: check colors with .getColorDepth()

PR-URL: https://github.com/nodejs/node/pull/26261
Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
Vladislav Kaminsky 2019-02-22 16:13:52 +04:00 committed by Ruben Bridgewater
parent d3a62fe7fc
commit 82b3ee776b
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
3 changed files with 32 additions and 1 deletions

View File

@ -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;

View File

@ -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');

View File

@ -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