diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-11-12 15:30:59 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-11-12 15:30:59 -0500 |
commit | cab27fc4ead3becc39185443dfa1f2fb51291fa4 (patch) | |
tree | 408a9997bc61b0db1e6d928d29dde8f8110665c4 | |
parent | a0120cd78144417f2f337087d8b4b83b7dd7a52d (diff) | |
download | nbsh-cab27fc4ead3becc39185443dfa1f2fb51291fa4.tar.gz nbsh-cab27fc4ead3becc39185443dfa1f2fb51291fa4.zip |
handle backspacing over combined characters properly
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/readline.rs | 7 |
3 files changed, 8 insertions, 1 deletions
@@ -385,6 +385,7 @@ dependencies = [ "signal-hook-async-std", "terminal_size", "textmode", + "unicode-width", "vt100", ] @@ -16,6 +16,7 @@ signal-hook = "0.3.10" signal-hook-async-std = "0.2.1" terminal_size = "0.1.17" textmode = { path = "../textmode", version = "0.1.1", features = ["async"] } +unicode-width = "0.1.9" vt100 = { path = "../vt100-rust", version = "0.12.0" } [features] diff --git a/src/readline.rs b/src/readline.rs index ff5f9a9..37fc054 100644 --- a/src/readline.rs +++ b/src/readline.rs @@ -1,4 +1,5 @@ use textmode::Textmode as _; +use unicode_width::UnicodeWidthChar as _; pub struct Readline { size: (u16, u16), @@ -74,7 +75,11 @@ impl Readline { } fn backspace(&mut self) { - self.input_line.pop(); + let mut width = 0; + while width == 0 { + width = + self.input_line.pop().map_or(1, |c| c.width().unwrap_or(0)); + } } fn clear_input(&mut self) { |