about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-06-21 23:37:49 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-21 23:42:39 -0700
commit6a0f71b9f89df0940a342cd2c91d246cecc18bdf (patch)
tree9e5a926941a0be71e477bf6fe31ac48bc816d295
parent45c08fea47de1a23ce98f4fc7a1c5c3bed92b5fb (diff)
downloadmu-6a0f71b9f89df0940a342cd2c91d246cecc18bdf.tar.gz
1617
-rw-r--r--061channel.mu6
-rw-r--r--074keyboard.mu9
-rw-r--r--console.mu14
-rw-r--r--display.mu14
-rw-r--r--keyboard.mu15
-rw-r--r--mouse.mu11
-rw-r--r--screen.mu14
7 files changed, 40 insertions, 43 deletions
diff --git a/061channel.mu b/061channel.mu
index 94c51df0..29f6d82b 100644
--- a/061channel.mu
+++ b/061channel.mu
@@ -320,9 +320,9 @@ recipe buffer-lines [
       line:address:buffer <- buffer-append line:address:buffer, c:character
       line-done?:boolean <- equal c:character, 10:literal/newline
       break-if line-done?:boolean
-      # stop buffering on eof (currently only generated by fake keyboard)
-      empty-fake-keyboard?:boolean <- equal c:character, 0:literal/eof
-      break-if empty-fake-keyboard?:boolean
+      # stop buffering on eof (currently only generated by fake console)
+      eof?:boolean <- equal c:character, 0:literal/eof
+      break-if eof?:boolean
       loop
     }
 #?     return-to-console #? 1
diff --git a/074keyboard.mu b/074keyboard.mu
index 9538546e..2d82a3d9 100644
--- a/074keyboard.mu
+++ b/074keyboard.mu
@@ -88,3 +88,12 @@ recipe send-keys-to-channel [
     loop
   }
 ]
+
+recipe wait-for-event [
+  default-space:address:array:location <- new location:type, 30:literal
+  console:address <- next-ingredient
+  {
+    _, console:address, found?:boolean <- read-event console:address
+    loop-unless found?:boolean
+  }
+]
diff --git a/console.mu b/console.mu
new file mode 100644
index 00000000..4e6c10a5
--- /dev/null
+++ b/console.mu
@@ -0,0 +1,14 @@
+# example program: reading events from keyboard or mouse
+#
+# Keeps printing 'a' until you press a key or click on the mouse.
+
+recipe main [
+  switch-to-display
+  {
+    _, found?:boolean <- check-for-interaction
+    break-if found?:boolean
+    print-character-to-display 97:literal, 7:literal/white
+    loop
+  }
+  return-to-console
+]
diff --git a/display.mu b/display.mu
index 43f29f1f..821f4bd5 100644
--- a/display.mu
+++ b/display.mu
@@ -4,21 +4,21 @@ recipe main [
   switch-to-display
   print-character-to-display 97:literal, 1:literal/red
   1:number/raw, 2:number/raw <- cursor-position-on-display
-  wait-for-key-from-keyboard
+  wait-for-some-interaction
   clear-display
   move-cursor-on-display 0:literal, 4:literal
   print-character-to-display 98:literal
-  wait-for-key-from-keyboard
+  wait-for-some-interaction
   move-cursor-on-display 0:literal, 0:literal
   clear-line-on-display
-  wait-for-key-from-keyboard
+  wait-for-some-interaction
   move-cursor-down-on-display
-  wait-for-key-from-keyboard
+  wait-for-some-interaction
   move-cursor-right-on-display
-  wait-for-key-from-keyboard
+  wait-for-some-interaction
   move-cursor-left-on-display
-  wait-for-key-from-keyboard
+  wait-for-some-interaction
   move-cursor-up-on-display
-  wait-for-key-from-keyboard
+  wait-for-some-interaction
   return-to-console
 ]
diff --git a/keyboard.mu b/keyboard.mu
deleted file mode 100644
index 530275ca..00000000
--- a/keyboard.mu
+++ /dev/null
@@ -1,15 +0,0 @@
-# example program: reading keys from keyboard
-#
-# Keeps printing 'a' until you press a key. Then prints the key you pressed
-# and exits.
-
-recipe main [
-  switch-to-display
-  {
-    c:character, found?:boolean <- read-key-from-keyboard
-    break-if found?:boolean
-    print-character-to-display 97:literal
-    loop
-  }
-  return-to-console
-]
diff --git a/mouse.mu b/mouse.mu
deleted file mode 100644
index 0621b306..00000000
--- a/mouse.mu
+++ /dev/null
@@ -1,11 +0,0 @@
-# example program: managing the display
-
-recipe main [
-  switch-to-display
-  {
-    _, found?:boolean <- read-keyboard-or-mouse-event
-    break-if found?:boolean
-    loop
-  }
-  return-to-console
-]
diff --git a/screen.mu b/screen.mu
index cacb8eaf..6565b46d 100644
--- a/screen.mu
+++ b/screen.mu
@@ -7,21 +7,21 @@ recipe main [
   switch-to-display
   print-character 0:literal/screen, 97:literal, 2:literal/red
   1:number/raw, 2:number/raw <- cursor-position 0:literal/screen
-  wait-for-key 0:literal/keyboard
+  wait-for-event 0:literal/console
   clear-screen 0:literal/screen
   move-cursor 0:literal/screen, 0:literal/row, 4:literal/column
   print-character 0:literal/screen, 98:literal
-  wait-for-key 0:literal/keyboard
+  wait-for-event 0:literal/console
   move-cursor 0:literal/screen, 0:literal/row, 0:literal/column
   clear-line 0:literal/screen
-  wait-for-key 0:literal/keyboard
+  wait-for-event 0:literal/console
   cursor-down 0:literal/screen
-  wait-for-key 0:literal/keyboard
+  wait-for-event 0:literal/console
   cursor-right 0:literal/screen
-  wait-for-key 0:literal/keyboard
+  wait-for-event 0:literal/console
   cursor-left 0:literal/screen
-  wait-for-key 0:literal/keyboard
+  wait-for-event 0:literal/console
   cursor-up 0:literal/screen
-  wait-for-key 0:literal/keyboard
+  wait-for-event 0:literal/console
   return-to-console
 ]