about summary refs log tree commit diff stats
path: root/html/084console.mu.html
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-11-13 10:08:57 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-11-13 10:08:57 -0800
commitc603cd6cef43100aa83a62e15f96fd54c9fb987e (patch)
treed8631b1964a0200d170a996314f6e023686ff8de /html/084console.mu.html
parent05d3592047a76db4cc8d77102508c21ca1b86e7b (diff)
downloadmu-c603cd6cef43100aa83a62e15f96fd54c9fb987e.tar.gz
2430 - make room for more transforms
Diffstat (limited to 'html/084console.mu.html')
-rw-r--r--html/084console.mu.html150
1 files changed, 150 insertions, 0 deletions
diff --git a/html/084console.mu.html b/html/084console.mu.html
new file mode 100644
index 00000000..c91544f9
--- /dev/null
+++ b/html/084console.mu.html
@@ -0,0 +1,150 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<title>Mu - 084console.mu</title>
+<meta name="Generator" content="Vim/7.4">
+<meta name="plugin-version" content="vim7.4_v1">
+<meta name="syntax" content="none">
+<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
+<meta name="colorscheme" content="minimal">
+<style type="text/css">
+<!--
+pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
+body { font-family: monospace; color: #eeeeee; background-color: #080808; }
+* { font-size: 1.05em; }
+.muControl { color: #c0a020; }
+.muRecipe { color: #ff8700; }
+.muData { color: #ffff00; }
+.Comment { color: #9090ff; }
+.Constant { color: #00a0a0; }
+.Special { color: #ff6060; }
+.Delimiter { color: #a04060; }
+-->
+</style>
+
+<script type='text/javascript'>
+<!--
+
+-->
+</script>
+</head>
+<body>
+<pre id='vimCodeElement'>
+<span class="Comment"># Wrappers around interaction primitives that take a potentially fake object</span>
+<span class="Comment"># and are thus easier to test.</span>
+
+<span class="muData">exclusive-container</span> event [
+  text:character
+  keycode:number  <span class="Comment"># keys on keyboard without a unicode representation</span>
+  touch:touch-event  <span class="Comment"># mouse, track ball, etc.</span>
+  resize:resize-event
+  <span class="Comment"># update the assume-console handler if you add more variants</span>
+]
+
+<span class="muData">container</span> touch-event [
+  type:number
+  row:number
+  column:number
+]
+
+<span class="muData">container</span> resize-event [
+  width:number
+  height:number
+]
+
+<span class="muData">container</span> console [
+  index:number
+  data:address:array:event
+]
+
+<span class="muRecipe">recipe</span> new-fake-console [
+  <span class="Constant">local-scope</span>
+  result:address:console<span class="Special"> &lt;- </span>new <span class="Constant">console:type</span>
+  buf:address:address:array:event<span class="Special"> &lt;- </span>get-address *result, <span class="Constant">data:offset</span>
+  *buf<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
+  idx:address:number<span class="Special"> &lt;- </span>get-address *result, <span class="Constant">index:offset</span>
+  *idx<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
+  <span class="muControl">reply</span> result
+]
+
+<span class="muRecipe">recipe</span> read-event [
+  <span class="Constant">local-scope</span>
+  x:address:console<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
+  <span class="Delimiter">{</span>
+    <span class="muControl">break-unless</span> x
+    idx:address:number<span class="Special"> &lt;- </span>get-address *x, <span class="Constant">index:offset</span>
+    buf:address:array:event<span class="Special"> &lt;- </span>get *x, <span class="Constant">data:offset</span>
+    <span class="Delimiter">{</span>
+      max:number<span class="Special"> &lt;- </span>length *buf
+      done?:boolean<span class="Special"> &lt;- </span>greater-or-equal *idx, max
+      <span class="muControl">break-unless</span> done?
+      dummy:address:event<span class="Special"> &lt;- </span>new <span class="Constant">event:type</span>
+      <span class="muControl">reply</span> *dummy, x/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">1/found</span>, <span class="Constant">1/quit</span>
+    <span class="Delimiter">}</span>
+    result:event<span class="Special"> &lt;- </span>index *buf, *idx
+    *idx<span class="Special"> &lt;- </span>add *idx, <span class="Constant">1</span>
+    <span class="muControl">reply</span> result, x/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">1/found</span>, <span class="Constant">0/quit</span>
+  <span class="Delimiter">}</span>
+  switch  <span class="Comment"># real event source is infrequent; avoid polling it too much</span>
+  result:event, found?:boolean<span class="Special"> &lt;- </span>check-for-interaction
+  <span class="muControl">reply</span> result, x/same-as-ingredient:<span class="Constant">0</span>, found?, <span class="Constant">0/quit</span>
+]
+
+<span class="Comment"># variant of read-event for just keyboard events. Discards everything that</span>
+<span class="Comment"># isn't unicode, so no arrow keys, page-up/page-down, etc. But you still get</span>
+<span class="Comment"># newlines, tabs, ctrl-d..</span>
+<span class="muRecipe">recipe</span> read-key [
+  <span class="Constant">local-scope</span>
+  console:address:console<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
+  x:event, console, found?:boolean, quit?:boolean<span class="Special"> &lt;- </span>read-event console
+  <span class="muControl">reply-if</span> quit?, <span class="Constant">0</span>, console/same-as-ingredient:<span class="Constant">0</span>, found?, quit?
+  <span class="muControl">reply-unless</span> found?, <span class="Constant">0</span>, console/same-as-ingredient:<span class="Constant">0</span>, found?, quit?
+  c:address:character<span class="Special"> &lt;- </span>maybe-convert x, <span class="Constant">text:variant</span>
+  <span class="muControl">reply-unless</span> c, <span class="Constant">0</span>, console/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">0/found</span>, <span class="Constant">0/quit</span>
+  <span class="muControl">reply</span> *c, console/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">1/found</span>, <span class="Constant">0/quit</span>
+]
+
+<span class="muRecipe">recipe</span> send-keys-to-channel [
+  <span class="Constant">local-scope</span>
+  console:address:console<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
+  chan:address:channel<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
+  screen:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
+  <span class="Delimiter">{</span>
+    c:character, console, found?:boolean, quit?:boolean<span class="Special"> &lt;- </span>read-key console
+    <span class="muControl">loop-unless</span> found?
+    <span class="muControl">break-if</span> quit?
+    assert c, <span class="Constant">[invalid event, expected text]</span>
+    screen<span class="Special"> &lt;- </span>print-character screen, c
+    chan<span class="Special"> &lt;- </span>write chan, c
+    <span class="muControl">loop</span>
+  <span class="Delimiter">}</span>
+  <span class="muControl">reply</span> console/same-as-ingredient:<span class="Constant">0</span>, chan/same-as-ingredient:<span class="Constant">1</span>, screen/same-as-ingredient:<span class="Constant">2</span>
+]
+
+<span class="muRecipe">recipe</span> wait-for-event [
+  <span class="Constant">local-scope</span>
+  console:address:console<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
+  <span class="Delimiter">{</span>
+    _, console, found?:boolean<span class="Special"> &lt;- </span>read-event console
+    <span class="muControl">loop-unless</span> found?
+  <span class="Delimiter">}</span>
+  <span class="muControl">reply</span> console/same-as-ingredient:<span class="Constant">0</span>
+]
+
+<span class="Comment"># use this helper to skip rendering if there's lots of other events queued up</span>
+<span class="muRecipe">recipe</span> has-more-events? [
+  <span class="Constant">local-scope</span>
+  console:address:console<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
+  <span class="Delimiter">{</span>
+    <span class="muControl">break-unless</span> console
+    <span class="Comment"># fake consoles should be plenty fast; never skip</span>
+    <span class="muControl">reply</span> <span class="Constant">0/false</span>
+  <span class="Delimiter">}</span>
+  result:boolean<span class="Special"> &lt;- </span>interactions-left?
+  <span class="muControl">reply</span> result
+]
+</pre>
+</body>
+</html>
+<!-- vim: set foldmethod=manual : -->