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 Jan 5, 2016
1 parent 711d47f commit db40abd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ var supportLevel = (function () {
return 1;
}

if (process.env.CLICOLOR === '0') {
return 0;
}

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

if (process.stdout && !process.stdout.isTTY) {
return 0;
}
Expand Down Expand Up @@ -65,7 +73,8 @@ var supportLevel = (function () {
return 0;
})();

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

Expand Down
21 changes: 21 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ 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), false);
});

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 db40abd

Please sign in to comment.