You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes you want to put some color on the text inside of the Box.
Right now, if you do it Boxx will improperly calculate the length of the line where the colors are used.
See attached screenshot:
Some code that can trigger this is:
let message = format!("There's a new version of the software! {} → {}\nUpdate with {}",
"11".red(),
"12".green(),
"software self-update".green().bold());Boxx::builder().border_style(BorderStyle::Round).build().display(&message);
I think this can be easily solved by using a "cleaning" function over the provided text to Boxx, so ansi characters are cleaned out, similar to the following implementation in JS:
/** This function removes the ansi escape characters (normally used for printing colors and so) Inspired by: https://github.com/chalk/ansi-regex/blob/master/index.js MIT License Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) */constcleanStdout=(stdout)=>{constpattern=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");constregexPattern=newRegExp(pattern,"g");returnstdout.replace(regexPattern,"");};
The text was updated successfully, but these errors were encountered:
syrusakbary
changed the title
Boxx layout is incorrect when text have ansi characters on it
Boxx layout is incorrect when text have ansi escape characters on it
Feb 18, 2020
Sometimes you want to put some color on the text inside of the Box.
Right now, if you do it
Boxx
will improperly calculate the length of the line where the colors are used.See attached screenshot:
Some code that can trigger this is:
I think this can be easily solved by using a "cleaning" function over the provided text to
Boxx
, so ansi characters are cleaned out, similar to the following implementation in JS:More context on the issue here: wasmerio/wapm-cli#169
The text was updated successfully, but these errors were encountered: