console: auto-detect color support by default
This makes Node pretty-print objects with color by default when `console.log()`-ing them. PR-URL: https://github.com/nodejs/node/pull/19372 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
57e8793c43
commit
565fd50b4a
@ -100,7 +100,7 @@ changes:
|
||||
Setting to `true` enables coloring while inspecting values, setting to
|
||||
`'auto'` will make color support depend on the value of the `isTTY` property
|
||||
and the value returned by `getColorDepth()` on the respective stream.
|
||||
**Default:** `false`
|
||||
**Default:** `'auto'`
|
||||
|
||||
Creates a new `Console` with one or two writable stream instances. `stdout` is a
|
||||
writable stream to print log or info output. `stderr` is used for warning or
|
||||
|
@ -68,7 +68,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
|
||||
stdout,
|
||||
stderr = stdout,
|
||||
ignoreErrors = true,
|
||||
colorMode = false
|
||||
colorMode = 'auto'
|
||||
} = options);
|
||||
} else {
|
||||
return new Console({
|
||||
|
9
test/pseudo-tty/console_colors.js
Normal file
9
test/pseudo-tty/console_colors.js
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
// Make this test OS-independent by overriding stdio getColorDepth().
|
||||
process.stdout.getColorDepth = () => 8;
|
||||
process.stderr.getColorDepth = () => 8;
|
||||
|
||||
console.log({ foo: 'bar' });
|
||||
console.log('%s q', 'string');
|
||||
console.log('%o with object format param', { foo: 'bar' });
|
3
test/pseudo-tty/console_colors.out
Normal file
3
test/pseudo-tty/console_colors.out
Normal file
@ -0,0 +1,3 @@
|
||||
{ foo: *[32m'bar'*[39m }
|
||||
string q
|
||||
{ foo: *[32m'bar'*[39m } with object format param
|
Loading…
x
Reference in New Issue
Block a user