From ff754fe893fc86daea9d10458a9142360ea4d36b Mon Sep 17 00:00:00 2001 From: James M Snell <jasnell@gmail.com> Date: Mon, 22 Feb 2021 10:50:01 -0800 Subject: [PATCH] doc: document the NO_COLOR and FORCE_COLOR env vars Signed-off-by: James M Snell <jasnell@gmail.com> Fixes: https://github.com/nodejs/node/issues/37404 --- doc/api/cli.md | 19 +++++++++++++++++++ doc/node.1 | 20 ++++++++++++++++++++ lib/internal/main/print_help.js | 3 +++ 3 files changed, 42 insertions(+) diff --git a/doc/api/cli.md b/doc/api/cli.md index c9f51b65f94cc7..7723a4bc237d15 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -1264,6 +1264,19 @@ Print node's version. ## Environment variables +### `FORCE_COLOR=[1, 2, 3]` + +The `FORCE_COLOR` environment variable is used to +enable ANSI colorized output. The value may be: + +* `1`, `true`, or the empty string `''` indicate 16-color support, +* `2` to indicate 256-color support, or +* `3` to indicate 16 million-color support. + +When `FORCE_COLOR` is used and set to a supported value, both the `NO_COLOR`, +and `NODE_DISABLE_COLORS` environment variables are ignored. + +Any other value will result in colorized output being disabled. ### `NODE_DEBUG=module[,…]` <!-- YAML added: v0.1.32 @@ -1609,6 +1622,11 @@ and the line lengths of the source file (in the key `lineLengths`). } ``` +### `NO_COLOR=<any>` + +[`NO_COLOR`][] is an alias for `NODE_DISABLE_COLORS`. The value of the +environment variable is arbitrary. + ### `OPENSSL_CONF=file` <!-- YAML added: v6.11.0 @@ -1704,6 +1722,7 @@ $ node --max-old-space-size=1536 index.js [`Buffer`]: buffer.md#buffer_class_buffer [`CRYPTO_secure_malloc_init`]: https://www.openssl.org/docs/man1.1.0/man3/CRYPTO_secure_malloc_init.html [`NODE_OPTIONS`]: #cli_node_options_options +[`NO_COLOR`]: https://no-color.org [`SlowBuffer`]: buffer.md#buffer_class_slowbuffer [`process.setUncaughtExceptionCaptureCallback()`]: process.md#process_process_setuncaughtexceptioncapturecallback_fn [`tls.DEFAULT_MAX_VERSION`]: tls.md#tls_tls_default_max_version diff --git a/doc/node.1 b/doc/node.1 index 63574131878042..6b091f5a795f42 100644 --- a/doc/node.1 +++ b/doc/node.1 @@ -530,6 +530,26 @@ Print node's version. .\" ===================================================================== .Sh ENVIRONMENT .Bl -tag -width 6n +.It Ev FORCE_COLOR +Used to enable ANSI colorized output. The value may be one of: +.Ar 1 +, +.Ar true +, or +.Ar an empty string +to +indicate 16-color support, +.Ar 2 +to indicate 256-color support, or +.Ar 3 +to indicate 16 million-color support. When used and set to a supported +value, both the NO_COLOR and NODE_DISABLE_COLORS environment variables +are ignored. Any other value will result in colorized output being +disabled. +. +.It Ev NO_COLOR +Alias for NODE_DISABLE_COLORS +. .It Ev NODE_DEBUG Ar modules... Comma-separated list of core modules that should print debug information. . diff --git a/lib/internal/main/print_help.js b/lib/internal/main/print_help.js index e3d7e68fa64846..e43bcaead89ca0 100644 --- a/lib/internal/main/print_help.js +++ b/lib/internal/main/print_help.js @@ -29,6 +29,9 @@ for (const key of ObjectKeys(types)) // so we gather the documentation here. const { hasIntl, hasSmallICU, hasNodeOptions } = internalBinding('config'); const envVars = new SafeMap(ArrayPrototypeConcat([ + ['FORCE_COLOR', { helpText: "when set to 'true', 1, 2, or 3, causes " + + 'NO_COLOR and NODE_DISABLE_COLORS to be ignored.' }], + ['NO_COLOR', { helpText: 'Alias for NODE_DISABLE_COLORS' }], ['NODE_DEBUG', { helpText: "','-separated list of core modules that " + 'should print debug information' }], ['NODE_DEBUG_NATIVE', { helpText: "','-separated list of C++ core debug " +