Skip to content

Commit

Permalink
Merge pull request #4361 from hargut/fix/dont-count-control-character…
Browse files Browse the repository at this point in the history
…s-in-line-wrap

fix(clap): line wrap on strings that contain ascii control characters
  • Loading branch information
epage committed Oct 9, 2022
2 parents 93648df + 505f760 commit db7439f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/output/textwrap/core.rs
Expand Up @@ -54,8 +54,21 @@
#[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;
continue;
}

if !control_sequence {
width += ch_width(ch);
}
}
width
}
Expand Down

0 comments on commit db7439f

Please sign in to comment.