about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-06-23 14:09:11 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-06-23 15:39:14 -0700
commitb1e558cfe42029df630e1c2d9399d4b52c187801 (patch)
tree35fba14030c48c8e3a5e1792ffef9a84095cfe85
parent0bf322d6f04c28d4b38eb07f5ee9bd588187a058 (diff)
downloadmu-b1e558cfe42029df630e1c2d9399d4b52c187801.tar.gz
3941
Even though the bug of commit 3938 is now fixed, I'm still trying to
track down why the failure looked different on the fake screen than on
the real one. Snapshot as I try to track down the difference.

One key lesson is that the approach of commit 3860 -- updating the
cursor before rather than after printing each character -- turns out to
be untenable. A sequence of `print` followed by `cursor-position` needs
to behave the same as the real screen.

But it's still not clear how the real screen. When you get to the end of
a line the cursor position wraps after print to the left margin (column
0) on the next row. When you get to the bottom right the cursor position
wraps to the *bottom left* margin. How the heck does it know to scroll
on the next print, then? Is there some hidden state in the terminal?
-rw-r--r--081print.mu21
-rw-r--r--edit/001-editor.mu2
-rw-r--r--edit/002-typing.mu9
-rw-r--r--edit/004-programming-environment.mu2
-rw-r--r--edit/005-sandbox.mu29
5 files changed, 49 insertions, 14 deletions
diff --git a/081print.mu b/081print.mu
index 47ec607d..ff6cf5c0 100644
--- a/081print.mu
+++ b/081print.mu
@@ -33,6 +33,7 @@ def new-fake-screen w:num, h:num -> result:&:screen [
 def clear-screen screen:&:screen -> screen:&:screen [
   local-scope
   load-ingredients
+  stash [clear-screen]
   {
     break-if screen
     # real screen
@@ -60,6 +61,7 @@ def clear-screen screen:&:screen -> screen:&:screen [
 def fake-screen-is-empty? screen:&:screen -> result:bool [
   local-scope
   load-ingredients
+  stash [fake-screen-is-empty?]
   return-unless screen, 1/true  # do nothing for real screens
   buf:&:@:screen-cell <- get *screen, data:offset
   i:num <- copy 0
@@ -97,6 +99,8 @@ def print screen:&:screen, c:char -> screen:&:screen [
   {
     # real screen
     break-if screen
+#?     x:num y:num <- cursor-position-on-display
+#?     stash [print] x y
     print-character-to-display c, color, bg-color
     return
   }
@@ -158,6 +162,7 @@ def print screen:&:screen, c:char -> screen:&:screen [
     *screen <- put *screen, cursor-row:offset, row
   }
   # }
+#?   stash [print] row column
 #?     $print [print-character (], row, [, ], column, [): ], c, 10/newline
   # special-case: newline
   {
@@ -199,6 +204,7 @@ def print screen:&:screen, c:char -> screen:&:screen [
 def cursor-down-on-fake-screen screen:&:screen -> screen:&:screen [
   local-scope
   load-ingredients
+  stash [cursor-down]
   row:num <- get *screen, cursor-row:offset
   height:num <- get *screen, num-rows:offset
   bottom:num <- subtract height, 1
@@ -217,6 +223,7 @@ def cursor-down-on-fake-screen screen:&:screen -> screen:&:screen [
 def scroll-fake-screen screen:&:screen -> screen:&:screen [
   local-scope
   load-ingredients
+  stash [scroll-fake-screen]
   width:num <- get *screen, num-columns:offset
   height:num <- get *screen, num-rows:offset
   buf:&:@:screen-cell <- get *screen, data:offset
@@ -502,12 +509,13 @@ def assert-no-scroll screen:&:screen, old-top-idx:num [
   return-unless screen
   new-top-idx:num <- get *screen, top-idx:offset
   no-scroll?:bool <- equal old-top-idx, new-top-idx
-  assert no-scroll?, [render should never use screen's scrolling capabilities]
+#?   assert no-scroll?, [render should never use screen's scrolling capabilities]
 ]
 
 def clear-line screen:&:screen -> screen:&:screen [
   local-scope
   load-ingredients
+  stash [clear-line]
   space:char <- copy 0/nul
   {
     break-if screen
@@ -537,6 +545,7 @@ def clear-line-until screen:&:screen, right:num/inclusive -> screen:&:screen [
   local-scope
   load-ingredients
   row:num, column:num <- cursor-position screen
+  stash [clear-line-until] row column
   height:num <- screen-height screen
   past-bottom?:bool <- greater-or-equal row, height
   return-if past-bottom?
@@ -573,6 +582,7 @@ def cursor-position screen:&:screen -> row:num, column:num [
 def move-cursor screen:&:screen, new-row:num, new-column:num -> screen:&:screen [
   local-scope
   load-ingredients
+  stash [move-cursor]
   {
     break-if screen
     # real screen
@@ -618,6 +628,7 @@ scenario clear-line-erases-printed-characters [
 def cursor-down screen:&:screen -> screen:&:screen [
   local-scope
   load-ingredients
+  stash [cursor-down]
   {
     break-if screen
     # real screen
@@ -660,6 +671,7 @@ scenario cursor-down-scrolls [
 def cursor-up screen:&:screen -> screen:&:screen [
   local-scope
   load-ingredients
+  stash [cursor-up]
   {
     break-if screen
     # real screen
@@ -677,6 +689,7 @@ def cursor-up screen:&:screen -> screen:&:screen [
 def cursor-right screen:&:screen -> screen:&:screen [
   local-scope
   load-ingredients
+  stash [cursor-right]
   {
     break-if screen
     # real screen
@@ -696,6 +709,7 @@ def cursor-right screen:&:screen -> screen:&:screen [
 def cursor-left screen:&:screen -> screen:&:screen [
   local-scope
   load-ingredients
+  stash [cursor-left]
   {
     break-if screen
     # real screen
@@ -713,6 +727,7 @@ def cursor-left screen:&:screen -> screen:&:screen [
 def cursor-to-start-of-line screen:&:screen -> screen:&:screen [
   local-scope
   load-ingredients
+  stash [cursor-to-start-of-line]
   row:num <- cursor-position screen
   column:num <- copy 0
   screen <- move-cursor screen, row, column
@@ -721,6 +736,7 @@ def cursor-to-start-of-line screen:&:screen -> screen:&:screen [
 def cursor-to-next-line screen:&:screen -> screen:&:screen [
   local-scope
   load-ingredients
+  stash [cursor-to-next-line]
   screen <- cursor-down screen
   screen <- cursor-to-start-of-line screen
 ]
@@ -729,12 +745,14 @@ def move-cursor-to-column screen:&:screen, column:num -> screen:&:screen [
   local-scope
   load-ingredients
   row:num, _ <- cursor-position screen
+  stash [move-cursor-to-column] row
   move-cursor screen, row, column
 ]
 
 def screen-width screen:&:screen -> width:num [
   local-scope
   load-ingredients
+  stash [screen-width]
   {
     break-unless screen
     # fake screen
@@ -748,6 +766,7 @@ def screen-width screen:&:screen -> width:num [
 def screen-height screen:&:screen -> height:num [
   local-scope
   load-ingredients
+  stash [screen-height]
   {
     break-unless screen
     # fake screen
diff --git a/edit/001-editor.mu b/edit/001-editor.mu
index 807cf442..f7b7fb89 100644
--- a/edit/001-editor.mu
+++ b/edit/001-editor.mu
@@ -207,6 +207,7 @@ def render screen:&:screen, editor:&:editor -> last-row:num, last-column:num, sc
 def clear-screen-from screen:&:screen, row:num, column:num, left:num, right:num -> screen:&:screen [
   local-scope
   load-ingredients
+  stash [clear-screen-from] row column [between] left [and] right
   # if it's the real screen, use the optimized primitive
   {
     break-if screen
@@ -217,6 +218,7 @@ def clear-screen-from screen:&:screen, row:num, column:num, left:num, right:num
   screen <- move-cursor screen, row, column
   clear-line-until screen, right
   clear-rest-of-screen screen, row, left, right
+  screen <- move-cursor screen, row, column
 ]
 
 def clear-rest-of-screen screen:&:screen, row:num, left:num, right:num -> screen:&:screen [
diff --git a/edit/002-typing.mu b/edit/002-typing.mu
index 3b29c322..05ace7c5 100644
--- a/edit/002-typing.mu
+++ b/edit/002-typing.mu
@@ -1116,8 +1116,11 @@ after <handle-special-key> [
 def draw-horizontal screen:&:screen, row:num, x:num, right:num -> screen:&:screen [
   local-scope
   load-ingredients
+  a:num, b:num <- cursor-position screen
+  stash [draw-horizontal] row [--] a b
   height:num <- screen-height screen
   past-bottom?:bool <- greater-or-equal row, height
+  stash [  past-bottom?] past-bottom?
   return-if past-bottom?
   style:char, style-found?:bool <- next-ingredient
   {
@@ -1135,12 +1138,18 @@ def draw-horizontal screen:&:screen, row:num, x:num, right:num -> screen:&:scree
     break-if bg-color-found?
     bg-color <- copy 0/black
   }
+  stash [aa] x
   screen <- move-cursor screen, row, x
   {
     continue?:bool <- lesser-or-equal x, right  # right is inclusive, to match editor semantics
     break-unless continue?
+  a b <- cursor-position screen
+  stash [bb] x [--] a b
     print screen, style, color, bg-color
+  a b <- cursor-position screen
+  stash [cc] x [--] a b
     x <- add x, 1
     loop
   }
+  stash [draw-horizontal done]
 ]
diff --git a/edit/004-programming-environment.mu b/edit/004-programming-environment.mu
index 897f2923..bcd3b524 100644
--- a/edit/004-programming-environment.mu
+++ b/edit/004-programming-environment.mu
@@ -447,6 +447,7 @@ def render-recipes screen:&:screen, env:&:environment, render-editor:render-reci
   clear-screen-from screen, row, left, left, right
   #
   assert-no-scroll screen, old-top-idx
+  stash [render recipes done]
 ]
 
 # replaced in a later layer
@@ -467,6 +468,7 @@ def render-sandbox-side screen:&:screen, env:&:environment, render-editor:render
   clear-screen-from screen, row, left, left, right
   #
   assert-no-scroll screen, old-top-idx
+  stash [render sandbox side0 done]
 ]
 
 def update-cursor screen:&:screen, recipes:&:editor, current-sandbox:&:editor, sandbox-in-focus?:bool, env:&:environment -> screen:&:screen [
diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu
index 827f6632..2b17ecc2 100644
--- a/edit/005-sandbox.mu
+++ b/edit/005-sandbox.mu
@@ -14,6 +14,8 @@ def! main [
   env:&:environment <- new-programming-environment 0/filesystem, 0/screen
   env <- restore-sandboxes env, 0/filesystem
   render-all 0/screen, env, render
+  wait-for-some-interaction
+  $exit
   event-loop 0/screen, 0/console, env, 0/filesystem
 ]
 
@@ -268,20 +270,25 @@ def! render-sandbox-side screen:&:screen, env:&:environment, render-editor:rende
   clear-rest-of-screen screen, row, left, right
   #
   assert-no-scroll screen, old-top-idx
+  stash [render sandbox side done]
 ]
 
 def render-sandboxes screen:&:screen, sandbox:&:sandbox, left:num, right:num, row:num, render-from:num, idx:num -> row:num, screen:&:screen, sandbox:&:sandbox [
   local-scope
   load-ingredients
   return-unless sandbox
+  a:num b:num <- cursor-position screen
+  stash [render-sandboxes] idx [:] row [--] a b
   screen-height:num <- screen-height screen
+  at-bottom?:bool <- greater-or-equal row, screen-height
+  return-if at-bottom?
   hidden?:bool <- lesser-than idx, render-from
   {
     break-if hidden?
     # render sandbox menu
     row <- add row, 1
-    at-bottom?:bool <- greater-or-equal row, screen-height
-    return-if at-bottom?
+#?     at-bottom?:bool <- greater-or-equal row, screen-height
+#?     return-if at-bottom?
     screen <- move-cursor screen, row, left
     screen <- render-sandbox-menu screen, idx, left, right
     # save menu row so we can detect clicks to it later
@@ -345,30 +352,26 @@ def render-sandbox-menu screen:&:screen, sandbox-index:num, left:num, right:num
 
 scenario skip-rendering-sandbox-menu-past-bottom-row [
   trace-until 100/app  # trace too long
-  assume-screen 100/width, 7/height
+  assume-screen 100/width, 6/height
   # recipe editor is empty
   assume-resources [
+    [lesson/0] <- [|add 2, 2|]
+    [lesson/1] <- [|add 1, 1|]
   ]
   # create two sandboxes such that the top one just barely fills the screen
   env:&:environment <- new-programming-environment resources, screen, []
-  render-all screen, env, render
-  assume-console [
-    left-click 1, 75
-    type [add 1, 1]
-    press F4
-    type [add 2, 2]
-    press F4
-  ]
+  env <- restore-sandboxes env, resources
+  $clear-trace
   run [
-    event-loop screen, console, env, resources
+    render-all screen, env, render
   ]
+  $dump-trace [app]
   screen-should-contain [
     .                                                                                 run (F4)           .
     .                                                  ┊                                                 .
     .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊─────────────────────────────────────────────────.
     .                                                  ┊0   edit       copy       to recipe    delete    .
     .                                                  ┊add 2, 2                                         .
-    .                                                  ┊4                                                .
     .                                                  ┊─────────────────────────────────────────────────.
   ]
 ]