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 --- tests/client_ui.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests') diff --git a/tests/client_ui.rs b/tests/client_ui.rs index ea432e0..f5e3c0e 100644 --- a/tests/client_ui.rs +++ b/tests/client_ui.rs @@ -98,6 +98,23 @@ fn redraw_moves_up_by_line_count_minus_one() { assert_eq!(lines_to_move_up(70_000), u16::MAX); } +#[test] +fn display_width_ignores_ansi_sequences() { + assert_eq!(display_width("\x1b[31m18\x1b[0m"), 2); + assert_eq!(display_width("\x1b[1;31m[ 18 ]\x1b[0m"), 6); + assert_eq!(display_width("plain"), 5); +} + +#[test] +fn visual_line_count_ignores_ansi_sequences() { + let styled = format!("\x1b[31m{}\x1b[0m", "x".repeat(75)); + assert_eq!(visual_line_count(&[styled], 72), 2); + assert_eq!( + visual_line_count(&["\x1b[31m18\x1b[0m".to_string()], 80), + 1 + ); +} + #[test] fn visual_line_count_accounts_for_terminal_wrapping() { let lines = vec![ -- cgit v1.2.3