summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
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 => { }
       }