Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URLs larger than column always begin on new line #38

Open
nicholaschiasson opened this issue Sep 19, 2019 · 2 comments
Open

URLs larger than column always begin on new line #38

nicholaschiasson opened this issue Sep 19, 2019 · 2 comments

Comments

@nicholaschiasson
Copy link
Contributor

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

@sindresorhus
Copy link
Member

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

@nicholaschiasson
Copy link
Contributor Author

nicholaschiasson commented Apr 16, 2020

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:

wrap-ansi/index.js

Lines 122 to 127 in a28eb7d

const remainingColumns = (columns - rowLength);
const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
if (breaksStartingNextLine < breaksStartingThisLine) {
rows.push('');
}

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! 😄

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants