about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-09-04 10:31:19 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-09-04 10:31:19 -0700
commit7e23f02f89ceebddaf55fa2c31621a18fe63ff98 (patch)
tree5de7f6c9145761a63f35b2020dedff342ce9c7ce
parentb94f150a57f7f3143f64e85f9ebc42f44376c4b5 (diff)
downloadmu-7e23f02f89ceebddaf55fa2c31621a18fe63ff98.tar.gz
2140 - refresh screen after falling behind
This bit of code is complex enough now that I'm bothered I can't write
tests for has-more-events?
-rw-r--r--cannot_write_tests_for5
-rw-r--r--edit.mu68
2 files changed, 62 insertions, 11 deletions
diff --git a/cannot_write_tests_for b/cannot_write_tests_for
new file mode 100644
index 00000000..a77ef91b
--- /dev/null
+++ b/cannot_write_tests_for
@@ -0,0 +1,5 @@
+1. screen background color
+2. has-more-events?
+3. hide/show screen
+4. more touch event types
+5. sandbox isolation
diff --git a/edit.mu b/edit.mu
index 0c0429d6..9b56a203 100644
--- a/edit.mu
+++ b/edit.mu
@@ -4739,6 +4739,10 @@ recipe event-loop [
   recipes:address:editor-data <- get *env, recipes:offset
   current-sandbox:address:editor-data <- get *env, current-sandbox:offset
   sandbox-in-focus?:address:boolean <- get-address *env, sandbox-in-focus?:offset
+  # if we fall behind we'll stop updating the screen, but then we have to
+  # render the entire screen when we catch up.
+  # todo: test this
+  render-all-on-no-more-events?:boolean <- copy 0/false
   {
     # looping over each (keyboard or touch) event as it occurs
     +next-event
@@ -4782,9 +4786,16 @@ recipe event-loop [
       break-unless r
       # if more events, we're still resizing; wait until we stop
       more-events?:boolean <- has-more-events? console
-      break-if more-events?
-      env <- resize screen, env
-      screen <- render-all screen, env
+      {
+        break-unless more-events?
+        render-all-on-no-more-events? <- copy 1/true  # no rendering now, full rendering on some future event
+      }
+      {
+        break-if more-events?
+        env <- resize screen, env
+        screen <- render-all screen, env
+        render-all-on-no-more-events? <- copy 0/false  # full render done
+      }
       loop +next-event:label
     }
     # if it's not global and not a touch event, send to appropriate editor
@@ -4793,25 +4804,60 @@ recipe event-loop [
       {
         break-if *sandbox-in-focus?
         screen, recipes, render?:boolean <- handle-keyboard-event screen, recipes, e:event
+        # refresh screen only if no more events
+        # if there are more events to process, wait for them to clear up, then make sure you render-all afterward.
+        more-events?:boolean <- has-more-events? console
+        {
+          break-unless more-events?
+          render-all-on-no-more-events? <- copy 1/true  # no rendering now, full rendering on some future event
+          jump +finish-event:label
+        }
         {
-          break-unless render?
-          # optimization: refresh screen only if no more events
-          more-events?:boolean <- has-more-events? console
           break-if more-events?
-          screen <- render-recipes screen, env
+          {
+            break-unless render-all-on-no-more-events?
+            # no more events, and we have to force render
+            screen <- render-all screen, env
+            render-all-on-no-more-events? <- copy 0/false
+            jump +finish-event:label
+          }
+          # no more events, no force render
+          {
+            break-unless render?
+            screen <- render-recipes screen, env
+            jump +finish-event:label
+          }
         }
       }
       {
         break-unless *sandbox-in-focus?
         screen, current-sandbox, render?:boolean <- handle-keyboard-event screen, current-sandbox, e:event
+        # refresh screen only if no more events
+        # if there are more events to process, wait for them to clear up, then make sure you render-all afterward.
+        more-events?:boolean <- has-more-events? console
+        {
+          break-unless more-events?
+          render-all-on-no-more-events? <- copy 1/true  # no rendering now, full rendering on some future event
+          jump +finish-event:label
+        }
         {
-          break-unless render?:boolean
-          # optimization: refresh screen only if no more events
-          more-events?:boolean <- has-more-events? console
           break-if more-events?
-          screen <- render-sandbox-side screen, env
+          {
+            break-unless render-all-on-no-more-events?
+            # no more events, and we have to force render
+            screen <- render-all screen, env
+            render-all-on-no-more-events? <- copy 0/false
+            jump +finish-event:label
+          }
+          # no more events, no force render
+          {
+            break-unless render?
+            screen <- render-sandbox-side screen, env
+            jump +finish-event:label
+          }
         }
       }
+      +finish-event
       screen <- update-cursor screen, recipes, current-sandbox, *sandbox-in-focus?
       show-screen screen
     }