about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-01-27 23:57:37 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-01-27 23:57:37 -0800
commit6533cdd047c09591aa9f93f8861f88cf3c869239 (patch)
treeaa090320b37338b4f31dfc06da8ae53ec2df0ba1
parent12d7cee846eac0b1d6f05e6d78036ace04728b94 (diff)
downloadmu-6533cdd047c09591aa9f93f8861f88cf3c869239.tar.gz
648
Extract a function; baby steps to better backspace support.
-rw-r--r--color-repl.mu38
1 files changed, 21 insertions, 17 deletions
diff --git a/color-repl.mu b/color-repl.mu
index 442f3f60..fcbc75de 100644
--- a/color-repl.mu
+++ b/color-repl.mu
@@ -150,23 +150,7 @@
     { begin
       (backslash?:boolean <- equal c:character ((#\\ literal)))
       (break-unless backslash?:boolean)
-      ; slurp an extra key
-      { begin
-        (c2:character <- $wait-for-key-from-host)
-        ($print-key-to-host c2:character 6:literal/fg/cyan)
-        ; handle backspace
-        ; test: "abc\<backspace>def"
-        { begin
-          (backspace?:boolean <- equal c2:character ((#\backspace literal)))
-          (break-unless backspace?:boolean)
-          (len:integer-address <- get-address result:buffer-address/deref length:offset)
-          ; just typed a backslash, so buffer can't be empty
-          (len:integer-address/deref <- subtract len:integer-address/deref 1:literal)
-          (jump next-key-in-string:offset)
-        }
-        ; if not backspace
-        (result:buffer-address <- append result:buffer-address c2:character)
-      }
+      (result:buffer-address <- slurp-escaped-character result:buffer-address)
       (jump next-key-in-string:offset)
     }
     ; if not backslash
@@ -176,6 +160,26 @@
   end
 ])
 
+(function slurp-escaped-character [
+  (default-space:space-address <- new space:literal 30:literal)
+  (result:buffer-address <- next-input)
+  (c2:character <- $wait-for-key-from-host)
+  ($print-key-to-host c2:character 6:literal/fg/cyan)
+  ; handle backspace
+  ; test: "abc\<backspace>def"
+  { begin
+    (backspace?:boolean <- equal c2:character ((#\backspace literal)))
+    (break-unless backspace?:boolean)
+    (len:integer-address <- get-address result:buffer-address/deref length:offset)
+    ; just typed a backslash, so buffer can't be empty
+    (len:integer-address/deref <- subtract len:integer-address/deref 1:literal)
+    (reply result:buffer-address/same-as-arg:0)
+  }
+  ; if not backspace
+  (result:buffer-address <- append result:buffer-address c2:character)
+  (reply result:buffer-address/same-as-arg:0)
+])
+
 (function main [
   (default-space:space-address <- new space:literal 30:literal)
   (cursor-mode)