diff options
author | Irene Knapp <ireneista@gmail.com> | 2021-06-07 09:13:50 -0700 |
---|---|---|
committer | Irene Knapp <ireneista@gmail.com> | 2021-06-07 09:13:50 -0700 |
commit | 49f760b5657823706503873f3088eb5982932cb4 (patch) | |
tree | ae8f848756bad2bdd65324342f5edf9534ea9321 /src | |
parent | 2d5e6c6a0758a39ac16de217bc4bd6bd53104d1c (diff) |
draw backspaces
Diffstat (limited to 'src')
-rw-r--r-- | src/terminal.rs | 12 |
1 files changed, 11 insertions, 1 deletions
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<InputStream: AsyncRead + AsRawFd + Unpin> Terminal<InputStream> { pub async fn handle_input(&mut self) -> Result<Input> { + let mut stdout = io::stdout(); + loop { let mut action: Option<InputAction> = None; @@ -207,7 +213,6 @@ impl<InputStream: AsyncRead + AsRawFd + Unpin> Terminal<InputStream> { _ => { 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<InputStream: AsyncRead + AsRawFd + Unpin> Terminal<InputStream> { } 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 => { } } |