From b7717659a14748502a469490f572915c5ebd9c98 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 12 Mar 2017 00:58:21 -0800 Subject: 3790 Don't try to snapshot in scenarios. --- edit/005-sandbox.mu | 5 +- html/edit/005-sandbox.mu.html | 2047 +++++++++++++++++----------------- html/edit/006-sandbox-copy.mu.html | 2 +- html/edit/007-sandbox-delete.mu.html | 2 +- html/edit/008-sandbox-edit.mu.html | 2 +- html/edit/009-sandbox-test.mu.html | 14 +- html/edit/010-sandbox-trace.mu.html | 4 +- html/edit/011-errors.mu.html | 12 +- sandbox/005-sandbox.mu | 5 +- 9 files changed, 1051 insertions(+), 1042 deletions(-) diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu index 47ca5aec..0bd76338 100644 --- a/edit/005-sandbox.mu +++ b/edit/005-sandbox.mu @@ -182,7 +182,10 @@ def run-sandboxes env:&:environment, resources:&:resources, screen:&:screen -> e } +return - $system [./snapshot_lesson] + { + break-if resources # ignore this in tests + $system [./snapshot_lesson] + } ] # load code from disk diff --git a/html/edit/005-sandbox.mu.html b/html/edit/005-sandbox.mu.html index 066a08a3..ace1471a 100644 --- a/html/edit/005-sandbox.mu.html +++ b/html/edit/005-sandbox.mu.html @@ -74,7 +74,7 @@ if ('onhashchange' in window) { 11 local-scope 12 open-console 13 env:&:environment <- new-programming-environment 0/filesystem, 0/screen - 14 env <- restore-sandboxes env + 14 env <- restore-sandboxes env 15 render-all 0/screen, env, render 16 event-loop 0/screen, 0/console, env, 0/filesystem 17 # never gets here @@ -190,13 +190,13 @@ if ('onhashchange' in window) { 127 { 128 ¦ do-run?:bool <- equal k, 65532/F4 129 ¦ break-unless do-run? - 130 ¦ screen <- update-status screen, [running... ], 245/grey + 130 ¦ screen <- update-status screen, [running... ], 245/grey 131 ¦ error?:bool <- run-sandboxes env, resources, screen 132 ¦ # F4 might update warnings and results on both sides 133 ¦ screen <- render-all screen, env, render 134 ¦ { 135 ¦ ¦ break-if error? - 136 ¦ ¦ screen <- update-status screen, [ ], 245/grey + 136 ¦ ¦ screen <- update-status screen, [ ], 245/grey 137 ¦ } 138 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env 139 ¦ loop +next-event @@ -212,7 +212,7 @@ if ('onhashchange' in window) { 149 <run-sandboxes-begin> 150 current-sandbox:&:editor <- get *env, current-sandbox:offset 151 { - 152 ¦ sandbox-contents:text <- editor-contents current-sandbox + 152 ¦ sandbox-contents:text <- editor-contents current-sandbox 153 ¦ break-unless sandbox-contents 154 ¦ # if contents exist, first save them 155 ¦ # run them and turn them into a new sandbox @@ -232,7 +232,7 @@ if ('onhashchange' in window) { 169 ¦ *current-sandbox <- put *current-sandbox, top-of-screen:offset, init 170 } 171 # save all sandboxes before running, just in case we die when running - 172 save-sandboxes env, resources + 172 save-sandboxes env, resources 173 # run all sandboxes 174 curr:&:sandbox <- get *env, sandbox:offset 175 idx:num <- copy 0 @@ -245,1037 +245,1040 @@ if ('onhashchange' in window) { 182 } 183 <run-sandboxes-end> 184 +return - 185 $system [./snapshot_lesson] - 186 ] - 187 - 188 # load code from disk - 189 # replaced in a later layer (whereupon errors-found? will actually be set) - 190 def update-recipes env:&:environment, resources:&:resources, screen:&:screen -> errors-found?:bool, env:&:environment, resources:&:resources, screen:&:screen [ - 191 local-scope - 192 load-ingredients - 193 recipes:&:editor <- get *env, recipes:offset - 194 in:text <- editor-contents recipes - 195 resources <- dump resources, [lesson/recipes.mu], in - 196 reload in - 197 errors-found? <- copy 0/false - 198 ] - 199 - 200 # replaced in a later layer - 201 def update-sandbox sandbox:&:sandbox, env:&:environment, idx:num -> sandbox:&:sandbox, env:&:environment [ - 202 local-scope - 203 load-ingredients - 204 data:text <- get *sandbox, data:offset - 205 response:text, _, fake-screen:&:screen <- run-sandboxed data - 206 *sandbox <- put *sandbox, response:offset, response - 207 *sandbox <- put *sandbox, screen:offset, fake-screen - 208 ] - 209 - 210 def update-status screen:&:screen, msg:text, color:num -> screen:&:screen [ - 211 local-scope - 212 load-ingredients - 213 screen <- move-cursor screen, 0, 2 - 214 screen <- print screen, msg, color, 238/grey/background - 215 ] - 216 - 217 def save-sandboxes env:&:environment, resources:&:resources -> resources:&:resources [ - 218 local-scope - 219 load-ingredients - 220 current-sandbox:&:editor <- get *env, current-sandbox:offset - 221 # first clear previous versions, in case we deleted some sandbox - 222 $system [rm lesson/[0-9]* >/dev/null 2>/dev/null] # some shells can't handle '>&' - 223 curr:&:sandbox <- get *env, sandbox:offset - 224 idx:num <- copy 0 - 225 { - 226 ¦ break-unless curr - 227 ¦ data:text <- get *curr, data:offset - 228 ¦ filename:text <- append [lesson/], idx - 229 ¦ resources <- dump resources, filename, data - 230 ¦ <end-save-sandbox> - 231 ¦ idx <- add idx, 1 - 232 ¦ curr <- get *curr, next-sandbox:offset - 233 ¦ loop - 234 } - 235 ] - 236 - 237 def! render-sandbox-side screen:&:screen, env:&:environment, {render-editor: (recipe (address screen) (address editor) -> number number (address screen) (address editor))} -> screen:&:screen, env:&:environment [ - 238 local-scope - 239 load-ingredients - 240 trace 11, [app], [render sandbox side] - 241 current-sandbox:&:editor <- get *env, current-sandbox:offset - 242 row:num, column:num <- copy 1, 0 - 243 left:num <- get *current-sandbox, left:offset - 244 right:num <- get *current-sandbox, right:offset - 245 # render sandbox editor - 246 render-from:num <- get *env, render-from:offset - 247 { - 248 ¦ render-current-sandbox?:bool <- equal render-from, -1 - 249 ¦ break-unless render-current-sandbox? - 250 ¦ row, column, screen, current-sandbox <- call render-editor, screen, current-sandbox - 251 ¦ clear-screen-from screen, row, column, left, right - 252 ¦ row <- add row, 1 - 253 } - 254 # render sandboxes - 255 draw-horizontal screen, row, left, right - 256 sandbox:&:sandbox <- get *env, sandbox:offset - 257 row, screen <- render-sandboxes screen, sandbox, left, right, row, render-from - 258 clear-rest-of-screen screen, row, left, right - 259 ] - 260 - 261 def render-sandboxes screen:&:screen, sandbox:&:sandbox, left:num, right:num, row:num, render-from:num, idx:num -> row:num, screen:&:screen, sandbox:&:sandbox [ - 262 local-scope - 263 load-ingredients - 264 return-unless sandbox - 265 screen-height:num <- screen-height screen - 266 at-bottom?:bool <- greater-or-equal row, screen-height - 267 return-if at-bottom?:bool - 268 hidden?:bool <- lesser-than idx, render-from - 269 { - 270 ¦ break-if hidden? - 271 ¦ # render sandbox menu - 272 ¦ row <- add row, 1 - 273 ¦ screen <- move-cursor screen, row, left - 274 ¦ screen <- render-sandbox-menu screen, idx, left, right - 275 ¦ # save menu row so we can detect clicks to it later - 276 ¦ *sandbox <- put *sandbox, starting-row-on-screen:offset, row - 277 ¦ # render sandbox contents - 278 ¦ row <- add row, 1 - 279 ¦ screen <- move-cursor screen, row, left - 280 ¦ sandbox-data:text <- get *sandbox, data:offset - 281 ¦ row, screen <- render-code screen, sandbox-data, left, right, row - 282 ¦ *sandbox <- put *sandbox, code-ending-row-on-screen:offset, row - 283 ¦ # render sandbox warnings, screen or response, in that order - 284 ¦ sandbox-response:text <- get *sandbox, response:offset - 285 ¦ <render-sandbox-results> - 286 ¦ { - 287 ¦ ¦ sandbox-screen:&:screen <- get *sandbox, screen:offset - 288 ¦ ¦ empty-screen?:bool <- fake-screen-is-empty? sandbox-screen - 289 ¦ ¦ break-if empty-screen? - 290 ¦ ¦ row, screen <- render-screen screen, sandbox-screen, left, right, row - 291 ¦ } - 292 ¦ { - 293 ¦ ¦ break-unless empty-screen? - 294 ¦ ¦ <render-sandbox-response> - 295 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 245/grey, row - 296 ¦ } - 297 ¦ +render-sandbox-end - 298 ¦ at-bottom?:bool <- greater-or-equal row, screen-height - 299 ¦ return-if at-bottom? - 300 ¦ # draw solid line after sandbox - 301 ¦ draw-horizontal screen, row, left, right - 302 } - 303 # if hidden, reset row attributes - 304 { - 305 ¦ break-unless hidden? - 306 ¦ *sandbox <- put *sandbox, starting-row-on-screen:offset, 0 - 307 ¦ *sandbox <- put *sandbox, code-ending-row-on-screen:offset, 0 - 308 ¦ <end-render-sandbox-reset-hidden> - 309 } - 310 # draw next sandbox - 311 next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset - 312 next-idx:num <- add idx, 1 - 313 row, screen <- render-sandboxes screen, next-sandbox, left, right, row, render-from, next-idx - 314 ] - 315 - 316 def render-sandbox-menu screen:&:screen, sandbox-index:num, left:num, right:num -> screen:&:screen [ - 317 local-scope - 318 load-ingredients - 319 move-cursor-to-column screen, left - 320 edit-button-left:num, edit-button-right:num, copy-button-left:num, copy-button-right:num, delete-button-left:num <- sandbox-menu-columns left, right - 321 print screen, sandbox-index, 232/dark-grey, 245/grey - 322 start-buttons:num <- subtract edit-button-left, 1 - 323 clear-line-until screen, start-buttons, 245/grey - 324 print screen, [edit], 232/black, 94/background-orange - 325 clear-line-until screen, edit-button-right, 94/background-orange - 326 _, col:num <- cursor-position screen - 327 at-start-of-copy-button?:bool <- equal col, copy-button-left - 328 assert at-start-of-copy-button?, [aaa] - 329 print screen, [copy], 232/black, 58/background-green - 330 clear-line-until screen, copy-button-right, 58/background-green - 331 _, col:num <- cursor-position screen - 332 at-start-of-delete-button?:bool <- equal col, delete-button-left - 333 assert at-start-of-delete-button?, [bbb] - 334 print screen, [delete], 232/black, 52/background-red - 335 clear-line-until screen, right, 52/background-red - 336 ] - 337 - 338 # divide up the menu bar for a sandbox into 3 segments, for edit/copy/delete buttons - 339 # delete-button-right == right - 340 # all left/right pairs are inclusive - 341 def sandbox-menu-columns left:num, right:num -> edit-button-left:num, edit-button-right:num, copy-button-left:num, copy-button-right:num, delete-button-left:num [ - 342 local-scope - 343 load-ingredients - 344 start-buttons:num <- add left, 4/space-for-sandbox-index - 345 buttons-space:num <- subtract right, start-buttons - 346 button-width:num <- divide-with-remainder buttons-space, 3 # integer division - 347 buttons-wide-enough?:bool <- greater-or-equal button-width, 8 - 348 assert buttons-wide-enough?, [sandbox must be at least 30 or so characters wide] - 349 edit-button-left:num <- copy start-buttons - 350 copy-button-left:num <- add start-buttons, button-width - 351 edit-button-right:num <- subtract copy-button-left, 1 - 352 delete-button-left:num <- subtract right, button-width - 353 copy-button-right:num <- subtract delete-button-left, 1 - 354 ] - 355 - 356 # print a text 's' to 'editor' in 'color' starting at 'row' - 357 # clear rest of last line, move cursor to next line - 358 def render-text screen:&:screen, s:text, left:num, right:num, color:num, row:num -> row:num, screen:&:screen [ - 359 local-scope - 360 load-ingredients - 361 return-unless s - 362 column:num <- copy left - 363 screen <- move-cursor screen, row, column - 364 screen-height:num <- screen-height screen - 365 i:num <- copy 0 - 366 len:num <- length *s - 367 { - 368 ¦ +next-character - 369 ¦ done?:bool <- greater-or-equal i, len - 370 ¦ break-if done? - 371 ¦ done? <- greater-or-equal row, screen-height - 372 ¦ break-if done? - 373 ¦ c:char <- index *s, i - 374 ¦ { - 375 ¦ ¦ # at right? wrap. - 376 ¦ ¦ at-right?:bool <- equal column, right - 377 ¦ ¦ break-unless at-right? - 378 ¦ ¦ # print wrap icon - 379 ¦ ¦ wrap-icon:char <- copy 8617/loop-back-to-left - 380 ¦ ¦ print screen, wrap-icon, 245/grey - 381 ¦ ¦ column <- copy left - 382 ¦ ¦ row <- add row, 1 - 383 ¦ ¦ screen <- move-cursor screen, row, column - 384 ¦ ¦ loop +next-character # retry i - 385 ¦ } - 386 ¦ i <- add i, 1 - 387 ¦ { - 388 ¦ ¦ # newline? move to left rather than 0 - 389 ¦ ¦ newline?:bool <- equal c, 10/newline - 390 ¦ ¦ break-unless newline? - 391 ¦ ¦ # clear rest of line in this window - 392 ¦ ¦ { - 393 ¦ ¦ ¦ done?:bool <- greater-than column, right - 394 ¦ ¦ ¦ break-if done? - 395 ¦ ¦ ¦ space:char <- copy 32/space - 396 ¦ ¦ ¦ print screen, space - 397 ¦ ¦ ¦ column <- add column, 1 - 398 ¦ ¦ ¦ loop - 399 ¦ ¦ } - 400 ¦ ¦ row <- add row, 1 - 401 ¦ ¦ column <- copy left - 402 ¦ ¦ screen <- move-cursor screen, row, column - 403 ¦ ¦ loop +next-character - 404 ¦ } - 405 ¦ print screen, c, color - 406 ¦ column <- add column, 1 - 407 ¦ loop - 408 } - 409 was-at-left?:bool <- equal column, left - 410 clear-line-until screen, right - 411 { - 412 ¦ break-if was-at-left? - 413 ¦ row <- add row, 1 - 414 } - 415 move-cursor screen, row, left - 416 ] - 417 - 418 # assumes programming environment has no sandboxes; restores them from previous session - 419 def restore-sandboxes env:&:environment, resources:&:resources -> env:&:environment [ - 420 local-scope - 421 load-ingredients - 422 # read all scenarios, pushing them to end of a list of scenarios - 423 idx:num <- copy 0 - 424 curr:&:sandbox <- copy 0 - 425 prev:&:sandbox <- copy 0 - 426 { - 427 ¦ filename:text <- append [lesson/], idx - 428 ¦ contents:text <- slurp resources, filename - 429 ¦ break-unless contents # stop at first error; assuming file didn't exist - 430 ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ # todo: handle empty sandbox - 431 ¦ # create new sandbox for file - 432 ¦ curr <- new sandbox:type - 433 ¦ *curr <- put *curr, data:offset, contents - 434 ¦ <end-restore-sandbox> - 435 ¦ { - 436 ¦ ¦ break-if idx - 437 ¦ ¦ *env <- put *env, sandbox:offset, curr - 438 ¦ } - 439 ¦ { - 440 ¦ ¦ break-unless idx - 441 ¦ ¦ *prev <- put *prev, next-sandbox:offset, curr - 442 ¦ } - 443 ¦ idx <- add idx, 1 - 444 ¦ prev <- copy curr - 445 ¦ loop - 446 } - 447 # update sandbox count - 448 *env <- put *env, number-of-sandboxes:offset, idx - 449 ] - 450 - 451 # print the fake sandbox screen to 'screen' with appropriate delimiters - 452 # leave cursor at start of next line - 453 def render-screen screen:&:screen, sandbox-screen:&:screen, left:num, right:num, row:num -> row:num, screen:&:screen [ - 454 local-scope - 455 load-ingredients - 456 return-unless sandbox-screen - 457 # print 'screen:' - 458 row <- render-text screen, [screen:], left, right, 245/grey, row - 459 screen <- move-cursor screen, row, left - 460 # start printing sandbox-screen - 461 column:num <- copy left - 462 s-width:num <- screen-width sandbox-screen - 463 s-height:num <- screen-height sandbox-screen - 464 buf:&:@:screen-cell <- get *sandbox-screen, data:offset - 465 stop-printing:num <- add left, s-width, 3 - 466 max-column:num <- min stop-printing, right - 467 i:num <- copy 0 - 468 len:num <- length *buf - 469 screen-height:num <- screen-height screen - 470 { - 471 ¦ done?:bool <- greater-or-equal i, len - 472 ¦ break-if done? - 473 ¦ done? <- greater-or-equal row, screen-height - 474 ¦ break-if done? - 475 ¦ column <- copy left - 476 ¦ screen <- move-cursor screen, row, column - 477 ¦ # initial leader for each row: two spaces and a '.' - 478 ¦ space:char <- copy 32/space - 479 ¦ print screen, space, 245/grey - 480 ¦ print screen, space, 245/grey - 481 ¦ full-stop:char <- copy 46/period - 482 ¦ print screen, full-stop, 245/grey - 483 ¦ column <- add left, 3 - 484 ¦ { - 485 ¦ ¦ # print row - 486 ¦ ¦ row-done?:bool <- greater-or-equal column, max-column - 487 ¦ ¦ break-if row-done? - 488 ¦ ¦ curr:screen-cell <- index *buf, i - 489 ¦ ¦ c:char <- get curr, contents:offset - 490 ¦ ¦ color:num <- get curr, color:offset - 491 ¦ ¦ { - 492 ¦ ¦ ¦ # damp whites down to grey - 493 ¦ ¦ ¦ white?:bool <- equal color, 7/white - 494 ¦ ¦ ¦ break-unless white? - 495 ¦ ¦ ¦ color <- copy 245/grey - 496 ¦ ¦ } - 497 ¦ ¦ print screen, c, color - 498 ¦ ¦ column <- add column, 1 - 499 ¦ ¦ i <- add i, 1 - 500 ¦ ¦ loop - 501 ¦ } - 502 ¦ # print final '.' - 503 ¦ print screen, full-stop, 245/grey - 504 ¦ column <- add column, 1 - 505 ¦ { - 506 ¦ ¦ # clear rest of current line - 507 ¦ ¦ line-done?:bool <- greater-than column, right - 508 ¦ ¦ break-if line-done? - 509 ¦ ¦ print screen, space - 510 ¦ ¦ column <- add column, 1 - 511 ¦ ¦ loop - 512 ¦ } - 513 ¦ row <- add row, 1 - 514 ¦ loop - 515 } - 516 ] - 517 - 518 scenario run-updates-results [ - 519 local-scope - 520 trace-until 100/app # trace too long - 521 assume-screen 100/width, 12/height - 522 # define a recipe (no indent for the 'add' line below so column numbers are more obvious) - 523 assume-resources [ - 524 ¦ [lesson/recipes.mu] <- [ - 525 ¦ ¦ || - 526 ¦ ¦ |recipe foo [| - 527 ¦ ¦ | local-scope| - 528 ¦ ¦ | z:num <- add 2, 2| - 529 ¦ ¦ | reply z| - 530 ¦ ¦ |]| - 531 ¦ ] - 532 ] - 533 # sandbox editor contains an instruction without storing outputs - 534 env:&:environment <- new-programming-environment resources, screen, [foo] # contents of sandbox editor - 535 # run the code in the editors - 536 assume-console [ - 537 ¦ press F4 - 538 ] - 539 event-loop screen, console, env, resources - 540 screen-should-contain [ - 541 ¦ . run (F4) . - 542 ¦ . ╎ . - 543 ¦ .recipe foo [ ╎─────────────────────────────────────────────────. - 544 ¦ . local-scope ╎0 edit copy delete . - 545 ¦ . z:num <- add 2, 2 ╎foo . - 546 ¦ . reply z ╎4 . - 547 ¦ .] ╎─────────────────────────────────────────────────. - 548 ¦ . ╎ . - 549 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . - 550 ¦ . ╎ . - 551 ] - 552 # make a change (incrementing one of the args to 'add'), then rerun - 553 assume-console [ - 554 ¦ left-click 4, 28 # one past the value of the second arg - 555 ¦ press backspace - 556 ¦ type [3] - 557 ¦ press F4 - 558 ] - 559 run [ - 560 ¦ event-loop screen, console, env, resources + 185 { + 186 ¦ break-if resources # ignore this in tests + 187 ¦ $system [./snapshot_lesson] + 188 } + 189 ] + 190 + 191 # load code from disk + 192 # replaced in a later layer (whereupon errors-found? will actually be set) + 193 def update-recipes env:&:environment, resources:&:resources, screen:&:screen -> errors-found?:bool, env:&:environment, resources:&:resources, screen:&:screen [ + 194 local-scope + 195 load-ingredients + 196 recipes:&:editor <- get *env, recipes:offset + 197 in:text <- editor-contents recipes + 198 resources <- dump resources, [lesson/recipes.mu], in + 199 reload in + 200 errors-found? <- copy 0/false + 201 ] + 202 + 203 # replaced in a later layer + 204 def update-sandbox sandbox:&:sandbox, env:&:environment, idx:num -> sandbox:&:sandbox, env:&:environment [ + 205 local-scope + 206 load-ingredients + 207 data:text <- get *sandbox, data:offset + 208 response:text, _, fake-screen:&:screen <- run-sandboxed data + 209 *sandbox <- put *sandbox, response:offset, response + 210 *sandbox <- put *sandbox, screen:offset, fake-screen + 211 ] + 212 + 213 def update-status screen:&:screen, msg:text, color:num -> screen:&:screen [ + 214 local-scope + 215 load-ingredients + 216 screen <- move-cursor screen, 0, 2 + 217 screen <- print screen, msg, color, 238/grey/background + 218 ] + 219 + 220 def save-sandboxes env:&:environment, resources:&:resources -> resources:&:resources [ + 221 local-scope + 222 load-ingredients + 223 current-sandbox:&:editor <- get *env, current-sandbox:offset + 224 # first clear previous versions, in case we deleted some sandbox + 225 $system [rm lesson/[0-9]* >/dev/null 2>/dev/null] # some shells can't handle '>&' + 226 curr:&:sandbox <- get *env, sandbox:offset + 227 idx:num <- copy 0 + 228 { + 229 ¦ break-unless curr + 230 ¦ data:text <- get *curr, data:offset + 231 ¦ filename:text <- append [lesson/], idx + 232 ¦ resources <- dump resources, filename, data + 233 ¦ <end-save-sandbox> + 234 ¦ idx <- add idx, 1 + 235 ¦ curr <- get *curr, next-sandbox:offset + 236 ¦ loop + 237 } + 238 ] + 239 + 240 def! render-sandbox-side screen:&:screen, env:&:environment, {render-editor: (recipe (address screen) (address editor) -> number number (address screen) (address editor))} -> screen:&:screen, env:&:environment [ + 241 local-scope + 242 load-ingredients + 243 trace 11, [app], [render sandbox side] + 244 current-sandbox:&:editor <- get *env, current-sandbox:offset + 245 row:num, column:num <- copy 1, 0 + 246 left:num <- get *current-sandbox, left:offset + 247 right:num <- get *current-sandbox, right:offset + 248 # render sandbox editor + 249 render-from:num <- get *env, render-from:offset + 250 { + 251 ¦ render-current-sandbox?:bool <- equal render-from, -1 + 252 ¦ break-unless render-current-sandbox? + 253 ¦ row, column, screen, current-sandbox <- call render-editor, screen, current-sandbox + 254 ¦ clear-screen-from screen, row, column, left, right + 255 ¦ row <- add row, 1 + 256 } + 257 # render sandboxes + 258 draw-horizontal screen, row, left, right + 259 sandbox:&:sandbox <- get *env, sandbox:offset + 260 row, screen <- render-sandboxes screen, sandbox, left, right, row, render-from + 261 clear-rest-of-screen screen, row, left, right + 262 ] + 263 + 264 def render-sandboxes screen:&:screen, sandbox:&:sandbox, left:num, right:num, row:num, render-from:num, idx:num -> row:num, screen:&:screen, sandbox:&:sandbox [ + 265 local-scope + 266 load-ingredients + 267 return-unless sandbox + 268 screen-height:num <- screen-height screen + 269 at-bottom?:bool <- greater-or-equal row, screen-height + 270 return-if at-bottom?:bool + 271 hidden?:bool <- lesser-than idx, render-from + 272 { + 273 ¦ break-if hidden? + 274 ¦ # render sandbox menu + 275 ¦ row <- add row, 1 + 276 ¦ screen <- move-cursor screen, row, left + 277 ¦ screen <- render-sandbox-menu screen, idx, left, right + 278 ¦ # save menu row so we can detect clicks to it later + 279 ¦ *sandbox <- put *sandbox, starting-row-on-screen:offset, row + 280 ¦ # render sandbox contents + 281 ¦ row <- add row, 1 + 282 ¦ screen <- move-cursor screen, row, left + 283 ¦ sandbox-data:text <- get *sandbox, data:offset + 284 ¦ row, screen <- render-code screen, sandbox-data, left, right, row + 285 ¦ *sandbox <- put *sandbox, code-ending-row-on-screen:offset, row + 286 ¦ # render sandbox warnings, screen or response, in that order + 287 ¦ sandbox-response:text <- get *sandbox, response:offset + 288 ¦ <render-sandbox-results> + 289 ¦ { + 290 ¦ ¦ sandbox-screen:&:screen <- get *sandbox, screen:offset + 291 ¦ ¦ empty-screen?:bool <- fake-screen-is-empty? sandbox-screen + 292 ¦ ¦ break-if empty-screen? + 293 ¦ ¦ row, screen <- render-screen screen, sandbox-screen, left, right, row + 294 ¦ } + 295 ¦ { + 296 ¦ ¦ break-unless empty-screen? + 297 ¦ ¦ <render-sandbox-response> + 298 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 245/grey, row + 299 ¦ } + 300 ¦ +render-sandbox-end + 301 ¦ at-bottom?:bool <- greater-or-equal row, screen-height + 302 ¦ return-if at-bottom? + 303 ¦ # draw solid line after sandbox + 304 ¦ draw-horizontal screen, row, left, right + 305 } + 306 # if hidden, reset row attributes + 307 { + 308 ¦ break-unless hidden? + 309 ¦ *sandbox <- put *sandbox, starting-row-on-screen:offset, 0 + 310 ¦ *sandbox <- put *sandbox, code-ending-row-on-screen:offset, 0 + 311 ¦ <end-render-sandbox-reset-hidden> + 312 } + 313 # draw next sandbox + 314 next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset + 315 next-idx:num <- add idx, 1 + 316 row, screen <- render-sandboxes screen, next-sandbox, left, right, row, render-from, next-idx + 317 ] + 318 + 319 def render-sandbox-menu screen:&:screen, sandbox-index:num, left:num, right:num -> screen:&:screen [ + 320 local-scope + 321 load-ingredients + 322 move-cursor-to-column screen, left + 323 edit-button-left:num, edit-button-right:num, copy-button-left:num, copy-button-right:num, delete-button-left:num <- sandbox-menu-columns left, right + 324 print screen, sandbox-index, 232/dark-grey, 245/grey + 325 start-buttons:num <- subtract edit-button-left, 1 + 326 clear-line-until screen, start-buttons, 245/grey + 327 print screen, [edit], 232/black, 94/background-orange + 328 clear-line-until screen, edit-button-right, 94/background-orange + 329 _, col:num <- cursor-position screen + 330 at-start-of-copy-button?:bool <- equal col, copy-button-left + 331 assert at-start-of-copy-button?, [aaa] + 332 print screen, [copy], 232/black, 58/background-green + 333 clear-line-until screen, copy-button-right, 58/background-green + 334 _, col:num <- cursor-position screen + 335 at-start-of-delete-button?:bool <- equal col, delete-button-left + 336 assert at-start-of-delete-button?, [bbb] + 337 print screen, [delete], 232/black, 52/background-red + 338 clear-line-until screen, right, 52/background-red + 339 ] + 340 + 341 # divide up the menu bar for a sandbox into 3 segments, for edit/copy/delete buttons + 342 # delete-button-right == right + 343 # all left/right pairs are inclusive + 344 def sandbox-menu-columns left:num, right:num -> edit-button-left:num, edit-button-right:num, copy-button-left:num, copy-button-right:num, delete-button-left:num [ + 345 local-scope + 346 load-ingredients + 347 start-buttons:num <- add left, 4/space-for-sandbox-index + 348 buttons-space:num <- subtract right, start-buttons + 349 button-width:num <- divide-with-remainder buttons-space, 3 # integer division + 350 buttons-wide-enough?:bool <- greater-or-equal button-width, 8 + 351 assert buttons-wide-enough?, [sandbox must be at least 30 or so characters wide] + 352 edit-button-left:num <- copy start-buttons + 353 copy-button-left:num <- add start-buttons, button-width + 354 edit-button-right:num <- subtract copy-button-left, 1 + 355 delete-button-left:num <- subtract right, button-width + 356 copy-button-right:num <- subtract delete-button-left, 1 + 357 ] + 358 + 359 # print a text 's' to 'editor' in 'color' starting at 'row' + 360 # clear rest of last line, move cursor to next line + 361 def render-text screen:&:screen, s:text, left:num, right:num, color:num, row:num -> row:num, screen:&:screen [ + 362 local-scope + 363 load-ingredients + 364 return-unless s + 365 column:num <- copy left + 366 screen <- move-cursor screen, row, column + 367 screen-height:num <- screen-height screen + 368 i:num <- copy 0 + 369 len:num <- length *s + 370 { + 371 ¦ +next-character + 372 ¦ done?:bool <- greater-or-equal i, len + 373 ¦ break-if done? + 374 ¦ done? <- greater-or-equal row, screen-height + 375 ¦ break-if done? + 376 ¦ c:char <- index *s, i + 377 ¦ { + 378 ¦ ¦ # at right? wrap. + 379 ¦ ¦ at-right?:bool <- equal column, right + 380 ¦ ¦ break-unless at-right? + 381 ¦ ¦ # print wrap icon + 382 ¦ ¦ wrap-icon:char <- copy 8617/loop-back-to-left + 383 ¦ ¦ print screen, wrap-icon, 245/grey + 384 ¦ ¦ column <- copy left + 385 ¦ ¦ row <- add row, 1 + 386 ¦ ¦ screen <- move-cursor screen, row, column + 387 ¦ ¦ loop +next-character # retry i + 388 ¦ } + 389 ¦ i <- add i, 1 + 390 ¦ { + 391 ¦ ¦ # newline? move to left rather than 0 + 392 ¦ ¦ newline?:bool <- equal c, 10/newline + 393 ¦ ¦ break-unless newline? + 394 ¦ ¦ # clear rest of line in this window + 395 ¦ ¦ { + 396 ¦ ¦ ¦ done?:bool <- greater-than column, right + 397 ¦ ¦ ¦ break-if done? + 398 ¦ ¦ ¦ space:char <- copy 32/space + 399 ¦ ¦ ¦ print screen, space + 400 ¦ ¦ ¦ column <- add column, 1 + 401 ¦ ¦ ¦ loop + 402 ¦ ¦ } + 403 ¦ ¦ row <- add row, 1 + 404 ¦ ¦ column <- copy left + 405 ¦ ¦ screen <- move-cursor screen, row, column + 406 ¦ ¦ loop +next-character + 407 ¦ } + 408 ¦ print screen, c, color + 409 ¦ column <- add column, 1 + 410 ¦ loop + 411 } + 412 was-at-left?:bool <- equal column, left + 413 clear-line-until screen, right + 414 { + 415 ¦ break-if was-at-left? + 416 ¦ row <- add row, 1 + 417 } + 418 move-cursor screen, row, left + 419 ] + 420 + 421 # assumes programming environment has no sandboxes; restores them from previous session + 422 def restore-sandboxes env:&:environment, resources:&:resources -> env:&:environment [ + 423 local-scope + 424 load-ingredients + 425 # read all scenarios, pushing them to end of a list of scenarios + 426 idx:num <- copy 0 + 427 curr:&:sandbox <- copy 0 + 428 prev:&:sandbox <- copy 0 + 429 { + 430 ¦ filename:text <- append [lesson/], idx + 431 ¦ contents:text <- slurp resources, filename + 432 ¦ break-unless contents # stop at first error; assuming file didn't exist + 433 ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ # todo: handle empty sandbox + 434 ¦ # create new sandbox for file + 435 ¦ curr <- new sandbox:type + 436 ¦ *curr <- put *curr, data:offset, contents + 437 ¦ <end-restore-sandbox> + 438 ¦ { + 439 ¦ ¦ break-if idx + 440 ¦ ¦ *env <- put *env, sandbox:offset, curr + 441 ¦ } + 442 ¦ { + 443 ¦ ¦ break-unless idx + 444 ¦ ¦ *prev <- put *prev, next-sandbox:offset, curr + 445 ¦ } + 446 ¦ idx <- add idx, 1 + 447 ¦ prev <- copy curr + 448 ¦ loop + 449 } + 450 # update sandbox count + 451 *env <- put *env, number-of-sandboxes:offset, idx + 452 ] + 453 + 454 # print the fake sandbox screen to 'screen' with appropriate delimiters + 455 # leave cursor at start of next line + 456 def render-screen screen:&:screen, sandbox-screen:&:screen, left:num, right:num, row:num -> row:num, screen:&:screen [ + 457 local-scope + 458 load-ingredients + 459 return-unless sandbox-screen + 460 # print 'screen:' + 461 row <- render-text screen, [screen:], left, right, 245/grey, row + 462 screen <- move-cursor screen, row, left + 463 # start printing sandbox-screen + 464 column:num <- copy left + 465 s-width:num <- screen-width sandbox-screen + 466 s-height:num <- screen-height sandbox-screen + 467 buf:&:@:screen-cell <- get *sandbox-screen, data:offset + 468 stop-printing:num <- add left, s-width, 3 + 469 max-column:num <- min stop-printing, right + 470 i:num <- copy 0 + 471 len:num <- length *buf + 472 screen-height:num <- screen-height screen + 473 { + 474 ¦ done?:bool <- greater-or-equal i, len + 475 ¦ break-if done? + 476 ¦ done? <- greater-or-equal row, screen-height + 477 ¦ break-if done? + 478 ¦ column <- copy left + 479 ¦ screen <- move-cursor screen, row, column + 480 ¦ # initial leader for each row: two spaces and a '.' + 481 ¦ space:char <- copy 32/space + 482 ¦ print screen, space, 245/grey + 483 ¦ print screen, space, 245/grey + 484 ¦ full-stop:char <- copy 46/period + 485 ¦ print screen, full-stop, 245/grey + 486 ¦ column <- add left, 3 + 487 ¦ { + 488 ¦ ¦ # print row + 489 ¦ ¦ row-done?:bool <- greater-or-equal column, max-column + 490 ¦ ¦ break-if row-done? + 491 ¦ ¦ curr:screen-cell <- index *buf, i + 492 ¦ ¦ c:char <- get curr, contents:offset + 493 ¦ ¦ color:num <- get curr, color:offset + 494 ¦ ¦ { + 495 ¦ ¦ ¦ # damp whites down to grey + 496 ¦ ¦ ¦ white?:bool <- equal color, 7/white + 497 ¦ ¦ ¦ break-unless white? + 498 ¦ ¦ ¦ color <- copy 245/grey + 499 ¦ ¦ } + 500 ¦ ¦ print screen, c, color + 501 ¦ ¦ column <- add column, 1 + 502 ¦ ¦ i <- add i, 1 + 503 ¦ ¦ loop + 504 ¦ } + 505 ¦ # print final '.' + 506 ¦ print screen, full-stop, 245/grey + 507 ¦ column <- add column, 1 + 508 ¦ { + 509 ¦ ¦ # clear rest of current line + 510 ¦ ¦ line-done?:bool <- greater-than column, right + 511 ¦ ¦ break-if line-done? + 512 ¦ ¦ print screen, space + 513 ¦ ¦ column <- add column, 1 + 514 ¦ ¦ loop + 515 ¦ } + 516 ¦ row <- add row, 1 + 517 ¦ loop + 518 } + 519 ] + 520 + 521 scenario run-updates-results [ + 522 local-scope + 523 trace-until 100/app # trace too long + 524 assume-screen 100/width, 12/height + 525 # define a recipe (no indent for the 'add' line below so column numbers are more obvious) + 526 assume-resources [ + 527 ¦ [lesson/recipes.mu] <- [ + 528 ¦ ¦ || + 529 ¦ ¦ |recipe foo [| + 530 ¦ ¦ | local-scope| + 531 ¦ ¦ | z:num <- add 2, 2| + 532 ¦ ¦ | reply z| + 533 ¦ ¦ |]| + 534 ¦ ] + 535 ] + 536 # sandbox editor contains an instruction without storing outputs + 537 env:&:environment <- new-programming-environment resources, screen, [foo] # contents of sandbox editor + 538 # run the code in the editors + 539 assume-console [ + 540 ¦ press F4 + 541 ] + 542 event-loop screen, console, env, resources + 543 screen-should-contain [ + 544 ¦ . run (F4) . + 545 ¦ . ╎ . + 546 ¦ .recipe foo [ ╎─────────────────────────────────────────────────. + 547 ¦ . local-scope ╎0 edit copy delete . + 548 ¦ . z:num <- add 2, 2 ╎foo . + 549 ¦ . reply z ╎4 . + 550 ¦ .] ╎─────────────────────────────────────────────────. + 551 ¦ . ╎ . + 552 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . + 553 ¦ . ╎ . + 554 ] + 555 # make a change (incrementing one of the args to 'add'), then rerun + 556 assume-console [ + 557 ¦ left-click 4, 28 # one past the value of the second arg + 558 ¦ press backspace + 559 ¦ type [3] + 560 ¦ press F4 561 ] - 562 # check that screen updates the result on the right - 563 screen-should-contain [ - 564 ¦ . run (F4) . - 565 ¦ . ╎ . - 566 ¦ .recipe foo [ ╎─────────────────────────────────────────────────. - 567 ¦ . local-scope ╎0 edit copy delete . - 568 ¦ . z:num <- add 2, 3 ╎foo . - 569 ¦ . reply z ╎5 . - 570 ¦ .] ╎─────────────────────────────────────────────────. - 571 ¦ . ╎ . - 572 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . - 573 ¦ . ╎ . - 574 ] - 575 ] - 576 - 577 scenario run-instruction-manages-screen-per-sandbox [ - 578 local-scope - 579 trace-until 100/app # trace too long - 580 assume-screen 100/width, 20/height - 581 # empty recipes - 582 assume-resources [ - 583 ] - 584 # sandbox editor contains an instruction - 585 env:&:environment <- new-programming-environment resources, screen, [print screen, 4] # contents of sandbox editor - 586 # run the code in the editor - 587 assume-console [ - 588 ¦ press F4 - 589 ] - 590 run [ - 591 ¦ event-loop screen, console, env, resources + 562 run [ + 563 ¦ event-loop screen, console, env, resources + 564 ] + 565 # check that screen updates the result on the right + 566 screen-should-contain [ + 567 ¦ . run (F4) . + 568 ¦ . ╎ . + 569 ¦ .recipe foo [ ╎─────────────────────────────────────────────────. + 570 ¦ . local-scope ╎0 edit copy delete . + 571 ¦ . z:num <- add 2, 3 ╎foo . + 572 ¦ . reply z ╎5 . + 573 ¦ .] ╎─────────────────────────────────────────────────. + 574 ¦ . ╎ . + 575 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . + 576 ¦ . ╎ . + 577 ] + 578 ] + 579 + 580 scenario run-instruction-manages-screen-per-sandbox [ + 581 local-scope + 582 trace-until 100/app # trace too long + 583 assume-screen 100/width, 20/height + 584 # empty recipes + 585 assume-resources [ + 586 ] + 587 # sandbox editor contains an instruction + 588 env:&:environment <- new-programming-environment resources, screen, [print screen, 4] # contents of sandbox editor + 589 # run the code in the editor + 590 assume-console [ + 591 ¦ press F4 592 ] - 593 # check that it prints a little toy screen - 594 screen-should-contain [ - 595 ¦ . run (F4) . - 596 ¦ . ╎ . - 597 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. - 598 ¦ . ╎0 edit copy delete . - 599 ¦ . ╎print screen, 4 . - 600 ¦ . ╎screen: . - 601 ¦ . ╎ .4 . . - 602 ¦ . ╎ . . . - 603 ¦ . ╎ . . . - 604 ¦ . ╎ . . . + 593 run [ + 594 ¦ event-loop screen, console, env, resources + 595 ] + 596 # check that it prints a little toy screen + 597 screen-should-contain [ + 598 ¦ . run (F4) . + 599 ¦ . ╎ . + 600 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. + 601 ¦ . ╎0 edit copy delete . + 602 ¦ . ╎print screen, 4 . + 603 ¦ . ╎screen: . + 604 ¦ . ╎ .4 . . 605 ¦ . ╎ . . . - 606 ¦ . ╎─────────────────────────────────────────────────. - 607 ¦ . ╎ . - 608 ] - 609 ] - 610 - 611 def editor-contents editor:&:editor -> result:text [ - 612 local-scope - 613 load-ingredients - 614 buf:&:buffer <- new-buffer 80 - 615 curr:&:duplex-list:char <- get *editor, data:offset - 616 # skip § sentinel - 617 assert curr, [editor without data is illegal; must have at least a sentinel] - 618 curr <- next curr - 619 return-unless curr, 0 - 620 { - 621 ¦ break-unless curr - 622 ¦ c:char <- get *curr, value:offset - 623 ¦ buf <- append buf, c - 624 ¦ curr <- next curr - 625 ¦ loop - 626 } - 627 result <- buffer-to-array buf - 628 ] - 629 - 630 scenario editor-provides-edited-contents [ - 631 local-scope - 632 assume-screen 10/width, 5/height - 633 e:&:editor <- new-editor [abc], 0/left, 10/right - 634 assume-console [ - 635 ¦ left-click 1, 2 - 636 ¦ type [def] - 637 ] - 638 run [ - 639 ¦ editor-event-loop screen, console, e - 640 ¦ s:text <- editor-contents e - 641 ¦ 1:@:char/raw <- copy *s - 642 ] - 643 memory-should-contain [ - 644 ¦ 1:array:character <- [abdefc] + 606 ¦ . ╎ . . . + 607 ¦ . ╎ . . . + 608 ¦ . ╎ . . . + 609 ¦ . ╎─────────────────────────────────────────────────. + 610 ¦ . ╎ . + 611 ] + 612 ] + 613 + 614 def editor-contents editor:&:editor -> result:text [ + 615 local-scope + 616 load-ingredients + 617 buf:&:buffer <- new-buffer 80 + 618 curr:&:duplex-list:char <- get *editor, data:offset + 619 # skip § sentinel + 620 assert curr, [editor without data is illegal; must have at least a sentinel] + 621 curr <- next curr + 622 return-unless curr, 0 + 623 { + 624 ¦ break-unless curr + 625 ¦ c:char <- get *curr, value:offset + 626 ¦ buf <- append buf, c + 627 ¦ curr <- next curr + 628 ¦ loop + 629 } + 630 result <- buffer-to-array buf + 631 ] + 632 + 633 scenario editor-provides-edited-contents [ + 634 local-scope + 635 assume-screen 10/width, 5/height + 636 e:&:editor <- new-editor [abc], 0/left, 10/right + 637 assume-console [ + 638 ¦ left-click 1, 2 + 639 ¦ type [def] + 640 ] + 641 run [ + 642 ¦ editor-event-loop screen, console, e + 643 ¦ s:text <- editor-contents e + 644 ¦ 1:@:char/raw <- copy *s 645 ] - 646 ] - 647 - 648 # keep the bottom of recipes from scrolling off the screen - 649 - 650 scenario scrolling-down-past-bottom-of-recipe-editor [ - 651 local-scope - 652 trace-until 100/app - 653 assume-screen 100/width, 10/height - 654 assume-resources [ - 655 ] - 656 env:&:environment <- new-programming-environment resources, screen, [] - 657 render-all screen, env, render - 658 assume-console [ - 659 ¦ press enter - 660 ¦ press down-arrow - 661 ] - 662 event-loop screen, console, env, resources - 663 # no scroll - 664 screen-should-contain [ - 665 ¦ . run (F4) . - 666 ¦ . ╎ . - 667 ¦ . ╎─────────────────────────────────────────────────. - 668 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . + 646 memory-should-contain [ + 647 ¦ 1:array:character <- [abdefc] + 648 ] + 649 ] + 650 + 651 # keep the bottom of recipes from scrolling off the screen + 652 + 653 scenario scrolling-down-past-bottom-of-recipe-editor [ + 654 local-scope + 655 trace-until 100/app + 656 assume-screen 100/width, 10/height + 657 assume-resources [ + 658 ] + 659 env:&:environment <- new-programming-environment resources, screen, [] + 660 render-all screen, env, render + 661 assume-console [ + 662 ¦ press enter + 663 ¦ press down-arrow + 664 ] + 665 event-loop screen, console, env, resources + 666 # no scroll + 667 screen-should-contain [ + 668 ¦ . run (F4) . 669 ¦ . ╎ . - 670 ] - 671 ] - 672 - 673 scenario cursor-down-in-recipe-editor [ - 674 local-scope - 675 trace-until 100/app - 676 assume-screen 100/width, 10/height - 677 assume-resources [ - 678 ] - 679 env:&:environment <- new-programming-environment resources, screen, [] - 680 render-all screen, env, render - 681 assume-console [ - 682 ¦ press enter - 683 ¦ press up-arrow - 684 ¦ press down-arrow # while cursor isn't at bottom - 685 ] - 686 event-loop screen, console, env, resources - 687 cursor:char <- copy 9251/␣ - 688 print screen, cursor - 689 # cursor moves back to bottom - 690 screen-should-contain [ - 691 ¦ . run (F4) . - 692 ¦ . ╎ . - 693 ¦ .␣ ╎─────────────────────────────────────────────────. - 694 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . + 670 ¦ . ╎─────────────────────────────────────────────────. + 671 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . + 672 ¦ . ╎ . + 673 ] + 674 ] + 675 + 676 scenario cursor-down-in-recipe-editor [ + 677 local-scope + 678 trace-until 100/app + 679 assume-screen 100/width, 10/height + 680 assume-resources [ + 681 ] + 682 env:&:environment <- new-programming-environment resources, screen, [] + 683 render-all screen, env, render + 684 assume-console [ + 685 ¦ press enter + 686 ¦ press up-arrow + 687 ¦ press down-arrow # while cursor isn't at bottom + 688 ] + 689 event-loop screen, console, env, resources + 690 cursor:char <- copy 9251/␣ + 691 print screen, cursor + 692 # cursor moves back to bottom + 693 screen-should-contain [ + 694 ¦ . run (F4) . 695 ¦ . ╎ . - 696 ] - 697 ] - 698 - 699 # we'll not use the recipe-editor's 'bottom' element directly, because later - 700 # layers will add other stuff to the left side below the editor (error messages) + 696 ¦ .␣ ╎─────────────────────────────────────────────────. + 697 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . + 698 ¦ . ╎ . + 699 ] + 700 ] 701 - 702 container environment [ - 703 recipe-bottom:num - 704 ] - 705 - 706 after <render-recipe-components-end> [ - 707 *env <- put *env, recipe-bottom:offset, row - 708 ] - 709 - 710 after <global-keypress> [ - 711 { - 712 ¦ break-if sandbox-in-focus? - 713 ¦ down-arrow?:bool <- equal k, 65516/down-arrow - 714 ¦ break-unless down-arrow? - 715 ¦ recipe-editor:&:editor <- get *env, recipes:offset - 716 ¦ recipe-cursor-row:num <- get *recipe-editor, cursor-row:offset - 717 ¦ recipe-editor-bottom:num <- get *recipe-editor, bottom:offset - 718 ¦ at-bottom-of-editor?:bool <- greater-or-equal recipe-cursor-row, recipe-editor-bottom - 719 ¦ break-unless at-bottom-of-editor? - 720 ¦ more-to-scroll?:bool <- more-to-scroll? env, screen - 721 ¦ break-if more-to-scroll? - 722 ¦ loop +next-event - 723 } - 724 { - 725 ¦ break-if sandbox-in-focus? - 726 ¦ page-down?:bool <- equal k, 65518/page-down - 727 ¦ break-unless page-down? - 728 ¦ more-to-scroll?:bool <- more-to-scroll? env, screen - 729 ¦ break-if more-to-scroll? - 730 ¦ loop +next-event - 731 } - 732 ] - 733 - 734 after <global-type> [ - 735 { - 736 ¦ break-if sandbox-in-focus? - 737 ¦ page-down?:bool <- equal k, 6/ctrl-f - 738 ¦ break-unless page-down? - 739 ¦ more-to-scroll?:bool <- more-to-scroll? env, screen - 740 ¦ break-if more-to-scroll? - 741 ¦ loop +next-event - 742 } - 743 ] - 744 - 745 def more-to-scroll? env:&:environment, screen:&:screen -> result:bool [ - 746 local-scope - 747 load-ingredients - 748 recipe-bottom:num <- get *env, recipe-bottom:offset - 749 height:num <- screen-height screen - 750 result <- greater-or-equal recipe-bottom, height - 751 ] - 752 - 753 scenario scrolling-down-past-bottom-of-recipe-editor-2 [ - 754 local-scope - 755 trace-until 100/app - 756 assume-screen 100/width, 10/height - 757 assume-resources [ - 758 ] - 759 env:&:environment <- new-programming-environment resources, screen, [] - 760 render-all screen, env, render - 761 assume-console [ - 762 ¦ # add a line - 763 ¦ press enter - 764 ¦ # cursor back to top line - 765 ¦ press up-arrow - 766 ¦ # try to scroll - 767 ¦ press page-down # or ctrl-f - 768 ] - 769 event-loop screen, console, env, resources - 770 # no scroll, and cursor remains at top line - 771 screen-should-contain [ - 772 ¦ . run (F4) . - 773 ¦ . ╎ . - 774 ¦ . ╎─────────────────────────────────────────────────. - 775 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . + 702 # we'll not use the recipe-editor's 'bottom' element directly, because later + 703 # layers will add other stuff to the left side below the editor (error messages) + 704 + 705 container environment [ + 706 recipe-bottom:num + 707 ] + 708 + 709 after <render-recipe-components-end> [ + 710 *env <- put *env, recipe-bottom:offset, row + 711 ] + 712 + 713 after <global-keypress> [ + 714 { + 715 ¦ break-if sandbox-in-focus? + 716 ¦ down-arrow?:bool <- equal k, 65516/down-arrow + 717 ¦ break-unless down-arrow? + 718 ¦ recipe-editor:&:editor <- get *env, recipes:offset + 719 ¦ recipe-cursor-row:num <- get *recipe-editor, cursor-row:offset + 720 ¦ recipe-editor-bottom:num <- get *recipe-editor, bottom:offset + 721 ¦ at-bottom-of-editor?:bool <- greater-or-equal recipe-cursor-row, recipe-editor-bottom + 722 ¦ break-unless at-bottom-of-editor? + 723 ¦ more-to-scroll?:bool <- more-to-scroll? env, screen + 724 ¦ break-if more-to-scroll? + 725 ¦ loop +next-event + 726 } + 727 { + 728 ¦ break-if sandbox-in-focus? + 729 ¦ page-down?:bool <- equal k, 65518/page-down + 730 ¦ break-unless page-down? + 731 ¦ more-to-scroll?:bool <- more-to-scroll? env, screen + 732 ¦ break-if more-to-scroll? + 733 ¦ loop +next-event + 734 } + 735 ] + 736 + 737 after <global-type> [ + 738 { + 739 ¦ break-if sandbox-in-focus? + 740 ¦ page-down?:bool <- equal k, 6/ctrl-f + 741 ¦ break-unless page-down? + 742 ¦ more-to-scroll?:bool <- more-to-scroll? env, screen + 743 ¦ break-if more-to-scroll? + 744 ¦ loop +next-event + 745 } + 746 ] + 747 + 748 def more-to-scroll? env:&:environment, screen:&:screen -> result:bool [ + 749 local-scope + 750 load-ingredients + 751 recipe-bottom:num <- get *env, recipe-bottom:offset + 752 height:num <- screen-height screen + 753 result <- greater-or-equal recipe-bottom, height + 754 ] + 755 + 756 scenario scrolling-down-past-bottom-of-recipe-editor-2 [ + 757 local-scope + 758 trace-until 100/app + 759 assume-screen 100/width, 10/height + 760 assume-resources [ + 761 ] + 762 env:&:environment <- new-programming-environment resources, screen, [] + 763 render-all screen, env, render + 764 assume-console [ + 765 ¦ # add a line + 766 ¦ press enter + 767 ¦ # cursor back to top line + 768 ¦ press up-arrow + 769 ¦ # try to scroll + 770 ¦ press page-down # or ctrl-f + 771 ] + 772 event-loop screen, console, env, resources + 773 # no scroll, and cursor remains at top line + 774 screen-should-contain [ + 775 ¦ . run (F4) . 776 ¦ . ╎ . - 777 ] - 778 ] - 779 - 780 scenario scrolling-down-past-bottom-of-recipe-editor-3 [ - 781 local-scope - 782 trace-until 100/app - 783 assume-screen 100/width, 10/height - 784 assume-resources [ - 785 ] - 786 env:&:environment <- new-programming-environment resources, screen, [ab - 787 cd] - 788 render-all screen, env, render - 789 assume-console [ - 790 ¦ # add a line - 791 ¦ press enter - 792 ¦ # switch to sandbox - 793 ¦ press ctrl-n - 794 ¦ # move cursor - 795 ¦ press down-arrow - 796 ] - 797 event-loop screen, console, env, resources - 798 cursor:char <- copy 9251/␣ - 799 print screen, cursor - 800 # no scroll on recipe side, cursor moves on sandbox side - 801 screen-should-contain [ - 802 ¦ . run (F4) . - 803 ¦ . ╎ab . - 804 ¦ . ╎␣d . - 805 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. - 806 ¦ . ╎ . - 807 ] - 808 ] - 809 - 810 # scrolling through sandboxes - 811 - 812 scenario scrolling-down-past-bottom-of-sandbox-editor [ - 813 local-scope - 814 trace-until 100/app # trace too long - 815 assume-screen 100/width, 10/height - 816 # initialize - 817 assume-resources [ - 818 ] - 819 env:&:environment <- new-programming-environment resources, screen, [add 2, 2] - 820 render-all screen, env, render - 821 assume-console [ - 822 ¦ # create a sandbox - 823 ¦ press F4 - 824 ] - 825 event-loop screen, console, env, resources - 826 screen-should-contain [ - 827 ¦ . run (F4) . - 828 ¦ . ╎ . - 829 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. - 830 ¦ . ╎0 edit copy delete . - 831 ¦ . ╎add 2, 2 . - 832 ] - 833 # switch to sandbox window and hit 'page-down' - 834 assume-console [ - 835 ¦ press ctrl-n - 836 ¦ press page-down - 837 ] - 838 run [ - 839 ¦ event-loop screen, console, env, resources - 840 ¦ cursor:char <- copy 9251/␣ - 841 ¦ print screen, cursor - 842 ] - 843 # sandbox editor hidden; first sandbox displayed - 844 # cursor moves to first sandbox - 845 screen-should-contain [ - 846 ¦ . run (F4) . - 847 ¦ . ╎─────────────────────────────────────────────────. - 848 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎␣ edit copy delete . - 849 ¦ . ╎add 2, 2 . - 850 ¦ . ╎4 . - 851 ] - 852 # hit 'page-up' - 853 assume-console [ - 854 ¦ press page-up - 855 ] - 856 run [ - 857 ¦ event-loop screen, console, env, resources - 858 ¦ cursor:char <- copy 9251/␣ - 859 ¦ print screen, cursor - 860 ] - 861 # sandbox editor displays again, cursor is in editor - 862 screen-should-contain [ - 863 ¦ . run (F4) . - 864 ¦ . ╎␣ . - 865 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. - 866 ¦ . ╎0 edit copy delete . - 867 ¦ . ╎add 2, 2 . - 868 ] - 869 ] - 870 - 871 # page-down on sandbox side updates render-from to scroll sandboxes - 872 after <global-keypress> [ - 873 { - 874 ¦ break-unless sandbox-in-focus? - 875 ¦ page-down?:bool <- equal k, 65518/page-down - 876 ¦ break-unless page-down? - 877 ¦ sandbox:&:sandbox <- get *env, sandbox:offset - 878 ¦ break-unless sandbox - 879 ¦ # slide down if possible - 880 ¦ { - 881 ¦ ¦ render-from:num <- get *env, render-from:offset - 882 ¦ ¦ number-of-sandboxes:num <- get *env, number-of-sandboxes:offset - 883 ¦ ¦ max:num <- subtract number-of-sandboxes, 1 - 884 ¦ ¦ at-end?:bool <- greater-or-equal render-from, max - 885 ¦ ¦ jump-if at-end?, +finish-event # render nothing - 886 ¦ ¦ render-from <- add render-from, 1 - 887 ¦ ¦ *env <- put *env, render-from:offset, render-from - 888 ¦ } - 889 ¦ hide-screen screen - 890 ¦ screen <- render-sandbox-side screen, env, render - 891 ¦ show-screen screen - 892 ¦ jump +finish-event - 893 } - 894 ] - 895 - 896 # update-cursor takes render-from into account - 897 after <update-cursor-special-cases> [ - 898 { - 899 ¦ break-unless sandbox-in-focus? - 900 ¦ render-from:num <- get *env, render-from:offset - 901 ¦ scrolling?:bool <- greater-or-equal render-from, 0 - 902 ¦ break-unless scrolling? - 903 ¦ cursor-column:num <- get *current-sandbox, left:offset - 904 ¦ screen <- move-cursor screen, 2/row, cursor-column # highlighted sandbox will always start at row 2 - 905 ¦ return - 906 } - 907 ] - 908 - 909 # 'page-up' on sandbox side is like 'page-down': updates render-from when necessary - 910 after <global-keypress> [ - 911 { - 912 ¦ break-unless sandbox-in-focus? - 913 ¦ page-up?:bool <- equal k, 65519/page-up - 914 ¦ break-unless page-up? - 915 ¦ render-from:num <- get *env, render-from:offset - 916 ¦ at-beginning?:bool <- equal render-from, -1 - 917 ¦ break-if at-beginning? - 918 ¦ render-from <- subtract render-from, 1 - 919 ¦ *env <- put *env, render-from:offset, render-from - 920 ¦ hide-screen screen - 921 ¦ screen <- render-sandbox-side screen, env, render - 922 ¦ show-screen screen - 923 ¦ jump +finish-event - 924 } - 925 ] - 926 - 927 # sandbox belonging to 'env' whose next-sandbox is 'in' - 928 # return 0 if there's no such sandbox, either because 'in' doesn't exist in 'env', or because it's the first sandbox - 929 def previous-sandbox env:&:environment, in:&:sandbox -> out:&:sandbox [ - 930 local-scope - 931 load-ingredients - 932 curr:&:sandbox <- get *env, sandbox:offset - 933 return-unless curr, 0/nil - 934 next:&:sandbox <- get *curr, next-sandbox:offset - 935 { - 936 ¦ return-unless next, 0/nil - 937 ¦ found?:bool <- equal next, in - 938 ¦ break-if found? - 939 ¦ curr <- copy next - 940 ¦ next <- get *curr, next-sandbox:offset - 941 ¦ loop - 942 } - 943 return curr - 944 ] - 945 - 946 scenario scrolling-down-past-bottom-on-recipe-side [ - 947 local-scope - 948 trace-until 100/app # trace too long - 949 assume-screen 100/width, 10/height - 950 # initialize sandbox side and create a sandbox - 951 assume-resources [ - 952 ¦ [lesson/recipes.mu] <- [ - 953 ¦ ¦ || # file containing just a newline - 954 ¦ ] - 955 ] - 956 # create a sandbox - 957 env:&:environment <- new-programming-environment resources, screen, [add 2, 2] - 958 render-all screen, env, render - 959 assume-console [ - 960 ¦ press F4 - 961 ] - 962 event-loop screen, console, env, resources - 963 # hit 'down' in recipe editor - 964 assume-console [ - 965 ¦ press page-down - 966 ] - 967 run [ - 968 ¦ event-loop screen, console, env, resources - 969 ¦ cursor:char <- copy 9251/␣ - 970 ¦ print screen, cursor - 971 ] - 972 # cursor doesn't move when the end is already on-screen - 973 screen-should-contain [ - 974 ¦ . run (F4) . - 975 ¦ .␣ ╎ . - 976 ¦ . ╎─────────────────────────────────────────────────. - 977 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . - 978 ¦ . ╎add 2, 2 . - 979 ] - 980 ] - 981 - 982 scenario scrolling-through-multiple-sandboxes [ - 983 local-scope - 984 trace-until 100/app # trace too long - 985 assume-screen 100/width, 10/height - 986 # initialize environment - 987 assume-resources [ - 988 ] - 989 env:&:environment <- new-programming-environment resources, screen, [] - 990 render-all screen, env, render - 991 # create 2 sandboxes - 992 assume-console [ - 993 ¦ press ctrl-n - 994 ¦ type [add 2, 2] - 995 ¦ press F4 - 996 ¦ type [add 1, 1] - 997 ¦ press F4 - 998 ] - 999 event-loop screen, console, env, resources -1000 cursor:char <- copy 9251/␣ -1001 print screen, cursor -1002 screen-should-contain [ -1003 ¦ . run (F4) . -1004 ¦ . ╎␣ . -1005 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -1006 ¦ . ╎0 edit copy delete . -1007 ¦ . ╎add 1, 1 . -1008 ¦ . ╎2 . -1009 ¦ . ╎─────────────────────────────────────────────────. -1010 ¦ . ╎1 edit copy delete . -1011 ¦ . ╎add 2, 2 . -1012 ¦ . ╎4 . -1013 ] -1014 # hit 'page-down' -1015 assume-console [ -1016 ¦ press page-down -1017 ] -1018 run [ -1019 ¦ event-loop screen, console, env, resources -1020 ¦ cursor:char <- copy 9251/␣ -1021 ¦ print screen, cursor -1022 ] -1023 # sandbox editor hidden; first sandbox displayed -1024 # cursor moves to first sandbox -1025 screen-should-contain [ -1026 ¦ . run (F4) . -1027 ¦ . ╎─────────────────────────────────────────────────. -1028 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎␣ edit copy delete . -1029 ¦ . ╎add 1, 1 . -1030 ¦ . ╎2 . -1031 ¦ . ╎─────────────────────────────────────────────────. -1032 ¦ . ╎1 edit copy delete . -1033 ¦ . ╎add 2, 2 . -1034 ¦ . ╎4 . -1035 ] -1036 # hit 'page-down' again -1037 assume-console [ -1038 ¦ press page-down -1039 ] -1040 run [ -1041 ¦ event-loop screen, console, env, resources + 777 ¦ . ╎─────────────────────────────────────────────────. + 778 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . + 779 ¦ . ╎ . + 780 ] + 781 ] + 782 + 783 scenario scrolling-down-past-bottom-of-recipe-editor-3 [ + 784 local-scope + 785 trace-until 100/app + 786 assume-screen 100/width, 10/height + 787 assume-resources [ + 788 ] + 789 env:&:environment <- new-programming-environment resources, screen, [ab + 790 cd] + 791 render-all screen, env, render + 792 assume-console [ + 793 ¦ # add a line + 794 ¦ press enter + 795 ¦ # switch to sandbox + 796 ¦ press ctrl-n + 797 ¦ # move cursor + 798 ¦ press down-arrow + 799 ] + 800 event-loop screen, console, env, resources + 801 cursor:char <- copy 9251/␣ + 802 print screen, cursor + 803 # no scroll on recipe side, cursor moves on sandbox side + 804 screen-should-contain [ + 805 ¦ . run (F4) . + 806 ¦ . ╎ab . + 807 ¦ . ╎␣d . + 808 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. + 809 ¦ . ╎ . + 810 ] + 811 ] + 812 + 813 # scrolling through sandboxes + 814 + 815 scenario scrolling-down-past-bottom-of-sandbox-editor [ + 816 local-scope + 817 trace-until 100/app # trace too long + 818 assume-screen 100/width, 10/height + 819 # initialize + 820 assume-resources [ + 821 ] + 822 env:&:environment <- new-programming-environment resources, screen, [add 2, 2] + 823 render-all screen, env, render + 824 assume-console [ + 825 ¦ # create a sandbox + 826 ¦ press F4 + 827 ] + 828 event-loop screen, console, env, resources + 829 screen-should-contain [ + 830 ¦ . run (F4) . + 831 ¦ . ╎ . + 832 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. + 833 ¦ . ╎0 edit copy delete . + 834 ¦ . ╎add 2, 2 . + 835 ] + 836 # switch to sandbox window and hit 'page-down' + 837 assume-console [ + 838 ¦ press ctrl-n + 839 ¦ press page-down + 840 ] + 841 run [ + 842 ¦ event-loop screen, console, env, resources + 843 ¦ cursor:char <- copy 9251/␣ + 844 ¦ print screen, cursor + 845 ] + 846 # sandbox editor hidden; first sandbox displayed + 847 # cursor moves to first sandbox + 848 screen-should-contain [ + 849 ¦ . run (F4) . + 850 ¦ . ╎─────────────────────────────────────────────────. + 851 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎␣ edit copy delete . + 852 ¦ . ╎add 2, 2 . + 853 ¦ . ╎4 . + 854 ] + 855 # hit 'page-up' + 856 assume-console [ + 857 ¦ press page-up + 858 ] + 859 run [ + 860 ¦ event-loop screen, console, env, resources + 861 ¦ cursor:char <- copy 9251/␣ + 862 ¦ print screen, cursor + 863 ] + 864 # sandbox editor displays again, cursor is in editor + 865 screen-should-contain [ + 866 ¦ . run (F4) . + 867 ¦ . ╎␣ . + 868 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. + 869 ¦ . ╎0 edit copy delete . + 870 ¦ . ╎add 2, 2 . + 871 ] + 872 ] + 873 + 874 # page-down on sandbox side updates render-from to scroll sandboxes + 875 after <global-keypress> [ + 876 { + 877 ¦ break-unless sandbox-in-focus? + 878 ¦ page-down?:bool <- equal k, 65518/page-down + 879 ¦ break-unless page-down? + 880 ¦ sandbox:&:sandbox <- get *env, sandbox:offset + 881 ¦ break-unless sandbox + 882 ¦ # slide down if possible + 883 ¦ { + 884 ¦ ¦ render-from:num <- get *env, render-from:offset + 885 ¦ ¦ number-of-sandboxes:num <- get *env, number-of-sandboxes:offset + 886 ¦ ¦ max:num <- subtract number-of-sandboxes, 1 + 887 ¦ ¦ at-end?:bool <- greater-or-equal render-from, max + 888 ¦ ¦ jump-if at-end?, +finish-event # render nothing + 889 ¦ ¦ render-from <- add render-from, 1 + 890 ¦ ¦ *env <- put *env, render-from:offset, render-from + 891 ¦ } + 892 ¦ hide-screen screen + 893 ¦ screen <- render-sandbox-side screen, env, render + 894 ¦ show-screen screen + 895 ¦ jump +finish-event + 896 } + 897 ] + 898 + 899 # update-cursor takes render-from into account + 900 after <update-cursor-special-cases> [ + 901 { + 902 ¦ break-unless sandbox-in-focus? + 903 ¦ render-from:num <- get *env, render-from:offset + 904 ¦ scrolling?:bool <- greater-or-equal render-from, 0 + 905 ¦ break-unless scrolling? + 906 ¦ cursor-column:num <- get *current-sandbox, left:offset + 907 ¦ screen <- move-cursor screen, 2/row, cursor-column # highlighted sandbox will always start at row 2 + 908 ¦ return + 909 } + 910 ] + 911 + 912 # 'page-up' on sandbox side is like 'page-down': updates render-from when necessary + 913 after <global-keypress> [ + 914 { + 915 ¦ break-unless sandbox-in-focus? + 916 ¦ page-up?:bool <- equal k, 65519/page-up + 917 ¦ break-unless page-up? + 918 ¦ render-from:num <- get *env, render-from:offset + 919 ¦ at-beginning?:bool <- equal render-from, -1 + 920 ¦ break-if at-beginning? + 921 ¦ render-from <- subtract render-from, 1 + 922 ¦ *env <- put *env, render-from:offset, render-from + 923 ¦ hide-screen screen + 924 ¦ screen <- render-sandbox-side screen, env, render + 925 ¦ show-screen screen + 926 ¦ jump +finish-event + 927 } + 928 ] + 929 + 930 # sandbox belonging to 'env' whose next-sandbox is 'in' + 931 # return 0 if there's no such sandbox, either because 'in' doesn't exist in 'env', or because it's the first sandbox + 932 def previous-sandbox env:&:environment, in:&:sandbox -> out:&:sandbox [ + 933 local-scope + 934 load-ingredients + 935 curr:&:sandbox <- get *env, sandbox:offset + 936 return-unless curr, 0/nil + 937 next:&:sandbox <- get *curr, next-sandbox:offset + 938 { + 939 ¦ return-unless next, 0/nil + 940 ¦ found?:bool <- equal next, in + 941 ¦ break-if found? + 942 ¦ curr <- copy next + 943 ¦ next <- get *curr, next-sandbox:offset + 944 ¦ loop + 945 } + 946 return curr + 947 ] + 948 + 949 scenario scrolling-down-past-bottom-on-recipe-side [ + 950 local-scope + 951 trace-until 100/app # trace too long + 952 assume-screen 100/width, 10/height + 953 # initialize sandbox side and create a sandbox + 954 assume-resources [ + 955 ¦ [lesson/recipes.mu] <- [ + 956 ¦ ¦ || # file containing just a newline + 957 ¦ ] + 958 ] + 959 # create a sandbox + 960 env:&:environment <- new-programming-environment resources, screen, [add 2, 2] + 961 render-all screen, env, render + 962 assume-console [ + 963 ¦ press F4 + 964 ] + 965 event-loop screen, console, env, resources + 966 # hit 'down' in recipe editor + 967 assume-console [ + 968 ¦ press page-down + 969 ] + 970 run [ + 971 ¦ event-loop screen, console, env, resources + 972 ¦ cursor:char <- copy 9251/␣ + 973 ¦ print screen, cursor + 974 ] + 975 # cursor doesn't move when the end is already on-screen + 976 screen-should-contain [ + 977 ¦ . run (F4) . + 978 ¦ .␣ ╎ . + 979 ¦ . ╎─────────────────────────────────────────────────. + 980 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . + 981 ¦ . ╎add 2, 2 . + 982 ] + 983 ] + 984 + 985 scenario scrolling-through-multiple-sandboxes [ + 986 local-scope + 987 trace-until 100/app # trace too long + 988 assume-screen 100/width, 10/height + 989 # initialize environment + 990 assume-resources [ + 991 ] + 992 env:&:environment <- new-programming-environment resources, screen, [] + 993 render-all screen, env, render + 994 # create 2 sandboxes + 995 assume-console [ + 996 ¦ press ctrl-n + 997 ¦ type [add 2, 2] + 998 ¦ press F4 + 999 ¦ type [add 1, 1] +1000 ¦ press F4 +1001 ] +1002 event-loop screen, console, env, resources +1003 cursor:char <- copy 9251/␣ +1004 print screen, cursor +1005 screen-should-contain [ +1006 ¦ . run (F4) . +1007 ¦ . ╎␣ . +1008 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1009 ¦ . ╎0 edit copy delete . +1010 ¦ . ╎add 1, 1 . +1011 ¦ . ╎2 . +1012 ¦ . ╎─────────────────────────────────────────────────. +1013 ¦ . ╎1 edit copy delete . +1014 ¦ . ╎add 2, 2 . +1015 ¦ . ╎4 . +1016 ] +1017 # hit 'page-down' +1018 assume-console [ +1019 ¦ press page-down +1020 ] +1021 run [ +1022 ¦ event-loop screen, console, env, resources +1023 ¦ cursor:char <- copy 9251/␣ +1024 ¦ print screen, cursor +1025 ] +1026 # sandbox editor hidden; first sandbox displayed +1027 # cursor moves to first sandbox +1028 screen-should-contain [ +1029 ¦ . run (F4) . +1030 ¦ . ╎─────────────────────────────────────────────────. +1031 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎␣ edit copy delete . +1032 ¦ . ╎add 1, 1 . +1033 ¦ . ╎2 . +1034 ¦ . ╎─────────────────────────────────────────────────. +1035 ¦ . ╎1 edit copy delete . +1036 ¦ . ╎add 2, 2 . +1037 ¦ . ╎4 . +1038 ] +1039 # hit 'page-down' again +1040 assume-console [ +1041 ¦ press page-down 1042 ] -1043 # just second sandbox displayed -1044 screen-should-contain [ -1045 ¦ . run (F4) . -1046 ¦ . ╎─────────────────────────────────────────────────. -1047 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . -1048 ¦ . ╎add 2, 2 . -1049 ¦ . ╎4 . -1050 ¦ . ╎─────────────────────────────────────────────────. -1051 ¦ . ╎ . -1052 ] -1053 # hit 'page-down' again -1054 assume-console [ -1055 ¦ press page-down -1056 ] -1057 run [ -1058 ¦ event-loop screen, console, env, resources +1043 run [ +1044 ¦ event-loop screen, console, env, resources +1045 ] +1046 # just second sandbox displayed +1047 screen-should-contain [ +1048 ¦ . run (F4) . +1049 ¦ . ╎─────────────────────────────────────────────────. +1050 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . +1051 ¦ . ╎add 2, 2 . +1052 ¦ . ╎4 . +1053 ¦ . ╎─────────────────────────────────────────────────. +1054 ¦ . ╎ . +1055 ] +1056 # hit 'page-down' again +1057 assume-console [ +1058 ¦ press page-down 1059 ] -1060 # no change -1061 screen-should-contain [ -1062 ¦ . run (F4) . -1063 ¦ . ╎─────────────────────────────────────────────────. -1064 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . -1065 ¦ . ╎add 2, 2 . -1066 ¦ . ╎4 . -1067 ¦ . ╎─────────────────────────────────────────────────. -1068 ¦ . ╎ . -1069 ] -1070 # hit 'page-up' -1071 assume-console [ -1072 ¦ press page-up -1073 ] -1074 run [ -1075 ¦ event-loop screen, console, env, resources +1060 run [ +1061 ¦ event-loop screen, console, env, resources +1062 ] +1063 # no change +1064 screen-should-contain [ +1065 ¦ . run (F4) . +1066 ¦ . ╎─────────────────────────────────────────────────. +1067 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . +1068 ¦ . ╎add 2, 2 . +1069 ¦ . ╎4 . +1070 ¦ . ╎─────────────────────────────────────────────────. +1071 ¦ . ╎ . +1072 ] +1073 # hit 'page-up' +1074 assume-console [ +1075 ¦ press page-up 1076 ] -1077 # back to displaying both sandboxes without editor -1078 screen-should-contain [ -1079 ¦ . run (F4) . -1080 ¦ . ╎─────────────────────────────────────────────────. -1081 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . -1082 ¦ . ╎add 1, 1 . -1083 ¦ . ╎2 . -1084 ¦ . ╎─────────────────────────────────────────────────. -1085 ¦ . ╎1 edit copy delete . -1086 ¦ . ╎add 2, 2 . -1087 ¦ . ╎4 . -1088 ] -1089 # hit 'page-up' again -1090 assume-console [ -1091 ¦ press page-up -1092 ] -1093 run [ -1094 ¦ event-loop screen, console, env, resources -1095 ¦ cursor:char <- copy 9251/␣ -1096 ¦ print screen, cursor -1097 ] -1098 # back to displaying both sandboxes as well as editor -1099 screen-should-contain [ -1100 ¦ . run (F4) . -1101 ¦ . ╎␣ . -1102 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -1103 ¦ . ╎0 edit copy delete . -1104 ¦ . ╎add 1, 1 . -1105 ¦ . ╎2 . -1106 ¦ . ╎─────────────────────────────────────────────────. -1107 ¦ . ╎1 edit copy delete . -1108 ¦ . ╎add 2, 2 . -1109 ¦ . ╎4 . -1110 ] -1111 # hit 'page-up' again -1112 assume-console [ -1113 ¦ press page-up -1114 ] -1115 run [ -1116 ¦ event-loop screen, console, env, resources -1117 ¦ cursor:char <- copy 9251/␣ -1118 ¦ print screen, cursor -1119 ] -1120 # no change -1121 screen-should-contain [ -1122 ¦ . run (F4) . -1123 ¦ . ╎␣ . -1124 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -1125 ¦ . ╎0 edit copy delete . -1126 ¦ . ╎add 1, 1 . -1127 ¦ . ╎2 . -1128 ¦ . ╎─────────────────────────────────────────────────. -1129 ¦ . ╎1 edit copy delete . -1130 ¦ . ╎add 2, 2 . -1131 ¦ . ╎4 . -1132 ] -1133 ] -1134 -1135 scenario scrolling-manages-sandbox-index-correctly [ -1136 local-scope -1137 trace-until 100/app # trace too long -1138 assume-screen 100/width, 10/height -1139 # initialize environment -1140 assume-resources [ -1141 ] -1142 env:&:environment <- new-programming-environment resources, screen, [] -1143 render-all screen, env, render -1144 # create a sandbox -1145 assume-console [ -1146 ¦ press ctrl-n -1147 ¦ type [add 1, 1] -1148 ¦ press F4 -1149 ] -1150 event-loop screen, console, env, resources -1151 screen-should-contain [ -1152 ¦ . run (F4) . -1153 ¦ . ╎ . -1154 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -1155 ¦ . ╎0 edit copy delete . -1156 ¦ . ╎add 1, 1 . -1157 ¦ . ╎2 . -1158 ¦ . ╎─────────────────────────────────────────────────. -1159 ¦ . ╎ . -1160 ] -1161 # hit 'page-down' and 'page-up' a couple of times. sandbox index should be stable -1162 assume-console [ -1163 ¦ press page-down -1164 ] -1165 run [ -1166 ¦ event-loop screen, console, env, resources +1077 run [ +1078 ¦ event-loop screen, console, env, resources +1079 ] +1080 # back to displaying both sandboxes without editor +1081 screen-should-contain [ +1082 ¦ . run (F4) . +1083 ¦ . ╎─────────────────────────────────────────────────. +1084 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +1085 ¦ . ╎add 1, 1 . +1086 ¦ . ╎2 . +1087 ¦ . ╎─────────────────────────────────────────────────. +1088 ¦ . ╎1 edit copy delete . +1089 ¦ . ╎add 2, 2 . +1090 ¦ . ╎4 . +1091 ] +1092 # hit 'page-up' again +1093 assume-console [ +1094 ¦ press page-up +1095 ] +1096 run [ +1097 ¦ event-loop screen, console, env, resources +1098 ¦ cursor:char <- copy 9251/␣ +1099 ¦ print screen, cursor +1100 ] +1101 # back to displaying both sandboxes as well as editor +1102 screen-should-contain [ +1103 ¦ . run (F4) . +1104 ¦ . ╎␣ . +1105 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1106 ¦ . ╎0 edit copy delete . +1107 ¦ . ╎add 1, 1 . +1108 ¦ . ╎2 . +1109 ¦ . ╎─────────────────────────────────────────────────. +1110 ¦ . ╎1 edit copy delete . +1111 ¦ . ╎add 2, 2 . +1112 ¦ . ╎4 . +1113 ] +1114 # hit 'page-up' again +1115 assume-console [ +1116 ¦ press page-up +1117 ] +1118 run [ +1119 ¦ event-loop screen, console, env, resources +1120 ¦ cursor:char <- copy 9251/␣ +1121 ¦ print screen, cursor +1122 ] +1123 # no change +1124 screen-should-contain [ +1125 ¦ . run (F4) . +1126 ¦ . ╎␣ . +1127 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1128 ¦ . ╎0 edit copy delete . +1129 ¦ . ╎add 1, 1 . +1130 ¦ . ╎2 . +1131 ¦ . ╎─────────────────────────────────────────────────. +1132 ¦ . ╎1 edit copy delete . +1133 ¦ . ╎add 2, 2 . +1134 ¦ . ╎4 . +1135 ] +1136 ] +1137 +1138 scenario scrolling-manages-sandbox-index-correctly [ +1139 local-scope +1140 trace-until 100/app # trace too long +1141 assume-screen 100/width, 10/height +1142 # initialize environment +1143 assume-resources [ +1144 ] +1145 env:&:environment <- new-programming-environment resources, screen, [] +1146 render-all screen, env, render +1147 # create a sandbox +1148 assume-console [ +1149 ¦ press ctrl-n +1150 ¦ type [add 1, 1] +1151 ¦ press F4 +1152 ] +1153 event-loop screen, console, env, resources +1154 screen-should-contain [ +1155 ¦ . run (F4) . +1156 ¦ . ╎ . +1157 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1158 ¦ . ╎0 edit copy delete . +1159 ¦ . ╎add 1, 1 . +1160 ¦ . ╎2 . +1161 ¦ . ╎─────────────────────────────────────────────────. +1162 ¦ . ╎ . +1163 ] +1164 # hit 'page-down' and 'page-up' a couple of times. sandbox index should be stable +1165 assume-console [ +1166 ¦ press page-down 1167 ] -1168 # sandbox editor hidden; first sandbox displayed -1169 # cursor moves to first sandbox -1170 screen-should-contain [ -1171 ¦ . run (F4) . -1172 ¦ . ╎─────────────────────────────────────────────────. -1173 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . -1174 ¦ . ╎add 1, 1 . -1175 ¦ . ╎2 . -1176 ¦ . ╎─────────────────────────────────────────────────. -1177 ¦ . ╎ . -1178 ] -1179 # hit 'page-up' again -1180 assume-console [ -1181 ¦ press page-up -1182 ] -1183 run [ -1184 ¦ event-loop screen, console, env, resources +1168 run [ +1169 ¦ event-loop screen, console, env, resources +1170 ] +1171 # sandbox editor hidden; first sandbox displayed +1172 # cursor moves to first sandbox +1173 screen-should-contain [ +1174 ¦ . run (F4) . +1175 ¦ . ╎─────────────────────────────────────────────────. +1176 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +1177 ¦ . ╎add 1, 1 . +1178 ¦ . ╎2 . +1179 ¦ . ╎─────────────────────────────────────────────────. +1180 ¦ . ╎ . +1181 ] +1182 # hit 'page-up' again +1183 assume-console [ +1184 ¦ press page-up 1185 ] -1186 # back to displaying both sandboxes as well as editor -1187 screen-should-contain [ -1188 ¦ . run (F4) . -1189 ¦ . ╎ . -1190 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -1191 ¦ . ╎0 edit copy delete . -1192 ¦ . ╎add 1, 1 . -1193 ¦ . ╎2 . -1194 ¦ . ╎─────────────────────────────────────────────────. -1195 ¦ . ╎ . -1196 ] -1197 # hit 'page-down' -1198 assume-console [ -1199 ¦ press page-down -1200 ] -1201 run [ -1202 ¦ event-loop screen, console, env, resources +1186 run [ +1187 ¦ event-loop screen, console, env, resources +1188 ] +1189 # back to displaying both sandboxes as well as editor +1190 screen-should-contain [ +1191 ¦ . run (F4) . +1192 ¦ . ╎ . +1193 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1194 ¦ . ╎0 edit copy delete . +1195 ¦ . ╎add 1, 1 . +1196 ¦ . ╎2 . +1197 ¦ . ╎─────────────────────────────────────────────────. +1198 ¦ . ╎ . +1199 ] +1200 # hit 'page-down' +1201 assume-console [ +1202 ¦ press page-down 1203 ] -1204 # sandbox editor hidden; first sandbox displayed -1205 # cursor moves to first sandbox -1206 screen-should-contain [ -1207 ¦ . run (F4) . -1208 ¦ . ╎─────────────────────────────────────────────────. -1209 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . -1210 ¦ . ╎add 1, 1 . -1211 ¦ . ╎2 . -1212 ¦ . ╎─────────────────────────────────────────────────. -1213 ¦ . ╎ . -1214 ] -1215 ] +1204 run [ +1205 ¦ event-loop screen, console, env, resources +1206 ] +1207 # sandbox editor hidden; first sandbox displayed +1208 # cursor moves to first sandbox +1209 screen-should-contain [ +1210 ¦ . run (F4) . +1211 ¦ . ╎─────────────────────────────────────────────────. +1212 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +1213 ¦ . ╎add 1, 1 . +1214 ¦ . ╎2 . +1215 ¦ . ╎─────────────────────────────────────────────────. +1216 ¦ . ╎ . +1217 ] +1218 ] diff --git a/html/edit/006-sandbox-copy.mu.html b/html/edit/006-sandbox-copy.mu.html index 9cfcc416..1d88177a 100644 --- a/html/edit/006-sandbox-copy.mu.html +++ b/html/edit/006-sandbox-copy.mu.html @@ -210,7 +210,7 @@ if ('onhashchange' in window) { 148 assert first-sandbox, [!!] 149 sandbox-left-margin:num <- get *first-sandbox, left:offset 150 sandbox-right-margin:num <- get *first-sandbox, right:offset -151 _, _, copy-button-left:num, copy-button-right:num, _ <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin +151 _, _, copy-button-left:num, copy-button-right:num, _ <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin 152 copy-button-vertical-area?:bool <- within-range? click-column, copy-button-left, copy-button-right 153 return-unless copy-button-vertical-area?, 0/false 154 # finally, is sandbox editor empty? diff --git a/html/edit/007-sandbox-delete.mu.html b/html/edit/007-sandbox-delete.mu.html index 541a6c02..4518c456 100644 --- a/html/edit/007-sandbox-delete.mu.html +++ b/html/edit/007-sandbox-delete.mu.html @@ -154,7 +154,7 @@ if ('onhashchange' in window) { 92 assert first-sandbox, [!!] 93 sandbox-left-margin:num <- get *first-sandbox, left:offset 94 sandbox-right-margin:num <- get *first-sandbox, right:offset - 95 _, _, _, _, delete-button-left:num <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin + 95 _, _, _, _, delete-button-left:num <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin 96 result <- within-range? click-column, delete-button-left, sandbox-right-margin 97 ] 98 diff --git a/html/edit/008-sandbox-edit.mu.html b/html/edit/008-sandbox-edit.mu.html index 222335bb..f22c8d20 100644 --- a/html/edit/008-sandbox-edit.mu.html +++ b/html/edit/008-sandbox-edit.mu.html @@ -193,7 +193,7 @@ if ('onhashchange' in window) { 131 assert first-sandbox, [!!] 132 sandbox-left-margin:num <- get *first-sandbox, left:offset 133 sandbox-right-margin:num <- get *first-sandbox, right:offset -134 edit-button-left:num, edit-button-right:num, _ <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin +134 edit-button-left:num, edit-button-right:num, _ <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin 135 edit-button-vertical-area?:bool <- within-range? click-column, edit-button-left, edit-button-right 136 return-unless edit-button-vertical-area?, 0/false 137 # finally, is sandbox editor empty? diff --git a/html/edit/009-sandbox-test.mu.html b/html/edit/009-sandbox-test.mu.html index 92ec3f39..b3863306 100644 --- a/html/edit/009-sandbox-test.mu.html +++ b/html/edit/009-sandbox-test.mu.html @@ -155,7 +155,7 @@ if ('onhashchange' in window) { 92 ] 93 94 # include expected response when saving or restoring a sandbox - 95 before <end-save-sandbox> [ + 95 before <end-save-sandbox> [ 96 { 97 ¦ expected-response:text <- get *curr, expected-response:offset 98 ¦ break-unless expected-response @@ -164,7 +164,7 @@ if ('onhashchange' in window) { 101 } 102 ] 103 -104 before <end-restore-sandbox> [ +104 before <end-restore-sandbox> [ 105 { 106 ¦ filename <- append filename, [.out] 107 ¦ contents <- slurp resources, filename @@ -192,7 +192,7 @@ if ('onhashchange' in window) { 129 ¦ break-unless sandbox 130 ¦ # toggle its expected-response, and save session 131 ¦ sandbox <- toggle-expected-response sandbox -132 ¦ save-sandboxes env, resources +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 @@ -246,7 +246,7 @@ if ('onhashchange' in window) { 183 ] 184 185 # when rendering a sandbox, color it in red/green if expected response exists -186 after <render-sandbox-response> [ +186 after <render-sandbox-response> [ 187 { 188 ¦ break-unless sandbox-response 189 ¦ *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row @@ -255,17 +255,17 @@ if ('onhashchange' in window) { 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 +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 +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> [ +205 before <end-render-sandbox-reset-hidden> [ 206 *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 207 ] diff --git a/html/edit/010-sandbox-trace.mu.html b/html/edit/010-sandbox-trace.mu.html index 39714aa5..ca54d47b 100644 --- a/html/edit/010-sandbox-trace.mu.html +++ b/html/edit/010-sandbox-trace.mu.html @@ -304,13 +304,13 @@ if ('onhashchange' in window) { 241 ] 242 243 # when rendering a sandbox, dump its trace before response/warning if display-trace? property is set -244 after <render-sandbox-results> [ +244 after <render-sandbox-results> [ 245 { 246 ¦ display-trace?:bool <- get *sandbox, display-trace?:offset 247 ¦ break-unless display-trace? 248 ¦ sandbox-trace:text <- get *sandbox, trace:offset 249 ¦ break-unless sandbox-trace # nothing to print; move on -250 ¦ row, screen <- render-text screen, sandbox-trace, left, right, 245/grey, row +250 ¦ row, screen <- render-text screen, sandbox-trace, left, right, 245/grey, row 251 } 252 <render-sandbox-trace-done> 253 ] diff --git a/html/edit/011-errors.mu.html b/html/edit/011-errors.mu.html index b6e5e3f6..b7f2abd8 100644 --- a/html/edit/011-errors.mu.html +++ b/html/edit/011-errors.mu.html @@ -72,14 +72,14 @@ if ('onhashchange' in window) { 9 local-scope 10 load-ingredients 11 recipes:&:editor <- get *env, recipes:offset - 12 in:text <- editor-contents recipes + 12 in:text <- editor-contents recipes 13 resources <- dump resources, [lesson/recipes.mu], in 14 recipe-errors:text <- reload in 15 *env <- put *env, recipe-errors:offset, recipe-errors 16 # if recipe editor has errors, stop 17 { 18 ¦ break-unless recipe-errors - 19 ¦ update-status screen, [errors found ], 1/red + 19 ¦ update-status screen, [errors found ], 1/red 20 ¦ errors-found? <- copy 1/true 21 ¦ return 22 } @@ -91,7 +91,7 @@ if ('onhashchange' in window) { 28 recipe-errors:text <- get *env, recipe-errors:offset 29 { 30 ¦ break-unless recipe-errors - 31 ¦ update-status screen, [errors found ], 1/red + 31 ¦ update-status screen, [errors found ], 1/red 32 } 33 ] 34 @@ -99,7 +99,7 @@ if ('onhashchange' in window) { 36 { 37 ¦ recipe-errors:text <- get *env, recipe-errors:offset 38 ¦ break-unless recipe-errors - 39 ¦ row, screen <- render-text screen, recipe-errors, left, right, 1/red, row + 39 ¦ row, screen <- render-text screen, recipe-errors, left, right, 1/red, row 40 } 41 ] 42 @@ -132,7 +132,7 @@ if ('onhashchange' in window) { 69 ¦ break-if sandboxes-completed-successfully? 70 ¦ error-index-text:text <- to-text error-index 71 ¦ status:text <- interpolate [errors found (_) ], error-index-text - 72 ¦ update-status screen, status, 1/red + 72 ¦ update-status screen, status, 1/red 73 } 74 ] 75 @@ -171,7 +171,7 @@ if ('onhashchange' in window) { 108 ¦ sandbox-errors:text <- get *sandbox, errors:offset 109 ¦ break-unless sandbox-errors 110 ¦ *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 # no response -111 ¦ row, screen <- render-text screen, sandbox-errors, left, right, 1/red, row +111 ¦ row, screen <- render-text screen, sandbox-errors, left, right, 1/red, row 112 ¦ # don't try to print anything more for this sandbox 113 ¦ jump +render-sandbox-end 114 } diff --git a/sandbox/005-sandbox.mu b/sandbox/005-sandbox.mu index 89feed60..be3c1f5d 100644 --- a/sandbox/005-sandbox.mu +++ b/sandbox/005-sandbox.mu @@ -173,7 +173,10 @@ def run-sandboxes env:&:environment, resources:&:resources, screen:&:screen -> e loop } - $system [./snapshot_lesson] + { + break-if resources # ignore this in tests + $system [./snapshot_lesson] + } ] # load code from disk -- cgit 1.4.1-2-gfad0