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

Multiple escape sequences not distributed to each line #49

Closed
uhyo opened this issue Jul 20, 2022 · 1 comment
Closed

Multiple escape sequences not distributed to each line #49

uhyo opened this issue Jul 20, 2022 · 1 comment

Comments

@uhyo
Copy link

uhyo commented Jul 20, 2022

Hi, thank you for the great package!

Bug Report

wrap-ansi can distribute escape sequence to wrapped lines. However, if there are multiple escape sequences only one of them is distributed.

Code

import chalk from 'chalk';
import wrapAnsi from 'wrap-ansi';

const greenString = chalk.green('This is a green string.')

console.log(splitWithRedLines(wrapAnsi(greenString, 10)));

const boldString = chalk.bold('This is a bold string.')

console.log(splitWithRedLines(wrapAnsi(boldString, 10)));

const blueBoldString = chalk.blue.bold('This is a blue and bold string.')

console.log(splitWithRedLines(wrapAnsi(blueBoldString, 10)));

function splitWithRedLines(string) {
  return string.split("\n").join(chalk.red("\n---\n"))
}

Result

スクリーンショット 2022-07-21 0 05 55

For greenString and boldString, corresponding escape sequences (\x1B[32m and \x1B[1m) are correctly copied to each line of resulting string.

However, for blueBoldString which contains two escape sequences (\x1B[34m\x1B[1m), only one of them (\x1B[1m) is copied to each line, and the other (\x1B[34m) remains at the very start of the resulting string.

As a result, the resulting string may break when another styled string intervenes the lines.

@uhyo
Copy link
Author

uhyo commented Jul 20, 2022

Sorry, duplicate of #43.

@uhyo uhyo closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2022
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

No branches or pull requests

1 participant