From e5c11a5137d538b7713dd8708ca767c208824c06 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 26 Dec 2016 01:17:01 -0800 Subject: 3709 - line numbers in html Each line number also gets an anchor name, but I'm not hyperlinking them for now because I don't want to encourage bookmarking these links just yet. They aren't permalinks because every revision may change what's at any given line number. --- html/084console.mu.html | 240 ++++++++++++++++++++++++++---------------------- 1 file changed, 132 insertions(+), 108 deletions(-) (limited to 'html/084console.mu.html') diff --git a/html/084console.mu.html b/html/084console.mu.html index 5cb819de..af1e1b66 100644 --- a/html/084console.mu.html +++ b/html/084console.mu.html @@ -6,7 +6,7 @@ - + @@ -26,116 +27,139 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color - +
-# Wrappers around interaction primitives that take a potentially fake object
-# and are thus easier to test.
-
-exclusive-container event [
-  text:char
-  keycode:num  # keys on keyboard without a unicode representation
-  touch:touch-event  # mouse, track ball, etc.
-  resize:resize-event
-  # update the assume-console handler if you add more variants
-]
-
-container touch-event [
-  type:num
-  row:num
-  column:num
-]
-
-container resize-event [
-  width:num
-  height:num
-]
-
-container console [
-  current-event-index:num
-  events:&:@:event
-]
-
-def new-fake-console events:&:@:event -> result:&:console [
-  local-scope
-  load-ingredients
-  result:&:console <- new console:type
-  *result <- put *result, events:offset, events
-]
-
-def read-event console:&:console -> result:event, found?:bool, quit?:bool, console:&:console [
-  local-scope
-  load-ingredients
-  {
-    break-unless console
-    current-event-index:num <- get *console, current-event-index:offset
-    buf:&:@:event <- get *console, events:offset
-    {
-      max:num <- length *buf
-      done?:bool <- greater-or-equal current-event-index, max
-      break-unless done?
-      dummy:&:event <- new event:type
-      return *dummy, 1/found, 1/quit
-    }
-    result <- index *buf, current-event-index
-    current-event-index <- add current-event-index, 1
-    *console <- put *console, current-event-index:offset, current-event-index
-    return result, 1/found, 0/quit
-  }
-  switch  # real event source is infrequent; avoid polling it too much
-  result:event, found?:bool <- check-for-interaction
-  return result, found?, 0/quit
-]
-
-# variant of read-event for just keyboard events. Discards everything that
-# isn't unicode, so no arrow keys, page-up/page-down, etc. But you still get
-# newlines, tabs, ctrl-d..
-def read-key console:&:console -> result:char, found?:bool, quit?:bool, console:&:console [
-  local-scope
-  load-ingredients
-  x:event, found?:bool, quit?:bool, console <- read-event console
-  return-if quit?, 0, found?, quit?
-  return-unless found?, 0, found?, quit?
-  c:char, converted?:bool <- maybe-convert x, text:variant
-  return-unless converted?, 0, 0/found, 0/quit
-  return c, 1/found, 0/quit
-]
-
-def send-keys-to-channel console:&:console, chan:&:sink:char, screen:&:screen -> console:&:console, chan:&:sink:char, screen:&:screen [
-  local-scope
-  load-ingredients
-  {
-    c:char, found?:bool, quit?:bool, console <- read-key console
-    loop-unless found?
-    break-if quit?
-    assert c, [invalid event, expected text]
-    screen <- print screen, c
-    chan <- write chan, c
-    loop
-  }
-  chan <- close chan
-]
-
-def wait-for-event console:&:console -> console:&:console [
-  local-scope
-  load-ingredients
-  {
-    _, found?:bool <- read-event console
-    break-if found?
-    switch
-    loop
-  }
-]
-
-# use this helper to skip rendering if there's lots of other events queued up
-def has-more-events? console:&:console -> result:bool [
-  local-scope
-  load-ingredients
-  return-if console, 0/false  # fake consoles should be plenty fast; never skip
-  result <- interactions-left?
-]
+  1 # Wrappers around interaction primitives that take a potentially fake object
+  2 # and are thus easier to test.
+  3 
+  4 exclusive-container event [
+  5   text:char
+  6   keycode:num  # keys on keyboard without a unicode representation
+  7   touch:touch-event  # mouse, track ball, etc.
+  8   resize:resize-event
+  9   # update the assume-console handler if you add more variants
+ 10 ]
+ 11 
+ 12 container touch-event [
+ 13   type:num
+ 14   row:num
+ 15   column:num
+ 16 ]
+ 17 
+ 18 container resize-event [
+ 19   width:num
+ 20   height:num
+ 21 ]
+ 22 
+ 23 container console [
+ 24   current-event-index:num
+ 25   events:&:@:event
+ 26 ]
+ 27 
+ 28 def new-fake-console events:&:@:event -> result:&:console [
+ 29   local-scope
+ 30   load-ingredients
+ 31   result:&:console <- new console:type
+ 32   *result <- put *result, events:offset, events
+ 33 ]
+ 34 
+ 35 def read-event console:&:console -> result:event, found?:bool, quit?:bool, console:&:console [
+ 36   local-scope
+ 37   load-ingredients
+ 38   {
+ 39     break-unless console
+ 40     current-event-index:num <- get *console, current-event-index:offset
+ 41     buf:&:@:event <- get *console, events:offset
+ 42     {
+ 43       max:num <- length *buf
+ 44       done?:bool <- greater-or-equal current-event-index, max
+ 45       break-unless done?
+ 46       dummy:&:event <- new event:type
+ 47       return *dummy, 1/found, 1/quit
+ 48     }
+ 49     result <- index *buf, current-event-index
+ 50     current-event-index <- add current-event-index, 1
+ 51     *console <- put *console, current-event-index:offset, current-event-index
+ 52     return result, 1/found, 0/quit
+ 53   }
+ 54   switch  # real event source is infrequent; avoid polling it too much
+ 55   result:event, found?:bool <- check-for-interaction
+ 56   return result, found?, 0/quit
+ 57 ]
+ 58 
+ 59 # variant of read-event for just keyboard events. Discards everything that
+ 60 # isn't unicode, so no arrow keys, page-up/page-down, etc. But you still get
+ 61 # newlines, tabs, ctrl-d..
+ 62 def read-key console:&:console -> result:char, found?:bool, quit?:bool, console:&:console [
+ 63   local-scope
+ 64   load-ingredients
+ 65   x:event, found?:bool, quit?:bool, console <- read-event console
+ 66   return-if quit?, 0, found?, quit?
+ 67   return-unless found?, 0, found?, quit?
+ 68   c:char, converted?:bool <- maybe-convert x, text:variant
+ 69   return-unless converted?, 0, 0/found, 0/quit
+ 70   return c, 1/found, 0/quit
+ 71 ]
+ 72 
+ 73 def send-keys-to-channel console:&:console, chan:&:sink:char, screen:&:screen -> console:&:console, chan:&:sink:char, screen:&:screen [
+ 74   local-scope
+ 75   load-ingredients
+ 76   {
+ 77     c:char, found?:bool, quit?:bool, console <- read-key console
+ 78     loop-unless found?
+ 79     break-if quit?
+ 80     assert c, [invalid event, expected text]
+ 81     screen <- print screen, c
+ 82     chan <- write chan, c
+ 83     loop
+ 84   }
+ 85   chan <- close chan
+ 86 ]
+ 87 
+ 88 def wait-for-event console:&:console -> console:&:console [
+ 89   local-scope
+ 90   load-ingredients
+ 91   {
+ 92     _, found?:bool <- read-event console
+ 93     break-if found?
+ 94     switch
+ 95     loop
+ 96   }
+ 97 ]
+ 98 
+ 99 # use this helper to skip rendering if there's lots of other events queued up
+100 def has-more-events? console:&:console -> result:bool [
+101   local-scope
+102   load-ingredients
+103   return-if console, 0/false  # fake consoles should be plenty fast; never skip
+104   result <- interactions-left?
+105 ]
 
-- cgit 1.4.1-2-gfad0