console: don't use ANSI escape codes when TERM=dumb

PR-URL: https://github.com/nodejs/node/pull/26261
Fixes: https://github.com/nodejs/node/issues/26187
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
Vladislav Kaminsky 2019-02-22 16:00:36 +04:00 committed by Ruben Bridgewater
parent 5f032a7a26
commit 99523758dc
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
3 changed files with 14 additions and 1 deletions

View File

@ -346,7 +346,7 @@ const consoleMethods = {
clear() {
// It only makes sense to clear if _stdout is a TTY.
// Otherwise, do nothing.
if (this._stdout.isTTY) {
if (this._stdout.isTTY && process.env.TERM !== 'dumb') {
// The require is here intentionally to avoid readline being
// required too early when console is first loaded.
const { cursorTo, clearScreenDown } = require('readline');

View File

@ -0,0 +1,9 @@
'use strict';
require('../common');
process.env.TERM = 'dumb';
console.log({ foo: 'bar' });
console.dir({ foo: 'bar' });
console.log('%s q', 'string');
console.log('%o with object format param', { foo: 'bar' });

View File

@ -0,0 +1,4 @@
{ foo: 'bar' }
{ foo: 'bar' }
string q
{ foo: 'bar' } with object format param