-
Notifications
You must be signed in to change notification settings - Fork 30
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
Wrapping doesn't take into account ansi color sequences. #26
Comments
Related to #17 |
@muffinresearch Another possible solution would be to enable passing chalk or chalk-like function to be used on the text after the wrapping, but since this was "Designed to handle sensible wrapping in npm search results.", I'm unsure as to what non-trivial features would be added if not to serve the that intended purpose, so we'll have to wait for Tim's take on this to be sure. |
fwiw and in-case it's useful for inspiration - there's wrap-ansi [1] that performs a similar operation in terms of splitting strings for wrapping and and handling ansi escape codes. |
Yes, this might make it pretty simple, and could also be used to fix #17. |
A partial work-around suggestion for anyone who ends up here: truncate your strings before passing them to const truncateString = (string, len) => (string.length <= len) ? string : string.substr(0, len - 1)+'…';
const data = {
date: chalk.bold.yellow(date),
repo: chalk.green(truncateString(repo, 25)),
title: truncateString(title, 50),
};
console.log(columnify(data));
} |
|
If the text that's being wrapped has ansi color codes the colors bleed into the other columns because the colorized string is split when it's wrapped and as a result the color codes are wrapping more than the intended text when the output lines are assembled.
Here's a test case (using chalk for the ansi colours):
Here's the output:
The text was updated successfully, but these errors were encountered: