From 1357f4ab39866eb23b6c3662a6b36851d9f0bb52 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Mon, 29 Jul 2024 14:26:05 +0200 Subject: [PATCH] Add `NO_COLOR` support https://no-color.org/ - fixes #91 --- environment.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/environment.js b/environment.js index 0afdd7f..2ee2fe4 100644 --- a/environment.js +++ b/environment.js @@ -132,10 +132,21 @@ const forceColor = isNode && f.isOneOf(process.env.FORCE_COLOR, ['true', '1', '2']) /* c8 ignore start */ -export const supportsColor = !hasParam('--no-colors') && - (!isNode || process.stdout.isTTY || forceColor) && ( - !isNode || hasParam('--color') || forceColor || +/** + * Color is enabled by default if the terminal supports it. + * + * Explicitly enable color using `--color` parameter + * Disable color using `--no-color` parameter or using `NO_COLOR=1` environment variable. + * `FORCE_COLOR=1` enables color and takes precedence over all. + */ +export const supportsColor = forceColor || ( + !hasParam('--no-colors') && // @todo deprecate --no-colors + !hasConf('no-color') && + (!isNode || process.stdout.isTTY) && ( + !isNode || + hasParam('--color') || getVariable('COLORTERM') !== null || (getVariable('TERM') || '').includes('color') + ) ) /* c8 ignore stop */