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:
Anna Henningsen 2018-03-15 14:10:43 +01:00
parent 57e8793c43
commit 565fd50b4a
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
4 changed files with 14 additions and 2 deletions

View File

@ -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

View File

@ -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({

View 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' });

View File

@ -0,0 +1,3 @@
{ foo: *[32m'bar'*[39m }
string q
{ foo: *[32m'bar'*[39m } with object format param