From 67160f82f285e4422927346c4ab0b5dd164b8544 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 25 Jun 2017 14:50:16 -0700 Subject: 3960 Don't refresh entire sandbox side when toggling the expected result for a single sandbox. --- edit/009-sandbox-test.mu | 52 ++++-- html/edit/009-sandbox-test.mu.html | 356 ++++++++++++++++++++----------------- sandbox/009-sandbox-test.mu | 50 ++++-- 3 files changed, 265 insertions(+), 193 deletions(-) diff --git a/edit/009-sandbox-test.mu b/edit/009-sandbox-test.mu index 5966617c..4893e1ea 100644 --- a/edit/009-sandbox-test.mu +++ b/edit/009-sandbox-test.mu @@ -3,7 +3,7 @@ scenario sandbox-click-on-result-toggles-color-to-green [ local-scope trace-until 100/app # trace too long - assume-screen 100/width, 10/height + assume-screen 100/width, 20/height # basic recipe assume-resources [ [lesson/recipes.mu] <- [ @@ -30,6 +30,7 @@ scenario sandbox-click-on-result-toggles-color-to-green [ . ┊ . ] # click on the '4' in the result + $clear-trace assume-console [ left-click 5, 51 ] @@ -47,6 +48,8 @@ scenario sandbox-click-on-result-toggles-color-to-green [ . . . . ] + # don't render entire sandbox side + check-trace-count-for-label-lesser-than 250, [print-character] # say 5 sandbox lines # cursor should remain unmoved run [ cursor:char <- copy 9251/␣ @@ -128,10 +131,19 @@ after [ # identify the sandbox whose output is being clicked on sandbox:&:sandbox, sandbox-index:num <- find-click-in-sandbox-output env, click-row break-unless sandbox - # toggle its expected-response, and save session + # update it sandbox <- toggle-expected-response sandbox + # minimal update to disk save-sandbox resources, sandbox, sandbox-index - screen <- render-sandbox-side screen, env, render + # minimal update to screen + sandbox-right-margin:num <- get *current-sandbox, right:offset + row:num <- render-sandbox-response screen, sandbox, sandbox-left-margin, sandbox-right-margin + { + height:num <- screen-height screen + at-bottom?:bool <- greater-or-equal row, height + break-if at-bottom? + draw-horizontal screen, row, sandbox-left-margin, sandbox-right-margin + } screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env loop +next-event } @@ -187,21 +199,33 @@ after [ { break-unless sandbox-response *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row - expected-response:text <- get *sandbox, expected-response:offset - break-unless expected-response # fall-through to print in grey - response-is-expected?:bool <- equal expected-response, sandbox-response - { - break-if response-is-expected? - row, screen <- render-text screen, sandbox-response, left, right, 1/red, row - } - { - break-unless response-is-expected?:bool - row, screen <- render-text screen, sandbox-response, left, right, 2/green, row - } + row <- render-sandbox-response screen, sandbox, left, right jump +render-sandbox-end } ] +def render-sandbox-response screen:&:screen, sandbox:&:sandbox, left:num, right:num -> row:num, screen:&:screen [ + local-scope + load-ingredients + sandbox-response:text <- get *sandbox, response:offset + expected-response:text <- get *sandbox, expected-response:offset + row:num <- get *sandbox response-starting-row-on-screen:offset + { + break-if expected-response + row <- render-text screen, sandbox-response, left, right, 245/grey, row + return + } + response-is-expected?:bool <- equal expected-response, sandbox-response + { + break-if response-is-expected? + row <- render-text screen, sandbox-response, left, right, 1/red, row + } + { + break-unless response-is-expected?:bool + row <- render-text screen, sandbox-response, left, right, 2/green, row + } +] + before [ *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 ] diff --git a/html/edit/009-sandbox-test.mu.html b/html/edit/009-sandbox-test.mu.html index df6f864e..5b817172 100644 --- a/html/edit/009-sandbox-test.mu.html +++ b/html/edit/009-sandbox-test.mu.html @@ -66,7 +66,7 @@ if ('onhashchange' in window) { 3 scenario sandbox-click-on-result-toggles-color-to-green [ 4 local-scope 5 trace-until 100/app # trace too long - 6 assume-screen 100/width, 10/height + 6 assume-screen 100/width, 20/height 7 # basic recipe 8 assume-resources [ 9 ¦ [lesson/recipes.mu] <- [ @@ -93,181 +93,205 @@ if ('onhashchange' in window) { 30 ¦ . ╎ . 31 ] 32 # click on the '4' in the result - 33 assume-console [ - 34 ¦ left-click 5, 51 - 35 ] - 36 run [ - 37 ¦ event-loop screen, console, env, resources - 38 ] - 39 # color toggles to green - 40 screen-should-contain-in-color 2/green, [ - 41 ¦ . . + 33 $clear-trace + 34 assume-console [ + 35 ¦ left-click 5, 51 + 36 ] + 37 run [ + 38 ¦ event-loop screen, console, env, resources + 39 ] + 40 # color toggles to green + 41 screen-should-contain-in-color 2/green, [ 42 ¦ . . 43 ¦ . . 44 ¦ . . 45 ¦ . . - 46 ¦ . 4 . - 47 ¦ . . + 46 ¦ . . + 47 ¦ . 4 . 48 ¦ . . - 49 ] - 50 # cursor should remain unmoved - 51 run [ - 52 ¦ cursor:char <- copy 9251/␣ - 53 ¦ print screen, cursor - 54 ] - 55 screen-should-contain [ - 56 ¦ . run (F4) . - 57 ¦ .␣ecipe foo [ ╎ . - 58 ¦ . reply 4 ╎─────────────────────────────────────────────────. - 59 ¦ .] ╎0 edit copy to recipe delete . - 60 ¦ . ╎foo . - 61 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎4 . - 62 ¦ . ╎─────────────────────────────────────────────────. - 63 ¦ . ╎ . - 64 ] - 65 # now change the result - 66 # then rerun - 67 assume-console [ - 68 ¦ left-click 2, 11 # cursor to end of line - 69 ¦ press backspace - 70 ¦ type [3] - 71 ¦ press F4 - 72 ] - 73 run [ - 74 ¦ event-loop screen, console, env, resources + 49 ¦ . . + 50 ] + 51 # don't render entire sandbox side + 52 check-trace-count-for-label-lesser-than 250, [print-character] # say 5 sandbox lines + 53 # cursor should remain unmoved + 54 run [ + 55 ¦ cursor:char <- copy 9251/␣ + 56 ¦ print screen, cursor + 57 ] + 58 screen-should-contain [ + 59 ¦ . run (F4) . + 60 ¦ .␣ecipe foo [ ╎ . + 61 ¦ . reply 4 ╎─────────────────────────────────────────────────. + 62 ¦ .] ╎0 edit copy to recipe delete . + 63 ¦ . ╎foo . + 64 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎4 . + 65 ¦ . ╎─────────────────────────────────────────────────. + 66 ¦ . ╎ . + 67 ] + 68 # now change the result + 69 # then rerun + 70 assume-console [ + 71 ¦ left-click 2, 11 # cursor to end of line + 72 ¦ press backspace + 73 ¦ type [3] + 74 ¦ press F4 75 ] - 76 # result turns red - 77 screen-should-contain-in-color 1/red, [ - 78 ¦ . . - 79 ¦ . . - 80 ¦ . . + 76 run [ + 77 ¦ event-loop screen, console, env, resources + 78 ] + 79 # result turns red + 80 screen-should-contain-in-color 1/red, [ 81 ¦ . . 82 ¦ . . - 83 ¦ . 3 . + 83 ¦ . . 84 ¦ . . 85 ¦ . . - 86 ] - 87 ] - 88 - 89 # this requires tracking a couple more things - 90 container sandbox [ - 91 response-starting-row-on-screen:num - 92 expected-response:text - 93 ] - 94 - 95 # include expected response when saving or restoring a sandbox - 96 before <end-save-sandbox> [ - 97 { - 98 ¦ expected-response:text <- get *sandbox, expected-response:offset - 99 ¦ break-unless expected-response -100 ¦ filename <- append filename, [.out] -101 ¦ resources <- dump resources, filename, expected-response -102 } -103 ] -104 -105 before <end-restore-sandbox> [ -106 { -107 ¦ filename <- append filename, [.out] -108 ¦ contents <- slurp resources, filename -109 ¦ break-unless contents -110 ¦ *curr <- put *curr, expected-response:offset, contents -111 } -112 ] -113 -114 # clicks on sandbox responses save it as 'expected' -115 after <global-touch> [ -116 # check if it's inside the output of any sandbox -117 { -118 ¦ sandbox-left-margin:num <- get *current-sandbox, left:offset -119 ¦ click-column:num <- get t, column:offset -120 ¦ on-sandbox-side?:bool <- greater-or-equal click-column, sandbox-left-margin -121 ¦ break-unless on-sandbox-side? -122 ¦ first-sandbox:&:sandbox <- get *env, sandbox:offset -123 ¦ break-unless first-sandbox -124 ¦ first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset -125 ¦ click-row:num <- get t, row:offset -126 ¦ below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins -127 ¦ break-unless below-sandbox-editor? -128 ¦ # identify the sandbox whose output is being clicked on -129 ¦ sandbox:&:sandbox, sandbox-index:num <- find-click-in-sandbox-output env, click-row -130 ¦ break-unless sandbox -131 ¦ # toggle its expected-response, and save session -132 ¦ sandbox <- toggle-expected-response sandbox -133 ¦ save-sandbox resources, sandbox, sandbox-index -134 ¦ screen <- render-sandbox-side screen, env, render -135 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env -136 ¦ loop +next-event -137 } -138 ] -139 -140 def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:sandbox, sandbox-index:num [ -141 local-scope -142 load-ingredients -143 # assert click-row >= sandbox.starting-row-on-screen -144 sandbox:&:sandbox <- get *env, sandbox:offset -145 start:num <- get *sandbox, starting-row-on-screen:offset -146 clicked-on-sandboxes?:bool <- greater-or-equal click-row, start -147 assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] -148 # while click-row < sandbox.next-sandbox.starting-row-on-screen -149 sandbox-index <- copy 0 -150 { -151 ¦ next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset -152 ¦ break-unless next-sandbox -153 ¦ next-start:num <- get *next-sandbox, starting-row-on-screen:offset -154 ¦ found?:bool <- lesser-than click-row, next-start -155 ¦ break-if found? -156 ¦ sandbox <- copy next-sandbox -157 ¦ sandbox-index <- add sandbox-index, 1 -158 ¦ loop -159 } -160 # return sandbox if click is in its output region -161 response-starting-row:num <- get *sandbox, response-starting-row-on-screen:offset -162 return-unless response-starting-row, 0/no-click-in-sandbox-output, 0/sandbox-index -163 click-in-response?:bool <- greater-or-equal click-row, response-starting-row -164 return-unless click-in-response?, 0/no-click-in-sandbox-output, 0/sandbox-index -165 return sandbox, sandbox-index -166 ] -167 -168 def toggle-expected-response sandbox:&:sandbox -> sandbox:&:sandbox [ -169 local-scope -170 load-ingredients -171 expected-response:text <- get *sandbox, expected-response:offset -172 { -173 ¦ # if expected-response is set, reset -174 ¦ break-unless expected-response -175 ¦ *sandbox <- put *sandbox, expected-response:offset, 0 -176 } -177 { -178 ¦ # if not, set expected response to the current response -179 ¦ break-if expected-response -180 ¦ response:text <- get *sandbox, response:offset -181 ¦ *sandbox <- put *sandbox, expected-response:offset, response -182 } -183 ] -184 -185 # when rendering a sandbox, color it in red/green if expected response exists -186 after <render-sandbox-response> [ -187 { -188 ¦ break-unless sandbox-response -189 ¦ *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row -190 ¦ expected-response:text <- get *sandbox, expected-response:offset -191 ¦ break-unless expected-response # fall-through to print in grey -192 ¦ response-is-expected?:bool <- equal expected-response, sandbox-response -193 ¦ { -194 ¦ ¦ break-if response-is-expected? -195 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 1/red, row -196 ¦ } -197 ¦ { -198 ¦ ¦ break-unless response-is-expected?:bool -199 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 2/green, row -200 ¦ } -201 ¦ jump +render-sandbox-end -202 } -203 ] -204 -205 before <end-render-sandbox-reset-hidden> [ -206 *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 -207 ] + 86 ¦ . 3 . + 87 ¦ . . + 88 ¦ . . + 89 ] + 90 ] + 91 + 92 # this requires tracking a couple more things + 93 container sandbox [ + 94 response-starting-row-on-screen:num + 95 expected-response:text + 96 ] + 97 + 98 # include expected response when saving or restoring a sandbox + 99 before <end-save-sandbox> [ +100 { +101 ¦ expected-response:text <- get *sandbox, expected-response:offset +102 ¦ break-unless expected-response +103 ¦ filename <- append filename, [.out] +104 ¦ resources <- dump resources, filename, expected-response +105 } +106 ] +107 +108 before <end-restore-sandbox> [ +109 { +110 ¦ filename <- append filename, [.out] +111 ¦ contents <- slurp resources, filename +112 ¦ break-unless contents +113 ¦ *curr <- put *curr, expected-response:offset, contents +114 } +115 ] +116 +117 # clicks on sandbox responses save it as 'expected' +118 after <global-touch> [ +119 # check if it's inside the output of any sandbox +120 { +121 ¦ sandbox-left-margin:num <- get *current-sandbox, left:offset +122 ¦ click-column:num <- get t, column:offset +123 ¦ on-sandbox-side?:bool <- greater-or-equal click-column, sandbox-left-margin +124 ¦ break-unless on-sandbox-side? +125 ¦ first-sandbox:&:sandbox <- get *env, sandbox:offset +126 ¦ break-unless first-sandbox +127 ¦ first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset +128 ¦ click-row:num <- get t, row:offset +129 ¦ below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins +130 ¦ break-unless below-sandbox-editor? +131 ¦ # identify the sandbox whose output is being clicked on +132 ¦ sandbox:&:sandbox, sandbox-index:num <- find-click-in-sandbox-output env, click-row +133 ¦ break-unless sandbox +134 ¦ # update it +135 ¦ sandbox <- toggle-expected-response sandbox +136 ¦ # minimal update to disk +137 ¦ save-sandbox resources, sandbox, sandbox-index +138 ¦ # minimal update to screen +139 ¦ sandbox-right-margin:num <- get *current-sandbox, right:offset +140 ¦ row:num <- render-sandbox-response screen, sandbox, sandbox-left-margin, sandbox-right-margin +141 ¦ { +142 ¦ ¦ height:num <- screen-height screen +143 ¦ ¦ at-bottom?:bool <- greater-or-equal row, height +144 ¦ ¦ break-if at-bottom? +145 ¦ ¦ draw-horizontal screen, row, sandbox-left-margin, sandbox-right-margin +146 ¦ } +147 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +148 ¦ loop +next-event +149 } +150 ] +151 +152 def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:sandbox, sandbox-index:num [ +153 local-scope +154 load-ingredients +155 # assert click-row >= sandbox.starting-row-on-screen +156 sandbox:&:sandbox <- get *env, sandbox:offset +157 start:num <- get *sandbox, starting-row-on-screen:offset +158 clicked-on-sandboxes?:bool <- greater-or-equal click-row, start +159 assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] +160 # while click-row < sandbox.next-sandbox.starting-row-on-screen +161 sandbox-index <- copy 0 +162 { +163 ¦ next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset +164 ¦ break-unless next-sandbox +165 ¦ next-start:num <- get *next-sandbox, starting-row-on-screen:offset +166 ¦ found?:bool <- lesser-than click-row, next-start +167 ¦ break-if found? +168 ¦ sandbox <- copy next-sandbox +169 ¦ sandbox-index <- add sandbox-index, 1 +170 ¦ loop +171 } +172 # return sandbox if click is in its output region +173 response-starting-row:num <- get *sandbox, response-starting-row-on-screen:offset +174 return-unless response-starting-row, 0/no-click-in-sandbox-output, 0/sandbox-index +175 click-in-response?:bool <- greater-or-equal click-row, response-starting-row +176 return-unless click-in-response?, 0/no-click-in-sandbox-output, 0/sandbox-index +177 return sandbox, sandbox-index +178 ] +179 +180 def toggle-expected-response sandbox:&:sandbox -> sandbox:&:sandbox [ +181 local-scope +182 load-ingredients +183 expected-response:text <- get *sandbox, expected-response:offset +184 { +185 ¦ # if expected-response is set, reset +186 ¦ break-unless expected-response +187 ¦ *sandbox <- put *sandbox, expected-response:offset, 0 +188 } +189 { +190 ¦ # if not, set expected response to the current response +191 ¦ break-if expected-response +192 ¦ response:text <- get *sandbox, response:offset +193 ¦ *sandbox <- put *sandbox, expected-response:offset, response +194 } +195 ] +196 +197 # when rendering a sandbox, color it in red/green if expected response exists +198 after <render-sandbox-response> [ +199 { +200 ¦ break-unless sandbox-response +201 ¦ *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row +202 ¦ row <- render-sandbox-response screen, sandbox, left, right +203 ¦ jump +render-sandbox-end +204 } +205 ] +206 +207 def render-sandbox-response screen:&:screen, sandbox:&:sandbox, left:num, right:num -> row:num, screen:&:screen [ +208 local-scope +209 load-ingredients +210 sandbox-response:text <- get *sandbox, response:offset +211 expected-response:text <- get *sandbox, expected-response:offset +212 row:num <- get *sandbox response-starting-row-on-screen:offset +213 { +214 ¦ break-if expected-response +215 ¦ row <- render-text screen, sandbox-response, left, right, 245/grey, row +216 ¦ return +217 } +218 response-is-expected?:bool <- equal expected-response, sandbox-response +219 { +220 ¦ break-if response-is-expected? +221 ¦ row <- render-text screen, sandbox-response, left, right, 1/red, row +222 } +223 { +224 ¦ break-unless response-is-expected?:bool +225 ¦ row <- render-text screen, sandbox-response, left, right, 2/green, row +226 } +227 ] +228 +229 before <end-render-sandbox-reset-hidden> [ +230 *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 +231 ] diff --git a/sandbox/009-sandbox-test.mu b/sandbox/009-sandbox-test.mu index 65381a2b..2bd3aac9 100644 --- a/sandbox/009-sandbox-test.mu +++ b/sandbox/009-sandbox-test.mu @@ -30,6 +30,7 @@ scenario sandbox-click-on-result-toggles-color-to-green [ . . ] # click on the '4' in the result + $clear-trace assume-console [ left-click 5, 21 ] @@ -46,6 +47,8 @@ scenario sandbox-click-on-result-toggles-color-to-green [ .4 . . . ] + # don't render entire sandbox side + check-trace-count-for-label-lesser-than 250, [print-character] # say 5 sandbox lines # cursor should remain unmoved run [ cursor:char <- copy 9251/␣ @@ -130,10 +133,19 @@ after [ # identify the sandbox whose output is being clicked on sandbox:&:sandbox, sandbox-index:num <- find-click-in-sandbox-output env, click-row break-unless sandbox - # toggle its expected-response, and save session + # update it sandbox <- toggle-expected-response sandbox + # minimal update to disk save-sandbox resources, sandbox, sandbox-index - screen <- render-sandbox-side screen, env, render + # minimal update to screen + sandbox-right-margin:num <- get *current-sandbox, right:offset + row:num <- render-sandbox-response screen, sandbox, sandbox-left-margin, sandbox-right-margin + { + height:num <- screen-height screen + at-bottom?:bool <- greater-or-equal row, height + break-if at-bottom? + draw-horizontal screen, row, sandbox-left-margin, sandbox-right-margin + } screen <- update-cursor screen, current-sandbox, env loop +next-event } @@ -189,21 +201,33 @@ after [ { break-unless sandbox-response *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row - expected-response:text <- get *sandbox, expected-response:offset - break-unless expected-response # fall-through to print in grey - response-is-expected?:bool <- equal expected-response, sandbox-response - { - break-if response-is-expected? - row, screen <- render-text screen, sandbox-response, left, right, 1/red, row - } - { - break-unless response-is-expected?:bool - row, screen <- render-text screen, sandbox-response, left, right, 2/green, row - } + row <- render-sandbox-response screen, sandbox, left, right jump +render-sandbox-end } ] +def render-sandbox-response screen:&:screen, sandbox:&:sandbox, left:num, right:num -> row:num, screen:&:screen [ + local-scope + load-ingredients + sandbox-response:text <- get *sandbox, response:offset + expected-response:text <- get *sandbox, expected-response:offset + row:num <- get *sandbox response-starting-row-on-screen:offset + { + break-if expected-response + row <- render-text screen, sandbox-response, left, right, 245/grey, row + return + } + response-is-expected?:bool <- equal expected-response, sandbox-response + { + break-if response-is-expected? + row <- render-text screen, sandbox-response, left, right, 1/red, row + } + { + break-unless response-is-expected?:bool + row <- render-text screen, sandbox-response, left, right, 2/green, row + } +] + before [ *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 ] -- cgit 1.4.1-2-gfad0