From 4d2daef57a1896d1bd591147f9184c7c0253c646 Mon Sep 17 00:00:00 2001 From: Jorik Tangelder Date: Mon, 21 Mar 2016 21:44:47 +0100 Subject: [PATCH 1/2] correct ansi colors for 16 colors environments --- lib/report/common/defaults.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/report/common/defaults.js b/lib/report/common/defaults.js index 9c7d7881..fae736fe 100644 --- a/lib/report/common/defaults.js +++ b/lib/report/common/defaults.js @@ -25,11 +25,12 @@ module.exports = { colorize: function (str, clazz) { /* istanbul ignore if: untestable in batch mode */ if (supportsColor) { - switch (clazz) { - case 'low' : str = '\x1B[91m' + str + '\x1B[0m'; break; - case 'medium': str = '\x1B[93m' + str + '\x1B[0m'; break; - case 'high': str = '\x1B[92m' + str + '\x1B[0m'; break; - } + var colors = { + low: '31;1', + medium: '33;1', + high: '32;1' + }; + return '\u001b[' + colors[clazz] + 'm' + str + '\u001b[0m'; } return str; }, From 0411600a679224e79edd82710e1f5c74558710be Mon Sep 17 00:00:00 2001 From: Jorik Tangelder Date: Wed, 6 Apr 2016 09:34:43 +0200 Subject: [PATCH 2/2] return plain string when an invalid clazz is given --- lib/report/common/defaults.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/report/common/defaults.js b/lib/report/common/defaults.js index fae736fe..a9851c32 100644 --- a/lib/report/common/defaults.js +++ b/lib/report/common/defaults.js @@ -24,12 +24,13 @@ module.exports = { colorize: function (str, clazz) { /* istanbul ignore if: untestable in batch mode */ - if (supportsColor) { - var colors = { - low: '31;1', - medium: '33;1', - high: '32;1' - }; + var colors = { + low: '31;1', + medium: '33;1', + high: '32;1' + }; + + if (supportsColor && colors[clazz]) { return '\u001b[' + colors[clazz] + 'm' + str + '\u001b[0m'; } return str;