Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: don't use tty control codes when $TERM is set to "dumb" #2712

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion lib/internal/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function createRepl(env, opts, cb) {
if (parseInt(env.NODE_NO_READLINE)) {
opts.terminal = false;
}
if (parseInt(env.NODE_DISABLE_COLORS)) {
// the "dumb" special terminal, as defined by terminfo, doesn't support
// ANSI colour control codes.
// see http://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials
if (parseInt(env.NODE_DISABLE_COLORS) || env.TERM === 'dumb') {
opts.useColors = false;
}

Expand Down
52 changes: 52 additions & 0 deletions test/parallel/test-repl-envvars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

// Flags: --expose-internals

const common = require('../common');
const stream = require('stream');
const REPL = require('internal/repl');
const assert = require('assert');

const tests = [{
env: {},
expected: { terminal: true, useColors: true }
},
{
env: { NODE_DISABLE_COLORS: "1" },
expected: { terminal: true, useColors: false }
},
{
env: { NODE_NO_READLINE: "1" },
expected: { terminal: false, useColors: false }
},
{
env: { TERM: "dumb" },
expected: { terminal: true, useColors: false }
},
{
env: { NODE_NO_READLINE: "1", NODE_DISABLE_COLORS: "1" },
expected: { terminal: false, useColors: false }
},
{
env: { NODE_NO_READLINE: "0" },
expected: { terminal: true, useColors: true }
}];

function run(test) {
const env = test.env;
const expected = test.expected;
const opts = {
terminal: true,
input: new stream.Readable({ read() {} }),
output: new stream.Writable({ write() {} })
}

REPL.createInternalRepl(env, opts, function(err, repl) {
if (err) throw err;
assert.equal(expected.terminal, repl.terminal);
assert.equal(expected.useColors, repl.useColors);
repl.close();
});
}

tests.forEach(run)