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:
parent
d3a62fe7fc
commit
82b3ee776b
@ -504,7 +504,9 @@ function REPLServer(prompt,
|
|||||||
self.writer = options.writer || exports.writer;
|
self.writer = options.writer || exports.writer;
|
||||||
|
|
||||||
if (options.useColors === undefined) {
|
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;
|
self.useColors = !!options.useColors;
|
||||||
|
|
||||||
|
15
test/pseudo-tty/repl-dumb-tty.js
Normal file
15
test/pseudo-tty/repl-dumb-tty.js
Normal 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');
|
14
test/pseudo-tty/repl-dumb-tty.out
Normal file
14
test/pseudo-tty/repl-dumb-tty.out
Normal 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
|
Loading…
x
Reference in New Issue
Block a user