-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
|
||
// Flags: --expose-internals | ||
|
||
const common = require('../common'); | ||
const stream = require('stream'); | ||
const REPL = require('internal/repl'); | ||
const assert = require('assert'); | ||
const inspect = require('util').inspect; | ||
|
||
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, | ||
'Expected ' + inspect(expected) + ' with ' + inspect(env)); | ||
assert.equal(expected.useColors, repl.useColors, | ||
'Expected ' + inspect(expected) + ' with ' + inspect(env)); | ||
repl.close(); | ||
}); | ||
} | ||
|
||
tests.forEach(run); |