From fac04a5cf26528d5590feaa01828030023b79c96 Mon Sep 17 00:00:00 2001 From: Allen Wild Date: Tue, 30 Jul 2024 12:05:12 -0400 Subject: [PATCH] pin unicode-width below v0.1.13 to fix rendering issues unicode-width's change "Control characters have width 1" between versions 0.1.12 and 0.1.13 changed the logic so that control characters are asumed to have width of 1 rather than 0 width [1]. This breaks skim's rendering pretty badly unfortunately, mainly by not erasing cells that should be erased, so the output looks garbled. Apparently this change broke other parts of the ecosystem too, such as the (actually-maintained, unlike tuikit) ratatui crate. There's some good discussion in [2] about how fundamentally unicode-width is not intended to be "how wide does this draw in a terminal emulator", despite many people using it that way. Other options should be explored longer term (if I decide to meaningfully pick up maintenance of skim), such as the unicode-display-width crated which is mentioned in [2] but still might not be the right algorithm. I think really the proper fix is to strip control characters within skim (or the TUI library) before doing anything to determine the unicode width. But for now, take the easy way out and just pin the unicode-width version to something below 0.1.13 and forget about it until I have more time to put into caring about improving skim. P.S. Change .width_cjk() to .width() in a couple places for consistency. [1] https://github.com/unicode-rs/unicode-width/commit/3063422f38039be82db2b3bd331c8a9f42d57ef1 [2] https://github.com/unicode-rs/unicode-width/issues/55 --- Cargo.toml | 2 +- src/selection.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1845e53d..add9fffb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ nix = "0.26" atty = { version = "0.2.14", optional = true } regex = "1.6.0" shlex = { version = "1.1.0", optional = true } -unicode-width = "0.1.9" +unicode-width = "0.1.9, <0.1.13" log = "0.4.17" env_logger = { version = "0.10", optional = true } time = "0.3.13" diff --git a/src/selection.rs b/src/selection.rs index 568b561b..c5b7e9fe 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -339,7 +339,7 @@ impl Selection { } else { let regex = self.skip_to_pattern.as_ref().unwrap(); if let Some(mat) = regex.find(text) { - text[..mat.start()].width_cjk() + text[..mat.start()].width() } else { 0 } @@ -512,7 +512,7 @@ impl Selection { .col(2) .tabstop(self.tabstop) .container_width(container_width) - .text_width(display_content.stripped().width_cjk()) + .text_width(display_content.stripped().width()) .hscroll_offset(self.hscroll_offset) .build() };