From cab27fc4ead3becc39185443dfa1f2fb51291fa4 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 12 Nov 2021 15:30:59 -0500 Subject: handle backspacing over combined characters properly --- Cargo.lock | 1 + Cargo.toml | 1 + src/readline.rs | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 77c5df0..1edc916 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -385,6 +385,7 @@ dependencies = [ "signal-hook-async-std", "terminal_size", "textmode", + "unicode-width", "vt100", ] diff --git a/Cargo.toml b/Cargo.toml index 9e1c444..e5cb362 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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) { -- cgit v1.2.3-54-g00ecf