Skip to content

Commit

Permalink
Give TERM=dumb higher priority (#90)
Browse files Browse the repository at this point in the history
Fixes #88
  • Loading branch information
plroebuck authored and sindresorhus committed Dec 21, 2018
1 parent c94d6c5 commit 8d6a7b5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Expand Up @@ -53,6 +53,10 @@ function supportsColor(stream) {

const min = forceColor ? 1 : 0;

if (env.TERM === 'dumb') {
return min;
}

if (process.platform === 'win32') {
// Node.js 7.5.0 is the first version of Node.js to include a patch to
// libuv that enables 256 color output on Windows. Anything earlier and it
Expand Down Expand Up @@ -112,10 +116,6 @@ function supportsColor(stream) {
return 1;
}

if (env.TERM === 'dumb') {
return min;
}

return min;
}

Expand Down
34 changes: 34 additions & 0 deletions test.js
Expand Up @@ -317,3 +317,37 @@ test('return level 2 when FORCE_COLOR is set when not TTY in xterm256', t => {
t.truthy(result.stdout);
t.is(result.stdout.level, 2);
});

test('return false when `TERM` is set to dumb', t => {
process.env.TERM = 'dumb';
const result = importFresh('.');
t.false(result.stdout);
});

test('return false when `TERM` is set to dumb when `TERM_PROGRAM` is set', t => {
process.env.TERM = 'dumb';
process.env.TERM_PROGRAM = 'Apple_Terminal';
const result = importFresh('.');
t.false(result.stdout);
});

test('return false when `TERM` is set to dumb when run on Windows', t => {
Object.defineProperty(process, 'platform', {
value: 'win32'
});
Object.defineProperty(process.versions, 'node', {
value: '10.13.0'
});
os.release = () => '10.0.14931';
process.env.TERM = 'dumb';
const result = importFresh('.');
t.false(result.stdout);
});

test('return level 1 when `TERM` is set to dumb when `FORCE_COLOR` is set', t => {
process.env.FORCE_COLOR = '1';
process.env.TERM = 'dumb';
const result = importFresh('.');
t.truthy(result.stdout);
t.is(result.stdout.level, 1);
});

0 comments on commit 8d6a7b5

Please sign in to comment.