From 05f87e25e108726ee469aa56cc88fcc160a911ed Mon Sep 17 00:00:00 2001 From: Martin Heidegger Date: Sun, 17 Jan 2016 12:35:27 +0100 Subject: [PATCH] Close #92 PR: 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 f2377a2..b7e3b10 100644 --- a/index.js +++ b/index.js @@ -79,6 +79,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 d753917..9dddc2f 100644 --- a/test.js +++ b/test.js @@ -68,6 +68,10 @@ describe('chalk', function () { assert.equal(chalk.reset(chalk.red.bgGreen.underline.bind(null)('foo') + 'foo'), '\u001b[0m\u001b[31m\u001b[42m\u001b[4mfoo\u001b[24m\u001b[49m\u001b[39mfoo\u001b[0m'); assert.equal(chalk.red.blue.black.call(null), ''); }); + + 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 () {