Skip to content

Commit

Permalink
repl: don't color output when TERM=dumb
Browse files Browse the repository at this point in the history
  • Loading branch information
wlodzislav committed Mar 5, 2019
1 parent 1b7434d commit 6aa691d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
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';
}
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) {
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

0 comments on commit 6aa691d

Please sign in to comment.