From 9fee69fe4870649b3c2118ad731db73c2b48282a Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Thu, 22 Oct 2015 13:18:01 +0200 Subject: [PATCH] Check for CLICOLOR and CLICOLOR_FORCE. Fixes #31 and #32. --- index.js | 14 ++++++++++++++ test.js | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/index.js b/index.js index 113040d..ad4de6b 100644 --- a/index.js +++ b/index.js @@ -38,6 +38,20 @@ 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; } diff --git a/test.js b/test.js index 034b8bb..52da8fa 100644 --- a/test.js +++ b/test.js @@ -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('./');