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

Support text wrapping and added correct splitting of strings containing ANSI style codes #36

Closed
wants to merge 5 commits into from

Conversation

Areadrill
Copy link

This PR resolves #16 and also fixes #35.

A condition was added to see whether the size of the content together with padding and margin would be larger than the number of columns available and if so it would use wrap-ansi to bring the content down to a size where the content fits just right on the terminal.

Also, when the string to place within the box contains ANSI codes, a new method will be used to split the strnig which correctly places ANSI style codes in order to maintain the expected style both on the string and the box.

@@ -60,6 +63,45 @@ const getBorderChars = borderStyle => {
return chars;
};

const splitAnsiCorrectly = text => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "correctly"? Why cannot wrap-ansi be used directly?

for (const len of lineLengths) {
t.is(len, process.stdout.columns);
}
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this feature needs a lot more tests. It's a difficult feature with a lot of potential issues.

@sindresorhus
Copy link
Owner

I seem to have missed this PR... If you're still interested in finishing this, could you fix the merge conflict?

@Areadrill
Copy link
Author

Areadrill commented Jun 12, 2019

Hi! I can definitely take a look at this again, but it will take me a bit to get reacquainted, since this PR is now a year old.

To answer your question:

What do you mean by "correctly"? Why cannot wrap-ansi be used directly?

If I recall correctly, at the time when I developed this, the introduction of newlines in the text screwed up the ANSI codes a bit, so I made a method in which they could be applied correctly. I seem to recall having made an issue about this. (Issue #35 )

@Areadrill
Copy link
Author

I haven't forgotten this, I've simply not had the time to work on it. I probably will progress with this issue in the next couple of weeks.

@sindresorhus
Copy link
Owner

Bump

@Areadrill
Copy link
Author

Hi! So yeah, a lot of stuff happened in between and I kind of lost track of this... I'll see if I can manage to work on this during the weekend (this time for real!)

@Areadrill
Copy link
Author

I feel like I've been putting this off for a while now, but I swear that every single weekend I've had has been super busy. I will try to do this ASAP.

@Areadrill Areadrill closed this Nov 24, 2019
@Areadrill Areadrill reopened this Nov 24, 2019
@Areadrill
Copy link
Author

Missclicked, my bad

@lukaszmn lukaszmn mentioned this pull request May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strange behaviour when combining chalk and wrap-ansi as input Support text wrapping
2 participants