about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-07-08 21:03:32 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-07-08 21:03:32 -0700
commit5e9eff8ca137dcb929e9c986d6aaa42c762caf61 (patch)
tree92292231115f8e7702021b728e0fe07389959c00
parentc12cca678e2d9e25155426649626ab36a79fcacc (diff)
downloadmu-5e9eff8ca137dcb929e9c986d6aaa42c762caf61.tar.gz
1731 - ah, now fully responsive
The trick is to check for more events and not bother rendering if so.
-rw-r--r--070display.cc11
-rw-r--r--074console.mu13
-rw-r--r--edit.mu6
-rw-r--r--termbox/termbox.c5
-rw-r--r--termbox/termbox.h2
5 files changed, 36 insertions, 1 deletions
diff --git a/070display.cc b/070display.cc
index b6e4b9ca..335a3e55 100644
--- a/070display.cc
+++ b/070display.cc
@@ -336,3 +336,14 @@ case CHECK_FOR_INTERACTION: {
   products.at(1).push_back(/*found*/false);
   break;
 }
+
+:(before "End Primitive Recipe Declarations")
+INTERACTIONS_LEFT,
+:(before "End Primitive Recipe Numbers")
+Recipe_ordinal["interactions-left?"] = INTERACTIONS_LEFT;
+:(before "End Primitive Recipe Implementations")
+case INTERACTIONS_LEFT: {
+  products.resize(1);
+  products.at(0).push_back(tb_event_ready());
+  break;
+}
diff --git a/074console.mu b/074console.mu
index 1d9702da..8ec8e1e9 100644
--- a/074console.mu
+++ b/074console.mu
@@ -100,3 +100,16 @@ recipe wait-for-event [
     loop-unless found?:boolean
   }
 ]
+
+# use this helper to skip rendering if there's lots of other events queued up
+recipe has-more-events? [
+  default-space:address:array:location <- new location:type, 30:literal
+  console:address <- next-ingredient
+  {
+    break-unless console:address
+    # fake consoles should be plenty fast; never skip
+    reply 0:literal/false
+  }
+  result:boolean <- interactions-left?
+  reply result:boolean
+]
diff --git a/edit.mu b/edit.mu
index 7c6cadee..cb0e06f0 100644
--- a/edit.mu
+++ b/edit.mu
@@ -683,7 +683,11 @@ recipe handle-event [
     # that's it; render will adjust cursor-column as necessary
   }
   +render
-  render editor:address:editor-data
+  {
+    more-events?:boolean <- has-more-events? console:address
+    break-if more-events?:boolean
+    render editor:address:editor-data
+  }
 ]
 
 recipe move-cursor-in-editor [
diff --git a/termbox/termbox.c b/termbox/termbox.c
index ee10cd49..0092abd1 100644
--- a/termbox/termbox.c
+++ b/termbox/termbox.c
@@ -502,6 +502,11 @@ static int read_up_to(int n) {
   return 0;
 }
 
+int tb_event_ready(void)
+{
+  return input_buffer.len > 0;
+}
+
 static int wait_fill_event(struct tb_event *event, struct timeval *timeout)
 {
   // ;-)
diff --git a/termbox/termbox.h b/termbox/termbox.h
index 50a8b5e1..c257434c 100644
--- a/termbox/termbox.h
+++ b/termbox/termbox.h
@@ -196,6 +196,8 @@ int tb_peek_event(struct tb_event *event, int timeout);
  */
 int tb_poll_event(struct tb_event *event);
 
+int tb_event_ready(void);
+
 
 
 /*** 3. Utility utf8 functions. */