From 99523758dc5d076b8f34259961291d7db2e6d497 Mon Sep 17 00:00:00 2001 From: Vladislav Kaminsky Date: Fri, 22 Feb 2019 16:00:36 +0400 Subject: [PATCH] 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 Reviewed-By: James M Snell Reviewed-By: Roman Reiss Reviewed-By: Rich Trott Reviewed-By: Jeremiah Senkpiel --- lib/internal/console/constructor.js | 2 +- test/pseudo-tty/console-dumb-tty.js | 9 +++++++++ test/pseudo-tty/console-dumb-tty.out | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/pseudo-tty/console-dumb-tty.js create mode 100644 test/pseudo-tty/console-dumb-tty.out diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index 1b9c4e7ba03..b8f2ae29244 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -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'); diff --git a/test/pseudo-tty/console-dumb-tty.js b/test/pseudo-tty/console-dumb-tty.js new file mode 100644 index 00000000000..93f9b99b0ff --- /dev/null +++ b/test/pseudo-tty/console-dumb-tty.js @@ -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' }); diff --git a/test/pseudo-tty/console-dumb-tty.out b/test/pseudo-tty/console-dumb-tty.out new file mode 100644 index 00000000000..c776b496474 --- /dev/null +++ b/test/pseudo-tty/console-dumb-tty.out @@ -0,0 +1,4 @@ +{ foo: 'bar' } +{ foo: 'bar' } +string q +{ foo: 'bar' } with object format param