diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e012aa..a01f614 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ Procedure when bumping the version number: ## Unreleased +### Fixed +- Width measurements of ASCII control characters + ## v0.2.2 - 2024-01-14 ### Fixed diff --git a/src/widthdb.rs b/src/widthdb.rs index 7d18570..200765f 100644 --- a/src/widthdb.rs +++ b/src/widthdb.rs @@ -101,6 +101,15 @@ impl WidthDb { return Ok(()); } for grapheme in self.requested.drain() { + 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 + // assign each control character a with of 0. + self.known.insert(grapheme, 0); + continue; + } + out.queue(Clear(ClearType::All))? .queue(MoveTo(0, 0))? .queue(Print(&grapheme))?;