chalk/wrap-ansi

Do you want to work on this issue?

You can request for a bounty in order to promote it!

URLs larger than column always begin on new line #38

nicholaschiasson posted onGitHub

I've only noticed this happen with URLs and only with hard: true. Even with wordWrap: false it still happens as long as hard: true is passed.


Normal 'word':

> const wrapAnsi = require('wrap-ansi');
> console.log(wrapAnsi('hi, this IsAReallyLongWordButIDoNotKnowHowItShouldBehave', 32, {hard: true}));
hi, this IsAReallyLongWordButIDo
NotKnowHowItShouldBehave

āœ…


Hyperlink:

> const wrapAnsi = require('wrap-ansi');
> console.log(wrapAnsi('hi, this https://IsAReallyLongWordButIDoNotKnowHowItShouldBehave.com', 32, {hard: true}));
hi, this
https://IsAReallyLongWordButIDoN
otKnowHowItShouldBehave.com

āŒ


It would be helpful if someone could submit a pull request with failing tests :)

posted by sindresorhus about 5 years ago

As it happens, this is actually expected behaviour, I learned while debugging #37. The strange word wrap starting on the next line is actually the result of this section of code it seems:

https://github.com/chalk/wrap-ansi/blob/a28eb7d6cdbf91bccb56d04d095ca9463c15d3db/index.js#L122-L127

So I guess we can close this. I am curious though why it is written like this. By that I mean to ask, is it intentional that it doesn't check that the wordWrap option is false? I believe with options.hard === true and options.wordWrap === true, this behaviour makes sense (although maybe not in the case where the word is longer than columns and will need to wrap inevitably). With options.hard === false and options.wordWrap === false, we also get the expected behaviour, no new line and the word wraps without going over the column limit. However, I would have assumed that if options.hard === true and options.wordWrap === false, it should behave the same as both being false. This is not the case. If you wouldn't mind sharing some context about this, I would appreciate it. Otherwise, I think it's safe to close this, thanks! :smile:

My proposal now, unless everything is indeed working as intended, is that we open a new issue to tackle making sure there is no line break if the wordWrap option is set false. Please share your thoughts on this.

posted by nicholaschiasson almost 5 years ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests