about summary refs log tree commit diff stats
path: root/516read-line.mu
diff options
context:
space:
mode:
Diffstat (limited to '516read-line.mu')
-rw-r--r--516read-line.mu13
1 files changed, 12 insertions, 1 deletions
diff --git a/516read-line.mu b/516read-line.mu
index 1bb79c5a..5c96a832 100644
--- a/516read-line.mu
+++ b/516read-line.mu
@@ -2,13 +2,24 @@
 # abort on stream overflow
 fn read-line-from-keyboard keyboard: (addr keyboard), out: (addr stream byte), screen: (addr screen), fg: int, bg: int {
   clear-stream out
-  {
+  $read-line-from-keyboard:loop: {
     draw-cursor screen, 0x20/space
     var key/eax: byte <- read-key keyboard
     compare key, 0xa/newline
     break-if-=
     compare key, 0
     loop-if-=
+    compare key, 8/backspace
+    {
+      break-if-!=
+      undo-append-byte out
+      draw-code-point-at-cursor-over-full-screen screen, 0x20/space, fg 0/bg  # clear cursor
+      move-cursor-left screen
+      move-cursor-left screen
+      draw-code-point-at-cursor-over-full-screen screen, 0x20/space, fg 0/bg  # clear old cursor
+      move-cursor-left screen
+      loop $read-line-from-keyboard:loop
+    }
     var key2/eax: int <- copy key
     append-byte out, key2
     var c/eax: code-point <- copy key2