Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9760e04

Browse filesBrowse files
saljamrvagg
authored andcommitted
repl: don't use tty control codes when $TERM is set to "dumb"
This change stops the REPL from using ANSI control codes for colours when the TERM environment variable is set to "dumb". "dumb" is the terminal type with the smallest set of capabilities as described by terminfo. See: http://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials Related: nodejs/node-v0.x-archive#5344 Related: nodejs/node-v0.x-archive#25506 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> PR-URL: #2712
1 parent f68fed2 commit 9760e04
Copy full SHA for 9760e04

File tree

Expand file treeCollapse file tree

2 files changed

+59
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+59
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/repl.js‎

Copy file name to clipboardExpand all lines: lib/internal/repl.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ function createRepl(env, opts, cb) {
3434
if (parseInt(env.NODE_NO_READLINE)) {
3535
opts.terminal = false;
3636
}
37-
if (parseInt(env.NODE_DISABLE_COLORS)) {
37+
// the "dumb" special terminal, as defined by terminfo, doesn't support
38+
// ANSI colour control codes.
39+
// see http://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials
40+
if (parseInt(env.NODE_DISABLE_COLORS) || env.TERM === 'dumb') {
3841
opts.useColors = false;
3942
}
4043

Collapse file

‎test/parallel/test-repl-envvars.js‎

Copy file name to clipboard
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict';
2+
3+
// Flags: --expose-internals
4+
5+
const common = require('../common');
6+
const stream = require('stream');
7+
const REPL = require('internal/repl');
8+
const assert = require('assert');
9+
const inspect = require('util').inspect;
10+
11+
const tests = [{
12+
env: {},
13+
expected: { terminal: true, useColors: true }
14+
},
15+
{
16+
env: { NODE_DISABLE_COLORS: '1' },
17+
expected: { terminal: true, useColors: false }
18+
},
19+
{
20+
env: { NODE_NO_READLINE: '1' },
21+
expected: { terminal: false, useColors: false }
22+
},
23+
{
24+
env: { TERM: 'dumb' },
25+
expected: { terminal: true, useColors: false }
26+
},
27+
{
28+
env: { NODE_NO_READLINE: '1', NODE_DISABLE_COLORS: '1' },
29+
expected: { terminal: false, useColors: false }
30+
},
31+
{
32+
env: { NODE_NO_READLINE: '0' },
33+
expected: { terminal: true, useColors: true }
34+
}];
35+
36+
function run(test) {
37+
const env = test.env;
38+
const expected = test.expected;
39+
const opts = {
40+
terminal: true,
41+
input: new stream.Readable({ read() {} }),
42+
output: new stream.Writable({ write() {} })
43+
};
44+
45+
REPL.createInternalRepl(env, opts, function(err, repl) {
46+
if (err) throw err;
47+
assert.equal(expected.terminal, repl.terminal,
48+
'Expected ' + inspect(expected) + ' with ' + inspect(env));
49+
assert.equal(expected.useColors, repl.useColors,
50+
'Expected ' + inspect(expected) + ' with ' + inspect(env));
51+
repl.close();
52+
});
53+
}
54+
55+
tests.forEach(run);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.