From ac01715624c3714d900089fc27ec0e4fcee3578f 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 | 13 +++++++++++++ test.js | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/index.js b/index.js index 113040d..0ab02de 100644 --- a/index.js +++ b/index.js @@ -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; } diff --git a/test.js b/test.js index 034b8bb..0963f39 100644 --- a/test.js +++ b/test.js @@ -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('./');