about summary refs log tree commit diff stats
path: root/074keyboard.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-06-21 23:23:57 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-21 23:27:54 -0700
commit45c08fea47de1a23ce98f4fc7a1c5c3bed92b5fb (patch)
tree78cbc5db454f79c6baf91afa49f090cf8cb14a58 /074keyboard.mu
parente552479afac60bdf3f5c089213cbc6422902ee5a (diff)
downloadmu-45c08fea47de1a23ce98f4fc7a1c5c3bed92b5fb.tar.gz
1616 - merging keyboard and events into 'console'
Only core layers currently passing. Console apps are probably still
broken.
Diffstat (limited to '074keyboard.mu')
-rw-r--r--074keyboard.mu90
1 files changed, 54 insertions, 36 deletions
diff --git a/074keyboard.mu b/074keyboard.mu
index 0d348e55..9538546e 100644
--- a/074keyboard.mu
+++ b/074keyboard.mu
@@ -1,72 +1,90 @@
-# Wrappers around keyboard primitives that take a 'keyboard' object and are thus
-# easier to test.
+# Wrappers around interaction primitives that take a potentially fake object
+# and are thus easier to test.
 
-# display:screen as keyboard:__? Can't think of another word.
-container keyboard [
+exclusive-container event [
+  text:character
+  keycode:number  # keys on keyboard without a unicode representation
+  pointer:single-touch-event  # mouse, track ball, etc.
+  # update the assume-console handler if you add more variants
+]
+
+container single-touch-event [
+  type:number
+  row:number
+  column:number
+]
+
+container console [
   index:number
-  data:address:array:character
+  data:address:array:event
 ]
 
-recipe new-fake-keyboard [
+recipe new-fake-console [
   default-space:address:array:location <- new location:type, 30:literal
-  result:address:keyboard <- new keyboard:type
-  buf:address:address:array:character <- get-address result:address:keyboard/deref, data:offset
+  result:address:console <- new console:type
+  buf:address:address:array:character <- get-address result:address:console/deref, data:offset
 #?   $start-tracing #? 1
   buf:address:address:array:character/deref <- next-ingredient
 #?   $stop-tracing #? 1
-  idx:address:number <- get-address result:address:keyboard/deref, index:offset
+  idx:address:number <- get-address result:address:console/deref, index:offset
   idx:address:number/deref <- copy 0:literal
-  reply result:address:keyboard
+  reply result:address:console
 ]
 
-recipe read-key [
+recipe read-event [
   default-space:address:array:location <- new location:type, 30:literal
-  x:address:keyboard <- next-ingredient
+  x:address:console <- next-ingredient
   {
-    break-unless x:address:keyboard
-    idx:address:number <- get-address x:address:keyboard/deref, index:offset
-    buf:address:array:character <- get x:address:keyboard/deref, data:offset
-    max:number <- length buf:address:array:character/deref
+    break-unless x:address:console
+    idx:address:number <- get-address x:address:console/deref, index:offset
+    buf:address:array:event <- get x:address:console/deref, data:offset
     {
+      max:number <- length buf:address:array:event/deref
       done?:boolean <- greater-or-equal idx:address:number/deref, max:number
       break-unless done?:boolean
-      reply 0:literal/eof, 1:literal/found, x:address:keyboard/same-as-ingredient:0
+      dummy:address:event <- new event:type
+      reply dummy:address:event/deref, x:address:console/same-as-ingredient:0, 1:literal/found, 1:literal/quit
     }
-    c:character <- index buf:address:array:character/deref, idx:address:number/deref
+    result:event <- index buf:address:array:event/deref, idx:address:number/deref
     idx:address:number/deref <- add idx:address:number/deref, 1:literal
-    reply c:character, 1:literal/found, x:address:keyboard/same-as-ingredient:0
+    reply result:event, x:address:console/same-as-ingredient:0, 1:literal/found, 0:literal/quit
   }
-  # real keyboard input is infrequent; avoid polling it too much
+  # real event source is infrequent; avoid polling it too much
   switch
-  c:character, found?:boolean <- read-key-from-keyboard
-  reply c:character, found?:boolean, x:address:keyboard/same-as-ingredient:0
+  result:event, found?:boolean <- check-for-interaction
+  reply result:event, x:address:console/same-as-ingredient:0, found?:boolean, 0:literal/quit
 ]
 
-recipe wait-for-key [
+recipe read-key [
   default-space:address:array:location <- new location:type, 30:literal
-  x:address:keyboard <- next-ingredient
-  {
-    break-unless x:address:keyboard
-    # on fake keyboards 'wait-for-key' behaves just like 'read-key'
-    c:character, found?:boolean, x:address:keyboard <- read-key x:address:keyboard
-    reply c:character, x:address:keyboard/same-as-ingredient:0
-  }
-  c:character <- wait-for-key-from-keyboard
-  reply c:character, x:address:keyboard/same-as-ingredient:0
+#?   $print default-space:address:array:location #? 1
+#?   $exit #? 1
+#?   $start-tracing #? 1
+  console:address <- next-ingredient
+  x:event, console:address, found?:boolean, quit?:boolean <- read-event console:address
+#?   $print [aaa 1] #? 1
+  reply-if quit?:boolean, 0:literal, console:address/same-as-ingredient:0, found?:boolean, quit?:boolean
+#?   $print [aaa 2] #? 1
+  reply-unless found?:boolean, 0:literal, console:address/same-as-ingredient:0, found?:boolean, quit?:boolean
+#?   $print [aaa 3] #? 1
+  c:address:character <- maybe-convert x:event, text:variant
+  reply-unless c:address:character, 0:literal, console:address/same-as-ingredient:0, 0:literal/found, 0:literal/quit
+#?   $print [aaa 4] #? 1
+  reply c:address:character/deref, console:address/same-as-ingredient:0, 1:literal/found, 0:literal/quit
 ]
 
 recipe send-keys-to-channel [
   default-space:address:array:location <- new location:type, 30:literal
-  keyboard:address <- next-ingredient
+  console:address <- next-ingredient
   chan:address:channel <- next-ingredient
   screen:address <- next-ingredient
   {
-    c:character, found?:boolean, keyboard:address <- read-key keyboard:address
+    c:character, console:address, found?:boolean, quit?:boolean <- read-key console:address
     loop-unless found?:boolean
-#?     print-integer screen:address, c:character #? 1
+    break-if quit?:boolean
+    assert c:character, [invalid event, expected text]
     print-character screen:address, c:character
     chan:address:channel <- write chan:address:channel, c:character
-    # todo: eof
     loop
   }
 ]