Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
repl: don't color output when TERM=dumb
Fixes: #26187
  • Loading branch information
wlodzislav committed Mar 5, 2019
commit 6aa691d17375cedc3713f5299268187209b6c610
7 changes: 5 additions & 2 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Comment thread
BridgeAR marked this conversation as resolved.
Outdated
}
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
Comment thread
BridgeAR marked this conversation as resolved.
Outdated
};
}

function filterInternalStackFrames(structuredStack) {
Expand Down
15 changes: 15 additions & 0 deletions test/pseudo-tty/repl-dumb-tty.js
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions test/pseudo-tty/repl-dumb-tty.out
Original file line number Diff line number Diff line change
@@ -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