about summary refs log tree commit diff stats
path: root/061channel.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-10 08:34:12 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-10 08:55:18 -0700
commitdc1323e936fb79823767f85529be15e0456b3169 (patch)
treea3313c1c41ffd67a506f92dabc77c7867a8c8dd9 /061channel.mu
parent3f367cb9466131f95c11c24df3aac7057143587b (diff)
downloadmu-dc1323e936fb79823767f85529be15e0456b3169.tar.gz
1323 - keyboard supports backspace and newline
Lots mixed into this commit:
  some off-by-one errors in display.cc
  a new transform to translate jump labels that I'd somehow never gotten around to supporting
Diffstat (limited to '061channel.mu')
-rw-r--r--061channel.mu31
1 files changed, 30 insertions, 1 deletions
diff --git a/061channel.mu b/061channel.mu
index 33b2566f..79f4dd02 100644
--- a/061channel.mu
+++ b/061channel.mu
@@ -276,13 +276,38 @@ recipe buffer-lines [
     line:address:buffer <- init-buffer, 30:literal
     # read characters from 'in' until newline, copy into line
     {
+      +next-character
       c:character, in:address:channel <- read in:address:channel
-      # todo: handle backspace
+      # drop a character on backspace
+      {
+        # special-case: if it's a backspace
+        backspace?:boolean <- equal c:character, 8:literal
+        break-unless backspace?:boolean
+        # drop previous character
+#?         return-to-console #? 2
+#?         $print [backspace! #? 1
+#? ] #? 1
+        buffer-length:address:integer <- get-address line:address:buffer/deref, length:offset
+        {
+          buffer-empty?:boolean <- equal buffer-length:address:integer/deref, 0:literal
+          break-if buffer-empty?:boolean
+#?           $print [before: ], buffer-length:address:integer/deref, [ #? 1
+#? ] #? 1
+          buffer-length:address:integer/deref <- subtract buffer-length:address:integer/deref, 1:literal
+#?           $print [after: ], buffer-length:address:integer/deref, [ #? 1
+#? ] #? 1
+        }
+#?         $exit #? 2
+        # and don't append this one
+        loop +next-character:label
+      }
+      # append anything else
       line:address:buffer <- buffer-append line:address:buffer, c:character
       line-done?:boolean <- equal c:character, 13:literal/newline
       break-if line-done?:boolean
       loop
     }
+#?     return-to-console #? 1
     # copy line into 'out'
     i:integer <- copy 0:literal
     line-contents:address:array:character <- get line:address:buffer/deref, data:offset
@@ -292,9 +317,13 @@ recipe buffer-lines [
       break-if done?:boolean
       c:character <- index line-contents:address:array:character/deref, i:integer
       out:address:channel <- write out:address:channel, c:character
+#?       $print [writing ], i:integer, [: ], c:character, [ #? 1
+#? ] #? 1
       i:integer <- add i:integer, 1:literal
       loop
     }
+#?     $dump-trace #? 1
+#?     $exit #? 1
     loop
   }
   reply out:address:channel/same-as-ingredient:1