From 1618264cb701917e90353b70bc6edd534bfdecd8 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 20 Feb 2025 21:24:07 +0100 Subject: [PATCH] Fix newlines causing bad rendering artifacts The unicode-width crate has started to consider newlines to have a width of 1 instead of 0. --- src/widthdb.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/widthdb.rs b/src/widthdb.rs index 200765f..9815190 100644 --- a/src/widthdb.rs +++ b/src/widthdb.rs @@ -47,9 +47,13 @@ impl WidthDb { if grapheme == "\t" { return self.tab_width_at_column(col); } + if grapheme.chars().any(|c| c.is_ascii_control()) { + return 0; // See measure_widths function + } if !self.active { return grapheme.width() as u8; } + if let Some(width) = self.known.get(grapheme) { *width } else { @@ -101,7 +105,7 @@ impl WidthDb { return Ok(()); } for grapheme in self.requested.drain() { - if grapheme.chars().any(|c|c.is_ascii_control()){ + if grapheme.chars().any(|c| c.is_ascii_control()) { // ASCII control characters like the escape character or the // bell character tend to be interpreted specially by terminals. // This may break width measurements. To avoid this, we just