summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@gmail.com>2021-06-07 09:13:50 -0700
committerIrene Knapp <ireneista@gmail.com>2021-06-07 09:13:50 -0700
commit49f760b5657823706503873f3088eb5982932cb4 (patch)
treeae8f848756bad2bdd65324342f5edf9534ea9321 /src
parent2d5e6c6a0758a39ac16de217bc4bd6bd53104d1c (diff)
draw backspaces
Diffstat (limited to 'src')
-rw-r--r--src/terminal.rs12
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 => { }
       }