From eb68b1266ac833a00ee5a11b3e2d9a9d516d7a3c Mon Sep 17 00:00:00 2001 From: salmonik Date: Thu, 29 Oct 2026 17:25:50 +0100 Subject: v2.1.2: ignore ANSI when measuring board height --- src/client/ui.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/client/ui.rs b/src/client/ui.rs index 11cedc7..1a35db1 100644 --- a/src/client/ui.rs +++ b/src/client/ui.rs @@ -159,7 +159,29 @@ pub fn parse_bet_arg(raw: &str) -> Result { /// ASCII, Latin diacritics, combining marks, CJK, and the common emoji ranges /// without adding a dependency. pub fn display_width(text: &str) -> usize { - text.chars().map(char_width).sum() + let mut width = 0; + let mut chars = text.chars().peekable(); + + while let Some(character) = chars.next() { + if character == '\x1b' { + if chars.peek() == Some(&'[') { + chars.next(); + // Skip CSI parameters until the final byte (@ through ~). + for character in chars.by_ref() { + if ('@'..='~').contains(&character) { + break; + } + } + } else { + // Two-character escape sequence. + chars.next(); + } + continue; + } + width += char_width(character); + } + + width } fn char_width(c: char) -> usize { -- cgit v1.2.3