From ee9405d00f4042fe812a73b367869bc788319d11 Mon Sep 17 00:00:00 2001 From: Martin Heidegger Date: Wed, 16 Dec 2015 00:15:35 +0900 Subject: [PATCH] Closing before and reopening the style after a line break --- index.js | 5 +++++ test.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/index.js b/index.js index d2ec92d..fa9863e 100644 --- a/index.js +++ b/index.js @@ -83,6 +83,11 @@ function applyStyle() { // otherwise only the part of the string until said closing code // will be colored, and the rest will simply be 'plain'. str = code.open + str.replace(code.closeRe, code.open) + code.close; + + // Close the coloring before a line break and reopening after next line + // To fix a bleed issue on macs + // see https://github.com/chalk/chalk/pull/92 + str = str.replace(/\n/gm, code.close + '\n' + code.open); } // Reset the original 'dim' if we changed it to work around the Windows dimmed gray issue. diff --git a/test.js b/test.js index 998d93d..93e1b59 100644 --- a/test.js +++ b/test.js @@ -61,6 +61,10 @@ describe('chalk', function () { it('don\'t output escape codes if the input is empty', function () { assert.equal(chalk.red(), ''); }); + + it('line breaks should open and close colors', function () { + assert.equal(chalk.grey('hello\nworld'), '\u001b[90mhello\u001b[39m\n\u001b[90mworld\u001b[39m'); + }); }); describe('chalk on windows', function () {