about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-27 17:19:43 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-27 17:22:36 -0700
commit13a706e009d253f1c32cdbdbfb52646bee4906d3 (patch)
tree0b0678c29fb0ce086f7be81acdad9e4d9b2ef2b0
parent8cdfed6acb211a1f3c740cb372cc8745f18d181c (diff)
downloadmu-13a706e009d253f1c32cdbdbfb52646bee4906d3.tar.gz
1489 - repl: initial support for color
-rw-r--r--repl.mu28
1 files changed, 27 insertions, 1 deletions
diff --git a/repl.mu b/repl.mu
index bc686ecd..47c46109 100644
--- a/repl.mu
+++ b/repl.mu
@@ -43,7 +43,9 @@ recipe read-instruction [
   k:address:keyboard <- next-ingredient
   x:address:screen <- next-ingredient
   result:address:buffer <- init-buffer 10:literal  # string to maybe add to
+  color:number <- copy 7:literal/white
   {
+    +next-character
     # read character
     c:character, k:address:keyboard <- wait-for-key k:address:keyboard
 #?     $print c:character, [ 
@@ -59,8 +61,15 @@ recipe read-instruction [
       break-unless null?:boolean
       reply 0:literal, k:address:keyboard/same-as-ingredient:0, x:address:screen/same-as-ingredient:1
     }
+    # comment?
+    {
+      comment?:boolean <- equal c:character, 35:literal/hash
+      break-unless comment?:boolean
+      color:number <- copy 4:literal/blue
+      # fall through
+    }
     # print
-    print-character x:address:screen, c:character
+    print-character x:address:screen, c:character, color:number
     # append
     result:address:buffer <- buffer-append result:address:buffer, c:character
     # done with this instruction?
@@ -71,3 +80,20 @@ recipe read-instruction [
   result2:address:array:character <- buffer-to-array result:address:buffer
   reply result2:address:array:character, k:address:keyboard, x:address:screen
 ]
+
+scenario read-instruction-color-comment [
+  assume-screen 30:literal/width, 5:literal/height
+  assume-keyboard [# comment
+]
+  run [
+    read-instruction keyboard:address, screen:address
+  ]
+  screen-should-contain-in-color 4:literal/blue, [
+    .# comment                     .
+    .                              .
+  ]
+  screen-should-contain-in-color 7:literal/white, [
+    .                              .
+    .                              .
+  ]
+]