From 104da286b1a804a61f08315f34a238730337b1be Mon Sep 17 00:00:00 2001 From: pjht Date: Wed, 11 Sep 2024 13:49:17 -0500 Subject: [PATCH] Remove the last character in the render buffer on backspace --- src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3b2e704..0651975 100644 --- a/src/main.rs +++ b/src/main.rs @@ -263,11 +263,17 @@ impl FramebufferWriter { impl fmt::Write for FramebufferWriter { fn write_char(&mut self, c: char) -> fmt::Result { - self.out_string.push(c); + if c == '\u{8}' { + self.out_string.pop(); + } else { + self.out_string.push(c); + } Ok(()) } fn write_str(&mut self, s: &str) -> core::fmt::Result { - self.out_string.push_str(s); + for c in s.chars() { + self.write_char(c)?; + } Ok(()) } }