Multiple escape sequences not distributed to each line #49
uhyo posted onGitHub
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
<img width="111" alt="γΉγ―γͺγΌγ³γ·γ§γγ 2022-07-21 0 05 55" src="https://user-images.githubusercontent.com/748348/180016785-bd5df054-9340-4d9c-809a-ff80208c1470.png">
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.