Skip to content

Commit 559e23a

Browse files
addaleaxjasnell
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: #19372 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 3f1562d commit 559e23a

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
@@ -68,7 +68,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
6868
stdout,
6969
stderr = stdout,
7070
ignoreErrors = true,
71-
colorMode = false
71+
colorMode = 'auto'
7272
} = options);
7373
} else {
7474
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)