mirror of
https://github.com/clap-rs/clap
synced 2024-11-14 16:47:21 +00:00
fix(clap): Early line wrap ascii control chars
counting ascii control sequences lead to unpredictable and early line breaks on colorized inputs (e.g. syntax highlighted strings)
This commit is contained in:
parent
93648df153
commit
95c638842a
1 changed files with 13 additions and 1 deletions
|
@ -54,8 +54,20 @@
|
|||
#[inline(never)]
|
||||
pub(crate) fn display_width(text: &str) -> usize {
|
||||
let mut width = 0;
|
||||
|
||||
let mut control_sequence = false;
|
||||
let control_terminate: char = 'm';
|
||||
|
||||
for ch in text.chars() {
|
||||
width += ch_width(ch);
|
||||
if ch.is_ascii_control() {
|
||||
control_sequence = true;
|
||||
} else if control_sequence && ch == control_terminate {
|
||||
control_sequence = false;
|
||||
}
|
||||
|
||||
if !control_sequence {
|
||||
width += ch_width(ch);
|
||||
}
|
||||
}
|
||||
width
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue