From 16697d408cebb7e7060a76c4eb3c9a8fe1ae64e7 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 14 Mar 2017 08:06:07 -0700 Subject: 3793 Move 'render-code' to the layer where it's used. Thanks Caleb Couch for finding this bit of ugliness. --- html/edit/004-programming-environment.mu.html | 169 +-- html/edit/005-sandbox.mu.html | 1647 +++++++++++++------------ html/edit/009-sandbox-test.mu.html | 2 +- html/edit/011-errors.mu.html | 2 +- 4 files changed, 910 insertions(+), 910 deletions(-) (limited to 'html/edit') diff --git a/html/edit/004-programming-environment.mu.html b/html/edit/004-programming-environment.mu.html index 69694356..97d27afc 100644 --- a/html/edit/004-programming-environment.mu.html +++ b/html/edit/004-programming-environment.mu.html @@ -523,7 +523,7 @@ if ('onhashchange' in window) { 460 trace 11, [app], [render divider] 461 divider:num, _ <- divide-with-remainder width, 2 462 height:num <- screen-height screen -463 draw-vertical screen, divider, 1/top, height, 9482/vertical-dotted +463 draw-vertical screen, divider, 1/top, height, 9482/vertical-dotted 464 # 465 screen <- render-recipes screen, env, render-editor 466 screen <- render-sandbox-side screen, env, render-editor @@ -588,121 +588,58 @@ if ('onhashchange' in window) { 525 screen <- move-cursor screen, cursor-row, cursor-column 526 ] 527 -528 # like 'render' for texts, but with colorization for comments like in the editor -529 def render-code screen:&:screen, s:text, left:num, right:num, row:num -> row:num, screen:&:screen [ -530 local-scope -531 load-ingredients -532 return-unless s -533 color:num <- copy 7/white -534 column:num <- copy left -535 screen <- move-cursor screen, row, column -536 screen-height:num <- screen-height screen -537 i:num <- copy 0 -538 len:num <- length *s -539 { -540 ¦ +next-character -541 ¦ done?:bool <- greater-or-equal i, len -542 ¦ break-if done? -543 ¦ done? <- greater-or-equal row, screen-height -544 ¦ break-if done? -545 ¦ c:char <- index *s, i -546 ¦ <character-c-received> # only line different from render -547 ¦ { -548 ¦ ¦ # at right? wrap. -549 ¦ ¦ at-right?:bool <- equal column, right -550 ¦ ¦ break-unless at-right? -551 ¦ ¦ # print wrap icon -552 ¦ ¦ wrap-icon:char <- copy 8617/loop-back-to-left -553 ¦ ¦ print screen, wrap-icon, 245/grey -554 ¦ ¦ column <- copy left -555 ¦ ¦ row <- add row, 1 -556 ¦ ¦ screen <- move-cursor screen, row, column -557 ¦ ¦ loop +next-character # retry i -558 ¦ } -559 ¦ i <- add i, 1 -560 ¦ { -561 ¦ ¦ # newline? move to left rather than 0 -562 ¦ ¦ newline?:bool <- equal c, 10/newline -563 ¦ ¦ break-unless newline? -564 ¦ ¦ # clear rest of line in this window -565 ¦ ¦ { -566 ¦ ¦ ¦ done?:bool <- greater-than column, right -567 ¦ ¦ ¦ break-if done? -568 ¦ ¦ ¦ space:char <- copy 32/space -569 ¦ ¦ ¦ print screen, space -570 ¦ ¦ ¦ column <- add column, 1 -571 ¦ ¦ ¦ loop -572 ¦ ¦ } -573 ¦ ¦ row <- add row, 1 -574 ¦ ¦ column <- copy left -575 ¦ ¦ screen <- move-cursor screen, row, column -576 ¦ ¦ loop +next-character -577 ¦ } -578 ¦ print screen, c, color -579 ¦ column <- add column, 1 -580 ¦ loop -581 } -582 was-at-left?:bool <- equal column, left -583 clear-line-until screen, right -584 { -585 ¦ break-if was-at-left? -586 ¦ row <- add row, 1 -587 } -588 move-cursor screen, row, left -589 ] -590 -591 # ctrl-l - redraw screen (just in case it printed junk somehow) -592 -593 after <global-type> [ -594 { -595 ¦ redraw-screen?:bool <- equal c, 12/ctrl-l -596 ¦ break-unless redraw-screen? -597 ¦ screen <- render-all screen, env:&:environment, render -598 ¦ sync-screen screen -599 ¦ loop +next-event -600 } -601 ] -602 -603 # ctrl-n - switch focus -604 # todo: test this -605 -606 after <global-type> [ -607 { -608 ¦ switch-side?:bool <- equal c, 14/ctrl-n -609 ¦ break-unless switch-side? -610 ¦ sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset -611 ¦ sandbox-in-focus? <- not sandbox-in-focus? -612 ¦ *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus? -613 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env -614 ¦ loop +next-event -615 } -616 ] -617 -618 ## helpers -619 -620 def draw-vertical screen:&:screen, col:num, y:num, bottom:num -> screen:&:screen [ -621 local-scope -622 load-ingredients -623 style:char, style-found?:bool <- next-ingredient -624 { -625 ¦ break-if style-found? -626 ¦ style <- copy 9474/vertical -627 } -628 color:num, color-found?:bool <- next-ingredient -629 { -630 ¦ # default color to white -631 ¦ break-if color-found? -632 ¦ color <- copy 245/grey -633 } -634 { -635 ¦ continue?:bool <- lesser-than y, bottom -636 ¦ break-unless continue? -637 ¦ screen <- move-cursor screen, y, col -638 ¦ print screen, style, color -639 ¦ y <- add y, 1 -640 ¦ loop -641 } -642 ] +528 # ctrl-l - redraw screen (just in case it printed junk somehow) +529 +530 after <global-type> [ +531 { +532 ¦ redraw-screen?:bool <- equal c, 12/ctrl-l +533 ¦ break-unless redraw-screen? +534 ¦ screen <- render-all screen, env:&:environment, render +535 ¦ sync-screen screen +536 ¦ loop +next-event +537 } +538 ] +539 +540 # ctrl-n - switch focus +541 # todo: test this +542 +543 after <global-type> [ +544 { +545 ¦ switch-side?:bool <- equal c, 14/ctrl-n +546 ¦ break-unless switch-side? +547 ¦ sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset +548 ¦ sandbox-in-focus? <- not sandbox-in-focus? +549 ¦ *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus? +550 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +551 ¦ loop +next-event +552 } +553 ] +554 +555 ## helpers +556 +557 def draw-vertical screen:&:screen, col:num, y:num, bottom:num -> screen:&:screen [ +558 local-scope +559 load-ingredients +560 style:char, style-found?:bool <- next-ingredient +561 { +562 ¦ break-if style-found? +563 ¦ style <- copy 9474/vertical +564 } +565 color:num, color-found?:bool <- next-ingredient +566 { +567 ¦ # default color to white +568 ¦ break-if color-found? +569 ¦ color <- copy 245/grey +570 } +571 { +572 ¦ continue?:bool <- lesser-than y, bottom +573 ¦ break-unless continue? +574 ¦ screen <- move-cursor screen, y, col +575 ¦ print screen, style, color +576 ¦ y <- add y, 1 +577 ¦ loop +578 } +579 ] diff --git a/html/edit/005-sandbox.mu.html b/html/edit/005-sandbox.mu.html index ace1471a..0d1f536a 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 @@ -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 @@ -257,7 +257,7 @@ if ('onhashchange' in window) { 194 local-scope 195 load-ingredients 196 recipes:&:editor <- get *env, recipes:offset - 197 in:text <- editor-contents recipes + 197 in:text <- editor-contents recipes 198 resources <- dump resources, [lesson/recipes.mu], in 199 reload in 200 errors-found? <- copy 0/false @@ -344,7 +344,7 @@ if ('onhashchange' in window) { 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 + 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 @@ -353,7 +353,7 @@ if ('onhashchange' in window) { 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 + 293 ¦ ¦ row, screen <- render-screen screen, sandbox-screen, left, right, row 294 ¦ } 295 ¦ { 296 ¦ ¦ break-unless empty-screen? @@ -481,804 +481,867 @@ if ('onhashchange' in window) { 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 [ + 421 # like 'render' for texts, but with colorization for comments like in the editor + 422 def render-code screen:&:screen, s:text, left:num, right:num, row:num -> row:num, screen:&:screen [ 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 + 425 return-unless s + 426 color:num <- copy 7/white + 427 column:num <- copy left + 428 screen <- move-cursor screen, row, column + 429 screen-height:num <- screen-height screen + 430 i:num <- copy 0 + 431 len:num <- length *s + 432 { + 433 ¦ +next-character + 434 ¦ done?:bool <- greater-or-equal i, len + 435 ¦ break-if done? + 436 ¦ done? <- greater-or-equal row, screen-height + 437 ¦ break-if done? + 438 ¦ c:char <- index *s, i + 439 ¦ <character-c-received> # only line different from render + 440 ¦ { + 441 ¦ ¦ # at right? wrap. + 442 ¦ ¦ at-right?:bool <- equal column, right + 443 ¦ ¦ break-unless at-right? + 444 ¦ ¦ # print wrap icon + 445 ¦ ¦ wrap-icon:char <- copy 8617/loop-back-to-left + 446 ¦ ¦ print screen, wrap-icon, 245/grey + 447 ¦ ¦ column <- copy left + 448 ¦ ¦ row <- add row, 1 + 449 ¦ ¦ screen <- move-cursor screen, row, column + 450 ¦ ¦ loop +next-character # retry i + 451 ¦ } + 452 ¦ i <- add i, 1 + 453 ¦ { + 454 ¦ ¦ # newline? move to left rather than 0 + 455 ¦ ¦ newline?:bool <- equal c, 10/newline + 456 ¦ ¦ break-unless newline? + 457 ¦ ¦ # clear rest of line in this window + 458 ¦ ¦ { + 459 ¦ ¦ ¦ done?:bool <- greater-than column, right + 460 ¦ ¦ ¦ break-if done? + 461 ¦ ¦ ¦ space:char <- copy 32/space + 462 ¦ ¦ ¦ print screen, space + 463 ¦ ¦ ¦ column <- add column, 1 + 464 ¦ ¦ ¦ loop + 465 ¦ ¦ } + 466 ¦ ¦ row <- add row, 1 + 467 ¦ ¦ column <- copy left + 468 ¦ ¦ screen <- move-cursor screen, row, column + 469 ¦ ¦ loop +next-character + 470 ¦ } + 471 ¦ print screen, c, color + 472 ¦ column <- add column, 1 + 473 ¦ loop + 474 } + 475 was-at-left?:bool <- equal column, left + 476 clear-line-until screen, right + 477 { + 478 ¦ break-if was-at-left? + 479 ¦ row <- add row, 1 + 480 } + 481 move-cursor screen, row, left + 482 ] + 483 + 484 # assumes programming environment has no sandboxes; restores them from previous session + 485 def restore-sandboxes env:&:environment, resources:&:resources -> env:&:environment [ + 486 local-scope + 487 load-ingredients + 488 # read all scenarios, pushing them to end of a list of scenarios + 489 idx:num <- copy 0 + 490 curr:&:sandbox <- copy 0 + 491 prev:&:sandbox <- copy 0 + 492 { + 493 ¦ filename:text <- append [lesson/], idx + 494 ¦ contents:text <- slurp resources, filename + 495 ¦ break-unless contents # stop at first error; assuming file didn't exist + 496 ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ # todo: handle empty sandbox + 497 ¦ # create new sandbox for file + 498 ¦ curr <- new sandbox:type + 499 ¦ *curr <- put *curr, data:offset, contents + 500 ¦ <end-restore-sandbox> + 501 ¦ { + 502 ¦ ¦ break-if idx + 503 ¦ ¦ *env <- put *env, sandbox:offset, curr 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 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 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 ] - 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] + 505 ¦ { + 506 ¦ ¦ break-unless idx + 507 ¦ ¦ *prev <- put *prev, next-sandbox:offset, curr + 508 ¦ } + 509 ¦ idx <- add idx, 1 + 510 ¦ prev <- copy curr + 511 ¦ loop + 512 } + 513 # update sandbox count + 514 *env <- put *env, number-of-sandboxes:offset, idx + 515 ] + 516 + 517 # print the fake sandbox screen to 'screen' with appropriate delimiters + 518 # leave cursor at start of next line + 519 def render-screen screen:&:screen, sandbox-screen:&:screen, left:num, right:num, row:num -> row:num, screen:&:screen [ + 520 local-scope + 521 load-ingredients + 522 return-unless sandbox-screen + 523 # print 'screen:' + 524 row <- render-text screen, [screen:], left, right, 245/grey, row + 525 screen <- move-cursor screen, row, left + 526 # start printing sandbox-screen + 527 column:num <- copy left + 528 s-width:num <- screen-width sandbox-screen + 529 s-height:num <- screen-height sandbox-screen + 530 buf:&:@:screen-cell <- get *sandbox-screen, data:offset + 531 stop-printing:num <- add left, s-width, 3 + 532 max-column:num <- min stop-printing, right + 533 i:num <- copy 0 + 534 len:num <- length *buf + 535 screen-height:num <- screen-height screen + 536 { + 537 ¦ done?:bool <- greater-or-equal i, len + 538 ¦ break-if done? + 539 ¦ done? <- greater-or-equal row, screen-height + 540 ¦ break-if done? + 541 ¦ column <- copy left + 542 ¦ screen <- move-cursor screen, row, column + 543 ¦ # initial leader for each row: two spaces and a '.' + 544 ¦ space:char <- copy 32/space + 545 ¦ print screen, space, 245/grey + 546 ¦ print screen, space, 245/grey + 547 ¦ full-stop:char <- copy 46/period + 548 ¦ print screen, full-stop, 245/grey + 549 ¦ column <- add left, 3 + 550 ¦ { + 551 ¦ ¦ # print row + 552 ¦ ¦ row-done?:bool <- greater-or-equal column, max-column + 553 ¦ ¦ break-if row-done? + 554 ¦ ¦ curr:screen-cell <- index *buf, i + 555 ¦ ¦ c:char <- get curr, contents:offset + 556 ¦ ¦ color:num <- get curr, color:offset + 557 ¦ ¦ { + 558 ¦ ¦ ¦ # damp whites down to grey + 559 ¦ ¦ ¦ white?:bool <- equal color, 7/white + 560 ¦ ¦ ¦ break-unless white? + 561 ¦ ¦ ¦ color <- copy 245/grey + 562 ¦ ¦ } + 563 ¦ ¦ print screen, c, color + 564 ¦ ¦ column <- add column, 1 + 565 ¦ ¦ i <- add i, 1 + 566 ¦ ¦ loop + 567 ¦ } + 568 ¦ # print final '.' + 569 ¦ print screen, full-stop, 245/grey + 570 ¦ column <- add column, 1 + 571 ¦ { + 572 ¦ ¦ # clear rest of current line + 573 ¦ ¦ line-done?:bool <- greater-than column, right + 574 ¦ ¦ break-if line-done? + 575 ¦ ¦ print screen, space + 576 ¦ ¦ column <- add column, 1 + 577 ¦ ¦ loop + 578 ¦ } + 579 ¦ row <- add row, 1 + 580 ¦ loop + 581 } + 582 ] + 583 + 584 scenario run-updates-results [ + 585 local-scope + 586 trace-until 100/app # trace too long + 587 assume-screen 100/width, 12/height + 588 # define a recipe (no indent for the 'add' line below so column numbers are more obvious) + 589 assume-resources [ + 590 ¦ [lesson/recipes.mu] <- [ + 591 ¦ ¦ || + 592 ¦ ¦ |recipe foo [| + 593 ¦ ¦ | local-scope| + 594 ¦ ¦ | z:num <- add 2, 2| + 595 ¦ ¦ | reply z| + 596 ¦ ¦ |]| + 597 ¦ ] + 598 ] + 599 # sandbox editor contains an instruction without storing outputs + 600 env:&:environment <- new-programming-environment resources, screen, [foo] # contents of sandbox editor + 601 # run the code in the editors + 602 assume-console [ + 603 ¦ press F4 + 604 ] + 605 event-loop screen, console, env, resources + 606 screen-should-contain [ + 607 ¦ . run (F4) . + 608 ¦ . ╎ . + 609 ¦ .recipe foo [ ╎─────────────────────────────────────────────────. + 610 ¦ . local-scope ╎0 edit copy delete . + 611 ¦ . z:num <- add 2, 2 ╎foo . + 612 ¦ . reply z ╎4 . + 613 ¦ .] ╎─────────────────────────────────────────────────. + 614 ¦ . ╎ . + 615 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . + 616 ¦ . ╎ . + 617 ] + 618 # make a change (incrementing one of the args to 'add'), then rerun + 619 assume-console [ + 620 ¦ left-click 4, 28 # one past the value of the second arg + 621 ¦ press backspace + 622 ¦ type [3] + 623 ¦ press F4 + 624 ] + 625 run [ + 626 ¦ event-loop screen, console, env, resources + 627 ] + 628 # check that screen updates the result on the right + 629 screen-should-contain [ + 630 ¦ . run (F4) . + 631 ¦ . ╎ . + 632 ¦ .recipe foo [ ╎─────────────────────────────────────────────────. + 633 ¦ . local-scope ╎0 edit copy delete . + 634 ¦ . z:num <- add 2, 3 ╎foo . + 635 ¦ . reply z ╎5 . + 636 ¦ .] ╎─────────────────────────────────────────────────. + 637 ¦ . ╎ . + 638 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . + 639 ¦ . ╎ . 640 ] - 641 run [ - 642 ¦ editor-event-loop screen, console, e - 643 ¦ s:text <- editor-contents e - 644 ¦ 1:@:char/raw <- copy *s - 645 ] - 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 [ + 641 ] + 642 + 643 scenario run-instruction-manages-screen-per-sandbox [ + 644 local-scope + 645 trace-until 100/app # trace too long + 646 assume-screen 100/width, 20/height + 647 # empty recipes + 648 assume-resources [ + 649 ] + 650 # sandbox editor contains an instruction + 651 env:&:environment <- new-programming-environment resources, screen, [print screen, 4] # contents of sandbox editor + 652 # run the code in the editor + 653 assume-console [ + 654 ¦ press F4 + 655 ] + 656 run [ + 657 ¦ event-loop screen, console, env, 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 ] - 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 ] - 700 ] - 701 - 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 ] - 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 run [ -1044 ¦ event-loop screen, console, env, resources + 659 # check that it prints a little toy screen + 660 screen-should-contain [ + 661 ¦ . run (F4) . + 662 ¦ . ╎ . + 663 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. + 664 ¦ . ╎0 edit copy delete . + 665 ¦ . ╎print screen, 4 . + 666 ¦ . ╎screen: . + 667 ¦ . ╎ .4 . . + 668 ¦ . ╎ . . . + 669 ¦ . ╎ . . . + 670 ¦ . ╎ . . . + 671 ¦ . ╎ . . . + 672 ¦ . ╎─────────────────────────────────────────────────. + 673 ¦ . ╎ . + 674 ] + 675 ] + 676 + 677 def editor-contents editor:&:editor -> result:text [ + 678 local-scope + 679 load-ingredients + 680 buf:&:buffer <- new-buffer 80 + 681 curr:&:duplex-list:char <- get *editor, data:offset + 682 # skip § sentinel + 683 assert curr, [editor without data is illegal; must have at least a sentinel] + 684 curr <- next curr + 685 return-unless curr, 0 + 686 { + 687 ¦ break-unless curr + 688 ¦ c:char <- get *curr, value:offset + 689 ¦ buf <- append buf, c + 690 ¦ curr <- next curr + 691 ¦ loop + 692 } + 693 result <- buffer-to-array buf + 694 ] + 695 + 696 scenario editor-provides-edited-contents [ + 697 local-scope + 698 assume-screen 10/width, 5/height + 699 e:&:editor <- new-editor [abc], 0/left, 10/right + 700 assume-console [ + 701 ¦ left-click 1, 2 + 702 ¦ type [def] + 703 ] + 704 run [ + 705 ¦ editor-event-loop screen, console, e + 706 ¦ s:text <- editor-contents e + 707 ¦ 1:@:char/raw <- copy *s + 708 ] + 709 memory-should-contain [ + 710 ¦ 1:array:character <- [abdefc] + 711 ] + 712 ] + 713 + 714 # keep the bottom of recipes from scrolling off the screen + 715 + 716 scenario scrolling-down-past-bottom-of-recipe-editor [ + 717 local-scope + 718 trace-until 100/app + 719 assume-screen 100/width, 10/height + 720 assume-resources [ + 721 ] + 722 env:&:environment <- new-programming-environment resources, screen, [] + 723 render-all screen, env, render + 724 assume-console [ + 725 ¦ press enter + 726 ¦ press down-arrow + 727 ] + 728 event-loop screen, console, env, resources + 729 # no scroll + 730 screen-should-contain [ + 731 ¦ . run (F4) . + 732 ¦ . ╎ . + 733 ¦ . ╎─────────────────────────────────────────────────. + 734 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . + 735 ¦ . ╎ . + 736 ] + 737 ] + 738 + 739 scenario cursor-down-in-recipe-editor [ + 740 local-scope + 741 trace-until 100/app + 742 assume-screen 100/width, 10/height + 743 assume-resources [ + 744 ] + 745 env:&:environment <- new-programming-environment resources, screen, [] + 746 render-all screen, env, render + 747 assume-console [ + 748 ¦ press enter + 749 ¦ press up-arrow + 750 ¦ press down-arrow # while cursor isn't at bottom + 751 ] + 752 event-loop screen, console, env, resources + 753 cursor:char <- copy 9251/␣ + 754 print screen, cursor + 755 # cursor moves back to bottom + 756 screen-should-contain [ + 757 ¦ . run (F4) . + 758 ¦ . ╎ . + 759 ¦ .␣ ╎─────────────────────────────────────────────────. + 760 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . + 761 ¦ . ╎ . + 762 ] + 763 ] + 764 + 765 # we'll not use the recipe-editor's 'bottom' element directly, because later + 766 # layers will add other stuff to the left side below the editor (error messages) + 767 + 768 container environment [ + 769 recipe-bottom:num + 770 ] + 771 + 772 after <render-recipe-components-end> [ + 773 *env <- put *env, recipe-bottom:offset, row + 774 ] + 775 + 776 after <global-keypress> [ + 777 { + 778 ¦ break-if sandbox-in-focus? + 779 ¦ down-arrow?:bool <- equal k, 65516/down-arrow + 780 ¦ break-unless down-arrow? + 781 ¦ recipe-editor:&:editor <- get *env, recipes:offset + 782 ¦ recipe-cursor-row:num <- get *recipe-editor, cursor-row:offset + 783 ¦ recipe-editor-bottom:num <- get *recipe-editor, bottom:offset + 784 ¦ at-bottom-of-editor?:bool <- greater-or-equal recipe-cursor-row, recipe-editor-bottom + 785 ¦ break-unless at-bottom-of-editor? + 786 ¦ more-to-scroll?:bool <- more-to-scroll? env, screen + 787 ¦ break-if more-to-scroll? + 788 ¦ loop +next-event + 789 } + 790 { + 791 ¦ break-if sandbox-in-focus? + 792 ¦ page-down?:bool <- equal k, 65518/page-down + 793 ¦ break-unless page-down? + 794 ¦ more-to-scroll?:bool <- more-to-scroll? env, screen + 795 ¦ break-if more-to-scroll? + 796 ¦ loop +next-event + 797 } + 798 ] + 799 + 800 after <global-type> [ + 801 { + 802 ¦ break-if sandbox-in-focus? + 803 ¦ page-down?:bool <- equal k, 6/ctrl-f + 804 ¦ break-unless page-down? + 805 ¦ more-to-scroll?:bool <- more-to-scroll? env, screen + 806 ¦ break-if more-to-scroll? + 807 ¦ loop +next-event + 808 } + 809 ] + 810 + 811 def more-to-scroll? env:&:environment, screen:&:screen -> result:bool [ + 812 local-scope + 813 load-ingredients + 814 recipe-bottom:num <- get *env, recipe-bottom:offset + 815 height:num <- screen-height screen + 816 result <- greater-or-equal recipe-bottom, height + 817 ] + 818 + 819 scenario scrolling-down-past-bottom-of-recipe-editor-2 [ + 820 local-scope + 821 trace-until 100/app + 822 assume-screen 100/width, 10/height + 823 assume-resources [ + 824 ] + 825 env:&:environment <- new-programming-environment resources, screen, [] + 826 render-all screen, env, render + 827 assume-console [ + 828 ¦ # add a line + 829 ¦ press enter + 830 ¦ # cursor back to top line + 831 ¦ press up-arrow + 832 ¦ # try to scroll + 833 ¦ press page-down # or ctrl-f + 834 ] + 835 event-loop screen, console, env, resources + 836 # no scroll, and cursor remains at top line + 837 screen-should-contain [ + 838 ¦ . run (F4) . + 839 ¦ . ╎ . + 840 ¦ . ╎─────────────────────────────────────────────────. + 841 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . + 842 ¦ . ╎ . + 843 ] + 844 ] + 845 + 846 scenario scrolling-down-past-bottom-of-recipe-editor-3 [ + 847 local-scope + 848 trace-until 100/app + 849 assume-screen 100/width, 10/height + 850 assume-resources [ + 851 ] + 852 env:&:environment <- new-programming-environment resources, screen, [ab + 853 cd] + 854 render-all screen, env, render + 855 assume-console [ + 856 ¦ # add a line + 857 ¦ press enter + 858 ¦ # switch to sandbox + 859 ¦ press ctrl-n + 860 ¦ # move cursor + 861 ¦ press down-arrow + 862 ] + 863 event-loop screen, console, env, resources + 864 cursor:char <- copy 9251/␣ + 865 print screen, cursor + 866 # no scroll on recipe side, cursor moves on sandbox side + 867 screen-should-contain [ + 868 ¦ . run (F4) . + 869 ¦ . ╎ab . + 870 ¦ . ╎␣d . + 871 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. + 872 ¦ . ╎ . + 873 ] + 874 ] + 875 + 876 # scrolling through sandboxes + 877 + 878 scenario scrolling-down-past-bottom-of-sandbox-editor [ + 879 local-scope + 880 trace-until 100/app # trace too long + 881 assume-screen 100/width, 10/height + 882 # initialize + 883 assume-resources [ + 884 ] + 885 env:&:environment <- new-programming-environment resources, screen, [add 2, 2] + 886 render-all screen, env, render + 887 assume-console [ + 888 ¦ # create a sandbox + 889 ¦ press F4 + 890 ] + 891 event-loop screen, console, env, resources + 892 screen-should-contain [ + 893 ¦ . run (F4) . + 894 ¦ . ╎ . + 895 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. + 896 ¦ . ╎0 edit copy delete . + 897 ¦ . ╎add 2, 2 . + 898 ] + 899 # switch to sandbox window and hit 'page-down' + 900 assume-console [ + 901 ¦ press ctrl-n + 902 ¦ press page-down + 903 ] + 904 run [ + 905 ¦ event-loop screen, console, env, resources + 906 ¦ cursor:char <- copy 9251/␣ + 907 ¦ print screen, cursor + 908 ] + 909 # sandbox editor hidden; first sandbox displayed + 910 # cursor moves to first sandbox + 911 screen-should-contain [ + 912 ¦ . run (F4) . + 913 ¦ . ╎─────────────────────────────────────────────────. + 914 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎␣ edit copy delete . + 915 ¦ . ╎add 2, 2 . + 916 ¦ . ╎4 . + 917 ] + 918 # hit 'page-up' + 919 assume-console [ + 920 ¦ press page-up + 921 ] + 922 run [ + 923 ¦ event-loop screen, console, env, resources + 924 ¦ cursor:char <- copy 9251/␣ + 925 ¦ print screen, cursor + 926 ] + 927 # sandbox editor displays again, cursor is in editor + 928 screen-should-contain [ + 929 ¦ . run (F4) . + 930 ¦ . ╎␣ . + 931 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. + 932 ¦ . ╎0 edit copy delete . + 933 ¦ . ╎add 2, 2 . + 934 ] + 935 ] + 936 + 937 # page-down on sandbox side updates render-from to scroll sandboxes + 938 after <global-keypress> [ + 939 { + 940 ¦ break-unless sandbox-in-focus? + 941 ¦ page-down?:bool <- equal k, 65518/page-down + 942 ¦ break-unless page-down? + 943 ¦ sandbox:&:sandbox <- get *env, sandbox:offset + 944 ¦ break-unless sandbox + 945 ¦ # slide down if possible + 946 ¦ { + 947 ¦ ¦ render-from:num <- get *env, render-from:offset + 948 ¦ ¦ number-of-sandboxes:num <- get *env, number-of-sandboxes:offset + 949 ¦ ¦ max:num <- subtract number-of-sandboxes, 1 + 950 ¦ ¦ at-end?:bool <- greater-or-equal render-from, max + 951 ¦ ¦ jump-if at-end?, +finish-event # render nothing + 952 ¦ ¦ render-from <- add render-from, 1 + 953 ¦ ¦ *env <- put *env, render-from:offset, render-from + 954 ¦ } + 955 ¦ hide-screen screen + 956 ¦ screen <- render-sandbox-side screen, env, render + 957 ¦ show-screen screen + 958 ¦ jump +finish-event + 959 } + 960 ] + 961 + 962 # update-cursor takes render-from into account + 963 after <update-cursor-special-cases> [ + 964 { + 965 ¦ break-unless sandbox-in-focus? + 966 ¦ render-from:num <- get *env, render-from:offset + 967 ¦ scrolling?:bool <- greater-or-equal render-from, 0 + 968 ¦ break-unless scrolling? + 969 ¦ cursor-column:num <- get *current-sandbox, left:offset + 970 ¦ screen <- move-cursor screen, 2/row, cursor-column # highlighted sandbox will always start at row 2 + 971 ¦ return + 972 } + 973 ] + 974 + 975 # 'page-up' on sandbox side is like 'page-down': updates render-from when necessary + 976 after <global-keypress> [ + 977 { + 978 ¦ break-unless sandbox-in-focus? + 979 ¦ page-up?:bool <- equal k, 65519/page-up + 980 ¦ break-unless page-up? + 981 ¦ render-from:num <- get *env, render-from:offset + 982 ¦ at-beginning?:bool <- equal render-from, -1 + 983 ¦ break-if at-beginning? + 984 ¦ render-from <- subtract render-from, 1 + 985 ¦ *env <- put *env, render-from:offset, render-from + 986 ¦ hide-screen screen + 987 ¦ screen <- render-sandbox-side screen, env, render + 988 ¦ show-screen screen + 989 ¦ jump +finish-event + 990 } + 991 ] + 992 + 993 # sandbox belonging to 'env' whose next-sandbox is 'in' + 994 # return 0 if there's no such sandbox, either because 'in' doesn't exist in 'env', or because it's the first sandbox + 995 def previous-sandbox env:&:environment, in:&:sandbox -> out:&:sandbox [ + 996 local-scope + 997 load-ingredients + 998 curr:&:sandbox <- get *env, sandbox:offset + 999 return-unless curr, 0/nil +1000 next:&:sandbox <- get *curr, next-sandbox:offset +1001 { +1002 ¦ return-unless next, 0/nil +1003 ¦ found?:bool <- equal next, in +1004 ¦ break-if found? +1005 ¦ curr <- copy next +1006 ¦ next <- get *curr, next-sandbox:offset +1007 ¦ loop +1008 } +1009 return curr +1010 ] +1011 +1012 scenario scrolling-down-past-bottom-on-recipe-side [ +1013 local-scope +1014 trace-until 100/app # trace too long +1015 assume-screen 100/width, 10/height +1016 # initialize sandbox side and create a sandbox +1017 assume-resources [ +1018 ¦ [lesson/recipes.mu] <- [ +1019 ¦ ¦ || # file containing just a newline +1020 ¦ ] +1021 ] +1022 # create a sandbox +1023 env:&:environment <- new-programming-environment resources, screen, [add 2, 2] +1024 render-all screen, env, render +1025 assume-console [ +1026 ¦ press F4 +1027 ] +1028 event-loop screen, console, env, resources +1029 # hit 'down' in recipe editor +1030 assume-console [ +1031 ¦ press page-down +1032 ] +1033 run [ +1034 ¦ event-loop screen, console, env, resources +1035 ¦ cursor:char <- copy 9251/␣ +1036 ¦ print screen, cursor +1037 ] +1038 # cursor doesn't move when the end is already on-screen +1039 screen-should-contain [ +1040 ¦ . run (F4) . +1041 ¦ .␣ ╎ . +1042 ¦ . ╎─────────────────────────────────────────────────. +1043 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +1044 ¦ . ╎add 2, 2 . 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 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 run [ -1078 ¦ event-loop screen, console, env, resources +1046 ] +1047 +1048 scenario scrolling-through-multiple-sandboxes [ +1049 local-scope +1050 trace-until 100/app # trace too long +1051 assume-screen 100/width, 10/height +1052 # initialize environment +1053 assume-resources [ +1054 ] +1055 env:&:environment <- new-programming-environment resources, screen, [] +1056 render-all screen, env, render +1057 # create 2 sandboxes +1058 assume-console [ +1059 ¦ press ctrl-n +1060 ¦ type [add 2, 2] +1061 ¦ press F4 +1062 ¦ type [add 1, 1] +1063 ¦ press F4 +1064 ] +1065 event-loop screen, console, env, resources +1066 cursor:char <- copy 9251/␣ +1067 print screen, cursor +1068 screen-should-contain [ +1069 ¦ . run (F4) . +1070 ¦ . ╎␣ . +1071 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1072 ¦ . ╎0 edit copy delete . +1073 ¦ . ╎add 1, 1 . +1074 ¦ . ╎2 . +1075 ¦ . ╎─────────────────────────────────────────────────. +1076 ¦ . ╎1 edit copy delete . +1077 ¦ . ╎add 2, 2 . +1078 ¦ . ╎4 . 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 +1080 # hit 'page-down' +1081 assume-console [ +1082 ¦ press page-down +1083 ] +1084 run [ +1085 ¦ event-loop screen, console, env, resources +1086 ¦ cursor:char <- copy 9251/␣ +1087 ¦ print screen, cursor +1088 ] +1089 # sandbox editor hidden; first sandbox displayed +1090 # cursor moves to first sandbox +1091 screen-should-contain [ +1092 ¦ . run (F4) . +1093 ¦ . ╎─────────────────────────────────────────────────. +1094 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎␣ edit copy delete . +1095 ¦ . ╎add 1, 1 . +1096 ¦ . ╎2 . +1097 ¦ . ╎─────────────────────────────────────────────────. +1098 ¦ . ╎1 edit copy delete . +1099 ¦ . ╎add 2, 2 . +1100 ¦ . ╎4 . +1101 ] +1102 # hit 'page-down' again +1103 assume-console [ +1104 ¦ press page-down +1105 ] +1106 run [ +1107 ¦ event-loop screen, console, env, resources +1108 ] +1109 # just second sandbox displayed +1110 screen-should-contain [ +1111 ¦ . run (F4) . +1112 ¦ . ╎─────────────────────────────────────────────────. +1113 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . +1114 ¦ . ╎add 2, 2 . +1115 ¦ . ╎4 . +1116 ¦ . ╎─────────────────────────────────────────────────. +1117 ¦ . ╎ . +1118 ] +1119 # hit 'page-down' again +1120 assume-console [ +1121 ¦ press page-down 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 . +1123 run [ +1124 ¦ event-loop screen, console, env, resources +1125 ] +1126 # no change +1127 screen-should-contain [ +1128 ¦ . run (F4) . +1129 ¦ . ╎─────────────────────────────────────────────────. +1130 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . +1131 ¦ . ╎add 2, 2 . +1132 ¦ . ╎4 . +1133 ¦ . ╎─────────────────────────────────────────────────. +1134 ¦ . ╎ . 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 ¦ . ╎ . +1136 # hit 'page-up' +1137 assume-console [ +1138 ¦ press page-up +1139 ] +1140 run [ +1141 ¦ event-loop screen, console, env, resources +1142 ] +1143 # back to displaying both sandboxes without editor +1144 screen-should-contain [ +1145 ¦ . run (F4) . +1146 ¦ . ╎─────────────────────────────────────────────────. +1147 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +1148 ¦ . ╎add 1, 1 . +1149 ¦ . ╎2 . +1150 ¦ . ╎─────────────────────────────────────────────────. +1151 ¦ . ╎1 edit copy delete . +1152 ¦ . ╎add 2, 2 . +1153 ¦ . ╎4 . +1154 ] +1155 # hit 'page-up' again +1156 assume-console [ +1157 ¦ press page-up +1158 ] +1159 run [ +1160 ¦ event-loop screen, console, env, resources +1161 ¦ cursor:char <- copy 9251/␣ +1162 ¦ print screen, cursor 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 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 +1164 # back to displaying both sandboxes as well as editor +1165 screen-should-contain [ +1166 ¦ . run (F4) . +1167 ¦ . ╎␣ . +1168 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1169 ¦ . ╎0 edit copy delete . +1170 ¦ . ╎add 1, 1 . +1171 ¦ . ╎2 . +1172 ¦ . ╎─────────────────────────────────────────────────. +1173 ¦ . ╎1 edit copy delete . +1174 ¦ . ╎add 2, 2 . +1175 ¦ . ╎4 . +1176 ] +1177 # hit 'page-up' again +1178 assume-console [ +1179 ¦ press page-up +1180 ] +1181 run [ +1182 ¦ event-loop screen, console, env, resources +1183 ¦ cursor:char <- copy 9251/␣ +1184 ¦ print screen, cursor 1185 ] -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 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 ] +1186 # no change +1187 screen-should-contain [ +1188 ¦ . run (F4) . +1189 ¦ . ╎␣ . +1190 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1191 ¦ . ╎0 edit copy delete . +1192 ¦ . ╎add 1, 1 . +1193 ¦ . ╎2 . +1194 ¦ . ╎─────────────────────────────────────────────────. +1195 ¦ . ╎1 edit copy delete . +1196 ¦ . ╎add 2, 2 . +1197 ¦ . ╎4 . +1198 ] +1199 ] +1200 +1201 scenario scrolling-manages-sandbox-index-correctly [ +1202 local-scope +1203 trace-until 100/app # trace too long +1204 assume-screen 100/width, 10/height +1205 # initialize environment +1206 assume-resources [ +1207 ] +1208 env:&:environment <- new-programming-environment resources, screen, [] +1209 render-all screen, env, render +1210 # create a sandbox +1211 assume-console [ +1212 ¦ press ctrl-n +1213 ¦ type [add 1, 1] +1214 ¦ press F4 +1215 ] +1216 event-loop screen, console, env, resources +1217 screen-should-contain [ +1218 ¦ . run (F4) . +1219 ¦ . ╎ . +1220 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1221 ¦ . ╎0 edit copy delete . +1222 ¦ . ╎add 1, 1 . +1223 ¦ . ╎2 . +1224 ¦ . ╎─────────────────────────────────────────────────. +1225 ¦ . ╎ . +1226 ] +1227 # hit 'page-down' and 'page-up' a couple of times. sandbox index should be stable +1228 assume-console [ +1229 ¦ press page-down +1230 ] +1231 run [ +1232 ¦ event-loop screen, console, env, resources +1233 ] +1234 # sandbox editor hidden; first sandbox displayed +1235 # cursor moves to first sandbox +1236 screen-should-contain [ +1237 ¦ . run (F4) . +1238 ¦ . ╎─────────────────────────────────────────────────. +1239 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +1240 ¦ . ╎add 1, 1 . +1241 ¦ . ╎2 . +1242 ¦ . ╎─────────────────────────────────────────────────. +1243 ¦ . ╎ . +1244 ] +1245 # hit 'page-up' again +1246 assume-console [ +1247 ¦ press page-up +1248 ] +1249 run [ +1250 ¦ event-loop screen, console, env, resources +1251 ] +1252 # back to displaying both sandboxes as well as editor +1253 screen-should-contain [ +1254 ¦ . run (F4) . +1255 ¦ . ╎ . +1256 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1257 ¦ . ╎0 edit copy delete . +1258 ¦ . ╎add 1, 1 . +1259 ¦ . ╎2 . +1260 ¦ . ╎─────────────────────────────────────────────────. +1261 ¦ . ╎ . +1262 ] +1263 # hit 'page-down' +1264 assume-console [ +1265 ¦ press page-down +1266 ] +1267 run [ +1268 ¦ event-loop screen, console, env, resources +1269 ] +1270 # sandbox editor hidden; first sandbox displayed +1271 # cursor moves to first sandbox +1272 screen-should-contain [ +1273 ¦ . run (F4) . +1274 ¦ . ╎─────────────────────────────────────────────────. +1275 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +1276 ¦ . ╎add 1, 1 . +1277 ¦ . ╎2 . +1278 ¦ . ╎─────────────────────────────────────────────────. +1279 ¦ . ╎ . +1280 ] +1281 ] diff --git a/html/edit/009-sandbox-test.mu.html b/html/edit/009-sandbox-test.mu.html index b3863306..0a7ba0d1 100644 --- a/html/edit/009-sandbox-test.mu.html +++ b/html/edit/009-sandbox-test.mu.html @@ -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 diff --git a/html/edit/011-errors.mu.html b/html/edit/011-errors.mu.html index b7f2abd8..ece25b72 100644 --- a/html/edit/011-errors.mu.html +++ b/html/edit/011-errors.mu.html @@ -72,7 +72,7 @@ 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 -- cgit 1.4.1-2-gfad0