diff --git a/lib/repl.js b/lib/repl.js index 60e07104dca11d..7e186778a48f8c 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -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; diff --git a/test/pseudo-tty/repl-dumb-tty.js b/test/pseudo-tty/repl-dumb-tty.js new file mode 100644 index 00000000000000..08c63881d38b97 --- /dev/null +++ b/test/pseudo-tty/repl-dumb-tty.js @@ -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'); diff --git a/test/pseudo-tty/repl-dumb-tty.out b/test/pseudo-tty/repl-dumb-tty.out new file mode 100644 index 00000000000000..69eb4e5da6313e --- /dev/null +++ b/test/pseudo-tty/repl-dumb-tty.out @@ -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