From 49f760b5657823706503873f3088eb5982932cb4 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Mon, 7 Jun 2021 09:13:50 -0700 Subject: draw backspaces --- src/terminal.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/terminal.rs b/src/terminal.rs index f42d153..7b6cda7 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -71,6 +71,10 @@ impl LineBuffer { pub fn as_string(&self) -> String { self.lines.join("\n") } + + pub fn cursor_to_end_of_line(&self) -> &str { + &self.lines[self.cursor.y][self.cursor.x ..] + } } @@ -181,6 +185,8 @@ impl Terminal { pub async fn handle_input(&mut self) -> Result { + let mut stdout = io::stdout(); + loop { let mut action: Option = None; @@ -207,7 +213,6 @@ impl Terminal { _ => { self.line_buffer.insert(&c.to_string()); - let mut stdout = io::stdout(); stdout.write_all(format!("{}", c).as_bytes()).await .map_err(error::internal)?; stdout.flush().await.map_err(error::internal)?; @@ -232,6 +237,11 @@ impl Terminal { } Some(InputAction::Backspace) => { self.line_buffer.backspace(); + + stdout.write_all(format!("\u{08}\u{1b}[1X{}", + self.line_buffer.cursor_to_end_of_line()) + .as_bytes()).await.map_err(error::internal)?; + stdout.flush().await.map_err(error::internal)?; } None => { } } -- cgit 1.4.1