Skip to content

Commit 9952375

Browse files
wlodzislavBridgeAR
authored andcommitted
console: don't use ANSI escape codes when TERM=dumb
PR-URL: #26261 Fixes: #26187 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 5f032a7 commit 9952375

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

lib/internal/console/constructor.js

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

test/pseudo-tty/console-dumb-tty.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
require('../common');
3+
4+
process.env.TERM = 'dumb';
5+
6+
console.log({ foo: 'bar' });
7+
console.dir({ foo: 'bar' });
8+
console.log('%s q', 'string');
9+
console.log('%o with object format param', { foo: 'bar' });

test/pseudo-tty/console-dumb-tty.out

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{ foo: 'bar' }
2+
{ foo: 'bar' }
3+
string q
4+
{ foo: 'bar' } with object format param

0 commit comments

Comments
 (0)