Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CLI flags/FORCE_COLOR precede other color support checks #154

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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