From b2a2dc9593bd8a06977830f228ee86bb80c6a36e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 16 Apr 2017 15:16:22 -0700 Subject: 3825 --- html/edit/009-sandbox-test.mu.html | 151 ++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 77 deletions(-) (limited to 'html/edit/009-sandbox-test.mu.html') diff --git a/html/edit/009-sandbox-test.mu.html b/html/edit/009-sandbox-test.mu.html index 2c10e04c..cd2c66ae 100644 --- a/html/edit/009-sandbox-test.mu.html +++ b/html/edit/009-sandbox-test.mu.html @@ -188,86 +188,83 @@ if ('onhashchange' in window) { 125 ¦ below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins 126 ¦ break-unless below-sandbox-editor? 127 ¦ # identify the sandbox whose output is being clicked on -128 ¦ sandbox:&:sandbox <- find-click-in-sandbox-output env, click-row +128 ¦ sandbox:&:sandbox <- find-click-in-sandbox-output env, click-row 129 ¦ break-unless sandbox 130 ¦ # toggle its expected-response, and save session -131 ¦ sandbox <- toggle-expected-response sandbox +131 ¦ sandbox <- toggle-expected-response sandbox 132 ¦ save-sandboxes env, resources -133 ¦ hide-screen screen -134 ¦ screen <- render-sandbox-side screen, env, render -135 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env -136 ¦ # no change in cursor -137 ¦ show-screen screen -138 ¦ loop +next-event -139 } -140 ] -141 -142 def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:sandbox [ -143 local-scope -144 load-ingredients -145 # assert click-row >= sandbox.starting-row-on-screen -146 sandbox:&:sandbox <- get *env, sandbox:offset -147 start:num <- get *sandbox, starting-row-on-screen:offset -148 clicked-on-sandboxes?:bool <- greater-or-equal click-row, start -149 assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] -150 # while click-row < sandbox.next-sandbox.starting-row-on-screen -151 { -152 ¦ next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset -153 ¦ break-unless next-sandbox -154 ¦ next-start:num <- get *next-sandbox, starting-row-on-screen:offset -155 ¦ found?:bool <- lesser-than click-row, next-start -156 ¦ break-if found? -157 ¦ sandbox <- copy next-sandbox -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 -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 -165 return sandbox -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?:bool -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 ] +133 ¦ screen <- render-sandbox-side screen, env, render +134 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +135 ¦ loop +next-event +136 } +137 ] +138 +139 def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:sandbox [ +140 local-scope +141 load-ingredients +142 # assert click-row >= sandbox.starting-row-on-screen +143 sandbox:&:sandbox <- get *env, sandbox:offset +144 start:num <- get *sandbox, starting-row-on-screen:offset +145 clicked-on-sandboxes?:bool <- greater-or-equal click-row, start +146 assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] +147 # while click-row < sandbox.next-sandbox.starting-row-on-screen +148 { +149 ¦ next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset +150 ¦ break-unless next-sandbox +151 ¦ next-start:num <- get *next-sandbox, starting-row-on-screen:offset +152 ¦ found?:bool <- lesser-than click-row, next-start +153 ¦ break-if found? +154 ¦ sandbox <- copy next-sandbox +155 ¦ loop +156 } +157 # return sandbox if click is in its output region +158 response-starting-row:num <- get *sandbox, response-starting-row-on-screen:offset +159 return-unless response-starting-row, 0/no-click-in-sandbox-output +160 click-in-response?:bool <- greater-or-equal click-row, response-starting-row +161 return-unless click-in-response?, 0/no-click-in-sandbox-output +162 return sandbox +163 ] +164 +165 def toggle-expected-response sandbox:&:sandbox -> sandbox:&:sandbox [ +166 local-scope +167 load-ingredients +168 expected-response:text <- get *sandbox, expected-response:offset +169 { +170 ¦ # if expected-response is set, reset +171 ¦ break-unless expected-response +172 ¦ *sandbox <- put *sandbox, expected-response:offset, 0 +173 } +174 { +175 ¦ # if not, set expected response to the current response +176 ¦ break-if expected-response +177 ¦ response:text <- get *sandbox, response:offset +178 ¦ *sandbox <- put *sandbox, expected-response:offset, response +179 } +180 ] +181 +182 # when rendering a sandbox, color it in red/green if expected response exists +183 after <render-sandbox-response> [ +184 { +185 ¦ break-unless sandbox-response +186 ¦ *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row +187 ¦ expected-response:text <- get *sandbox, expected-response:offset +188 ¦ break-unless expected-response # fall-through to print in grey +189 ¦ response-is-expected?:bool <- equal expected-response, sandbox-response +190 ¦ { +191 ¦ ¦ break-if response-is-expected?:bool +192 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 1/red, row +193 ¦ } +194 ¦ { +195 ¦ ¦ break-unless response-is-expected?:bool +196 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 2/green, row +197 ¦ } +198 ¦ jump +render-sandbox-end +199 } +200 ] +201 +202 before <end-render-sandbox-reset-hidden> [ +203 *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 +204 ] -- cgit 1.4.1-2-gfad0