summaryrefslogtreecommitdiffstats
path: root/src/readline.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-11-12 15:30:59 -0500
committerJesse Luehrs <doy@tozt.net>2021-11-12 15:30:59 -0500
commitcab27fc4ead3becc39185443dfa1f2fb51291fa4 (patch)
tree408a9997bc61b0db1e6d928d29dde8f8110665c4 /src/readline.rs
parenta0120cd78144417f2f337087d8b4b83b7dd7a52d (diff)
downloadnbsh-cab27fc4ead3becc39185443dfa1f2fb51291fa4.tar.gz
nbsh-cab27fc4ead3becc39185443dfa1f2fb51291fa4.zip
handle backspacing over combined characters properly
Diffstat (limited to 'src/readline.rs')
-rw-r--r--src/readline.rs7
1 files changed, 6 insertions, 1 deletions
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) {