Skip to content

Commit

Permalink
pin unicode-width below v0.1.13 to fix rendering issues
Browse files Browse the repository at this point in the history
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] unicode-rs/unicode-width@3063422
[2] unicode-rs/unicode-width#55
  • Loading branch information
aswild committed Jul 30, 2024
1 parent 9c34879 commit fac04a5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
};
Expand Down

0 comments on commit fac04a5

Please sign in to comment.