From 02ad6909c7875d691a26a6d39f0d3e4621da6485 Mon Sep 17 00:00:00 2001 From: Sam Verschueren Date: Fri, 21 Jul 2017 13:31:40 +0200 Subject: [PATCH] Fix no word wrap bug - fixes #18 (#19) --- index.js | 5 +++++ test.js | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index ff62543..c4fef39 100755 --- a/index.js +++ b/index.js @@ -131,6 +131,11 @@ function exec(str, cols, opts) { rows.push(''); } + if (rowLength + lengths[i] > cols && options.wordWrap === false) { + wrapWord(rows, word, cols); + continue; + } + rows[rows.length - 1] += word; } diff --git a/test.js b/test.js index dec3a24..ace8b33 100755 --- a/test.js +++ b/test.js @@ -81,8 +81,11 @@ test('no word-wrapping', t => { const res = fn(fixture3, 15, {wordWrap: false}); t.is(res, '12345678\n901234567890 12\n345'); - const res2 = fn(fixture, 5, {wordWrap: false}); - t.is(res2, 'The q\nuick\nbrown\nfox j\numped\nover\nthe l\nazy d\nog an\nd the\nn ran\naway\nwith\nthe u\nnicor\nn.'); + const res2 = fn(fixture3, 5, {wordWrap: false}); + t.is(res2, '12345\n678\n90123\n45678\n90 12\n345'); + + const res3 = fn(fixture, 5, {wordWrap: false}); + t.is(res3, 'The q\nuick\nbrown\nfox j\numped\nover\nthe l\nazy d\nog an\nd the\nn ran\naway\nwith\nthe u\nnicor\nn.'); }); // /~https://github.com/chalk/wrap-ansi/issues/10