Skip to content

Commit ae40ac5

Browse files
addaleaxBridgeAR
authored andcommitted
console: auto-detect color support by default
This makes Node pretty-print objects with color by default when `console.log()`-ing them. PR-URL: nodejs#19372 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent c6dec0f commit ae40ac5

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

doc/api/console.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ changes:
100100
Setting to `true` enables coloring while inspecting values, setting to
101101
`'auto'` will make color support depend on the value of the `isTTY` property
102102
and the value returned by `getColorDepth()` on the respective stream.
103-
**Default:** `false`
103+
**Default:** `'auto'`
104104

105105
Creates a new `Console` with one or two writable stream instances. `stdout` is a
106106
writable stream to print log or info output. `stderr` is used for warning or

lib/console.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
6767
stdout,
6868
stderr = stdout,
6969
ignoreErrors = true,
70-
colorMode = false
70+
colorMode = 'auto'
7171
} = options);
7272
} else {
7373
return new Console({

test/pseudo-tty/console_colors.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
require('../common');
3+
// Make this test OS-independent by overriding stdio getColorDepth().
4+
process.stdout.getColorDepth = () => 8;
5+
process.stderr.getColorDepth = () => 8;
6+
7+
console.log({ foo: 'bar' });
8+
console.log('%s q', 'string');
9+
console.log('%o with object format param', { foo: 'bar' });

test/pseudo-tty/console_colors.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{ foo: *[32m'bar'*[39m }
2+
string q
3+
{ foo: *[32m'bar'*[39m } with object format param

0 commit comments

Comments
 (0)