Skip to content

Commit 8d6a7b5

Browse files
plroebucksindresorhus
authored andcommitted
Give TERM=dumb higher priority (#90)
Fixes #88
1 parent c94d6c5 commit 8d6a7b5

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ function supportsColor(stream) {
5353

5454
const min = forceColor ? 1 : 0;
5555

56+
if (env.TERM === 'dumb') {
57+
return min;
58+
}
59+
5660
if (process.platform === 'win32') {
5761
// Node.js 7.5.0 is the first version of Node.js to include a patch to
5862
// libuv that enables 256 color output on Windows. Anything earlier and it
@@ -112,10 +116,6 @@ function supportsColor(stream) {
112116
return 1;
113117
}
114118

115-
if (env.TERM === 'dumb') {
116-
return min;
117-
}
118-
119119
return min;
120120
}
121121

test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,37 @@ test('return level 2 when FORCE_COLOR is set when not TTY in xterm256', t => {
317317
t.truthy(result.stdout);
318318
t.is(result.stdout.level, 2);
319319
});
320+
321+
test('return false when `TERM` is set to dumb', t => {
322+
process.env.TERM = 'dumb';
323+
const result = importFresh('.');
324+
t.false(result.stdout);
325+
});
326+
327+
test('return false when `TERM` is set to dumb when `TERM_PROGRAM` is set', t => {
328+
process.env.TERM = 'dumb';
329+
process.env.TERM_PROGRAM = 'Apple_Terminal';
330+
const result = importFresh('.');
331+
t.false(result.stdout);
332+
});
333+
334+
test('return false when `TERM` is set to dumb when run on Windows', t => {
335+
Object.defineProperty(process, 'platform', {
336+
value: 'win32'
337+
});
338+
Object.defineProperty(process.versions, 'node', {
339+
value: '10.13.0'
340+
});
341+
os.release = () => '10.0.14931';
342+
process.env.TERM = 'dumb';
343+
const result = importFresh('.');
344+
t.false(result.stdout);
345+
});
346+
347+
test('return level 1 when `TERM` is set to dumb when `FORCE_COLOR` is set', t => {
348+
process.env.FORCE_COLOR = '1';
349+
process.env.TERM = 'dumb';
350+
const result = importFresh('.');
351+
t.truthy(result.stdout);
352+
t.is(result.stdout.level, 1);
353+
});

0 commit comments

Comments
 (0)