diff --git a/lib/repl.js b/lib/repl.js index d3363d4bbc6fd3..15605042975c11 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -501,14 +501,17 @@ function REPLServer(prompt, self.writer = options.writer || exports.writer; if (options.useColors === undefined) { - options.useColors = self.terminal; + options.useColors = self.terminal && process.env.TERM !== 'dumb'; } self.useColors = !!options.useColors; if (self.useColors && self.writer === writer) { // Turn on ANSI coloring. self.writer = (obj) => util.inspect(obj, self.writer.options); - self.writer.options = { ...writer.options, colors: true }; + self.writer.options = { + ...writer.options, + colors: self.useColors + }; } function filterInternalStackFrames(structuredStack) { 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