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

Inconsistant styling for strings with background and foreground. #43

Open
Brittany-Reid opened this issue Aug 5, 2020 · 1 comment
Open

Comments

@Brittany-Reid
Copy link

Something similar to slice-ansi: chalk/slice-ansi#22

My use case is wrapping strings to terminal width, and only showing some lines. The following example works as expected:

var string = chalk.bgGreen("test");
var wrapped = wrapAnsi(string, 2, {hard: true, trim: false, wordWrap: false});
var lines = wrapped.split("\n");
console.log(lines[0])
console.log(lines)

You can see that the background is properly ended for each line, this is the behavior I expect when I try background and foreground:

[ '\u001b[42mte\u001b[49m', '\u001b[42mst\u001b[49m' ]

When you add a foreground however, the background never stops.

var string = chalk.bgGreen.black('test');
var wrapped = wrapAnsi(string, 2, {hard: true, trim: false, wordWrap: false});
var lines = wrapped.split("\n");
console.log(lines[0])
console.log(lines)

Result:

image

[
  '\u001b[42m\u001b[30mte\u001b[39m',
  '\u001b[30mst\u001b[39m\u001b[49m'
]

You can see that the inner ansi style is applied and ended per line, but that the outer style is applied only once. I would expect the behavior to be consistent with the previous example.

Thanks!

@Brittany-Reid
Copy link
Author

My workaround for now is to just add the reset code \u001b[0m to the end of the line.

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