Skip to content

Commit

Permalink
fix: CLI flags/FORCE_COLOR precedes other color support checks
Browse files Browse the repository at this point in the history
  • Loading branch information
m15a committed Feb 12, 2024
1 parent d4f413e commit 53cf1b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {

const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;

if (forceColor === 0) {
return 0;
if (forceColor !== undefined) {
return forceColor;
}

if (sniffFlags) {
Expand All @@ -91,7 +91,7 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
return 0;
}

const min = forceColor || 0;
const min = 0;

if (env.TERM === 'dumb') {
return min;
Expand Down
16 changes: 16 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ test('return true if `FORCE_COLOR` is in env, but honor 256 #2', t => {
t.is(result.stdout.level, 2);
});

test('CLI color flags precede other color support checks', t => {
process.env.COLORTERM = 'truecolor';
process.argv = ['--color=256'];
const result = importFresh('./index.js');
t.truthy(result.stdout);
t.is(result.stdout.level, 2)
});

test('`FORCE_COLOR` environment variable precedes other color support checks', t => {
process.env.COLORTERM = 'truecolor';
process.env.FORCE_COLOR = '2';
const result = importFresh('./index.js');
t.truthy(result.stdout);
t.is(result.stdout.level, 2)
});

test('return false if `FORCE_COLOR` is in env and is 0', t => {
process.env.FORCE_COLOR = '0';
const result = importFresh('./index.js');
Expand Down

0 comments on commit 53cf1b3

Please sign in to comment.