chalk / wrap-ansi

Wordwrap a string with ANSI escape codes
MIT License
120 stars 25 forks source link

Improve handling of invisible sequences in trim mode #33

Closed stroncium closed 5 years ago

stroncium commented 5 years ago

Added tests from #32 and fixed code to pass them.

sindresorhus commented 5 years ago

I merged https://github.com/chalk/wrap-ansi/pull/32, can you rebase and remove the .failing part from that test instead? I think it makes more sense to keep it as a separate test.

sindresorhus commented 5 years ago

// @coreyfarrell

coreyfarrell commented 5 years ago

@sindresorhus I've just realized another question - should strings be wrapped before or after trimming? Currently wrapping is done before trimming which produces the following results:

// 3 spaces before / between / after
t.is(wrapAnsi('   foo   bar   ', 6), 'foo\nbar');
t.is(wrapAnsi('   foo   bar   ', 3), '\nfoo\n\nbar\n');
stroncium commented 5 years ago

@coreyfarrell @sindresorhus It's not a question of trim first or not(trimming is not just a stage), it's a bug, and I guess part of it was introduced by my big patch. Anyhow, added test, fixed.

coreyfarrell commented 5 years ago

@stroncium I just verified that all cliui tests now pass when wrap-ansi code is updated with this PR. Thanks!

sindresorhus commented 5 years ago

Thanks for fixing, @stroncium 👍