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

Handle spaces inside background color escapes #29

Closed
wants to merge 3 commits into from
Closed

Handle spaces inside background color escapes #29

wants to merge 3 commits into from

Conversation

vadimdemedes
Copy link

Fixes #27.

The original issue is about wrap-ansi stripping the beginning space, if string is wrapped into an ansi escape (usually colors). I think it's ok for chalk.green(' hello '), because spaces won't be colorized anyway. However, for chalk.bgGreen(' hello ') this results in:

Reason it was happening is because wrap-ansi splits input string by space here https://github.com/chalk/wrap-ansi/blob/master/index.js#L82.

const words = chalk.bgGreen(' hello ');
const parts = words.split(' ');
//=> ['opening escape', 'hello', 'closing escape']

This PR fixes this case by scanning result of split() and joining opening escape, content and closing escape (following is pseudo code).

const normalizedParts = normalizeParts(parts);
//=> ['opening escape hello closing escape']

This PR is still failing, because it doesn't yet handle chalk.bgGreen(' hello ' + chalk.red('world')) case. Any help is appreciated!

@vadimdemedes vadimdemedes marked this pull request as ready for review February 28, 2019 07:17
@vadimdemedes
Copy link
Author

I asked the author of #30 to copy tests from this PR, so that I can close this one, since the other one fixes many issues at once and has way less code.

@sindresorhus
Copy link
Member

@vadimdemedes Can this be closed now?

@vadimdemedes
Copy link
Author

Oh yes, sorry, forgot!

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.

leading space removed when line starts with ansi escape
2 participants