Skip to content

Commit

Permalink
Check for CLICOLOR and CLICOLOR_FORCE. Fixes chalk#31 and chalk#32.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse committed Oct 22, 2015
1 parent 711d47f commit ac01715
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ var supportLevel = (function () {
return 1;
}

if ('CLICOLOR' in process.env) {
if (process.env.CLICOLOR === '0') {
return 0;
}
if (process.stdout && process.stdout.isTTY) {
return 1;
}
}

if ('CLICOLOR_FORCE' in process.env && process.env.CLICOLOR_FORCE !== '0') {
return 1;
}

if (process.stdout && !process.stdout.isTTY) {
return 0;
}
Expand Down
22 changes: 22 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@ it('should return true if `FORCE_COLOR` is in env', function () {
assert.equal(result.level, 1);
});

it('should return true if `CLICOLOR_FORCE` is != 0', function () {
process.env.CLICOLOR_FORCE = 1;
process.stdout.isTTY = false;
var result = requireUncached('./');
assert.equal(Boolean(result), true);
assert.equal(result.level, 1);
});

it('should return false if `CLICOLOR` is 0', function () {
process.env.CLICOLOR = 0;
var result = requireUncached('./');
assert.equal(Boolean(result), true);
assert.equal(result.level, 1);
});

it('should return true if `CLICOLOR` is != 0', function () {
process.env.CLICOLOR = 1;
var result = requireUncached('./');
assert.equal(Boolean(result), true);
assert.equal(result.level, 1);
});

it('should return false if not TTY', function () {
process.stdout.isTTY = false;
var result = requireUncached('./');
Expand Down

0 comments on commit ac01715

Please sign in to comment.