From 94ffc3776c8037416e4834eb5b94644587c18e10 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 18 Feb 2018 15:55:42 -0800 Subject: 4209 --- html/edit/004-programming-environment.mu.html | 230 +++++++++++++------------- 1 file changed, 113 insertions(+), 117 deletions(-) (limited to 'html/edit/004-programming-environment.mu.html') diff --git a/html/edit/004-programming-environment.mu.html b/html/edit/004-programming-environment.mu.html index bb5d020b..5aa8c1d3 100644 --- a/html/edit/004-programming-environment.mu.html +++ b/html/edit/004-programming-environment.mu.html @@ -145,7 +145,7 @@ if ('onhashchange' in window) { 83 _ <- move-cursor recipes, screen, t 84 sandbox-in-focus?:bool <- move-cursor current-sandbox, screen, t 85 *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus? - 86 screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + 86 screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env 87 loop +next-event 88 } 89 # 'resize' event - redraw editor @@ -184,7 +184,7 @@ if ('onhashchange' in window) { 122 screen <- render-sandbox-side screen, env, render 123 } 124 } -125 screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +125 screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env 126 } 127 loop 128 } @@ -468,7 +468,7 @@ if ('onhashchange' in window) { 406 # top menu 407 trace 11, [app], [render top menu] 408 width:num <- screen-width screen -409 draw-horizontal screen, 0, 0/left, width, 32/space, 0/black, 238/grey +409 draw-horizontal screen, 0, 0/left, width, 32/space, 0/black, 238/grey 410 button-start:num <- subtract width, 20 411 button-on-screen?:bool <- greater-or-equal button-start, 0 412 assert button-on-screen?, [screen too narrow for menu] @@ -478,7 +478,7 @@ if ('onhashchange' in window) { 416 trace 11, [app], [render divider] 417 divider:num, _ <- divide-with-remainder width, 2 418 height:num <- screen-height screen -419 draw-vertical screen, divider, 1/top, height, 9482/vertical-dotted +419 draw-vertical screen, divider, 1/top, height, 9482/vertical-dotted 420 # 421 screen <- render-recipes screen, env, render-editor 422 screen <- render-sandbox-side screen, env, render-editor @@ -487,7 +487,7 @@ if ('onhashchange' in window) { 425 recipes:&:editor <- get *env, recipes:offset 426 current-sandbox:&:editor <- get *env, current-sandbox:offset 427 sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset -428 screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +428 screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env 429 ] 430 431 def render-recipes screen:&:screen, env:&:environment, render-editor:render-recipe -> screen:&:screen, env:&:environment [ @@ -500,119 +500,115 @@ if ('onhashchange' in window) { 438 left:num <- get *recipes, left:offset 439 right:num <- get *recipes, right:offset 440 row:num, column:num, screen <- call render-editor, screen, recipes -441 clear-line-until screen, right -442 row <- add row, 1 -443 <end-render-recipe-components> -444 # draw dotted line after recipes -445 draw-horizontal screen, row, left, right, 9480/horizontal-dotted -446 row <- add row, 1 -447 clear-screen-from screen, row, left, left, right -448 # -449 assert-no-scroll screen, old-top-idx -450 ] -451 -452 # replaced in a later layer -453 def render-sandbox-side screen:&:screen, env:&:environment, render-editor:render-recipe -> screen:&:screen, env:&:environment [ -454 local-scope -455 load-inputs -456 trace 11, [app], [render sandboxes] -457 old-top-idx:num <- save-top-idx screen -458 current-sandbox:&:editor <- get *env, current-sandbox:offset -459 left:num <- get *current-sandbox, left:offset -460 right:num <- get *current-sandbox, right:offset -461 row:num, column:num, screen, current-sandbox <- call render-editor, screen, current-sandbox -462 clear-line-until screen, right -463 row <- add row, 1 -464 # draw solid line after code (you'll see why in later layers) -465 draw-horizontal screen, row, left, right -466 row <- add row, 1 -467 clear-screen-from screen, row, left, left, right -468 # -469 assert-no-scroll screen, old-top-idx -470 ] -471 -472 def update-cursor screen:&:screen, recipes:&:editor, current-sandbox:&:editor, sandbox-in-focus?:bool, env:&:environment -> screen:&:screen [ -473 local-scope -474 load-inputs -475 <update-cursor-special-cases> -476 { -477 break-if sandbox-in-focus? -478 cursor-row:num <- get *recipes, cursor-row:offset -479 cursor-column:num <- get *recipes, cursor-column:offset -480 } -481 { -482 break-unless sandbox-in-focus? -483 cursor-row:num <- get *current-sandbox, cursor-row:offset -484 cursor-column:num <- get *current-sandbox, cursor-column:offset -485 } -486 screen <- move-cursor screen, cursor-row, cursor-column -487 ] -488 -489 # ctrl-n - switch focus -490 # todo: test this -491 -492 after <global-type> [ -493 { -494 switch-side?:bool <- equal c, 14/ctrl-n -495 break-unless switch-side? -496 sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset -497 sandbox-in-focus? <- not sandbox-in-focus? -498 *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus? -499 screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env -500 loop +next-event -501 } -502 ] -503 -504 ## helpers -505 -506 def draw-vertical screen:&:screen, col:num, y:num, bottom:num -> screen:&:screen [ -507 local-scope -508 load-inputs -509 style:char, style-found?:bool <- next-input -510 { -511 break-if style-found? -512 style <- copy 9474/vertical -513 } -514 color:num, color-found?:bool <- next-input -515 { -516 # default color to white -517 break-if color-found? -518 color <- copy 245/grey -519 } -520 { -521 continue?:bool <- lesser-than y, bottom -522 break-unless continue? -523 screen <- move-cursor screen, y, col -524 print screen, style, color -525 y <- add y, 1 -526 loop -527 } -528 ] -529 -530 scenario backspace-over-text [ -531 local-scope -532 trace-until 100/app # trace too long -533 assume-screen 50/width, 15/height -534 # recipes.mu is empty -535 assume-resources [ -536 ] -537 # sandbox editor contains an instruction without storing outputs -538 env:&:environment <- new-programming-environment resources, screen, [] -539 # run the code in the editors -540 assume-console [ -541 type [a] -542 press backspace -543 ] -544 run [ -545 event-loop screen, console, env, resources -546 10:num/raw <- get *screen, cursor-row:offset -547 11:num/raw <- get *screen, cursor-column:offset +441 <end-render-recipe-components> +442 # draw dotted line after recipes +443 draw-horizontal screen, row, left, right, 9480/horizontal-dotted +444 row <- add row, 1 +445 clear-screen-from screen, row, left, left, right +446 # +447 assert-no-scroll screen, old-top-idx +448 ] +449 +450 # replaced in a later layer +451 def render-sandbox-side screen:&:screen, env:&:environment, render-editor:render-recipe -> screen:&:screen, env:&:environment [ +452 local-scope +453 load-inputs +454 trace 11, [app], [render sandboxes] +455 old-top-idx:num <- save-top-idx screen +456 current-sandbox:&:editor <- get *env, current-sandbox:offset +457 left:num <- get *current-sandbox, left:offset +458 right:num <- get *current-sandbox, right:offset +459 row:num, column:num, screen, current-sandbox <- call render-editor, screen, current-sandbox +460 # draw solid line after code (you'll see why in later layers) +461 draw-horizontal screen, row, left, right +462 row <- add row, 1 +463 clear-screen-from screen, row, left, left, right +464 # +465 assert-no-scroll screen, old-top-idx +466 ] +467 +468 def update-cursor screen:&:screen, recipes:&:editor, current-sandbox:&:editor, sandbox-in-focus?:bool, env:&:environment -> screen:&:screen [ +469 local-scope +470 load-inputs +471 <update-cursor-special-cases> +472 { +473 break-if sandbox-in-focus? +474 cursor-row:num <- get *recipes, cursor-row:offset +475 cursor-column:num <- get *recipes, cursor-column:offset +476 } +477 { +478 break-unless sandbox-in-focus? +479 cursor-row:num <- get *current-sandbox, cursor-row:offset +480 cursor-column:num <- get *current-sandbox, cursor-column:offset +481 } +482 screen <- move-cursor screen, cursor-row, cursor-column +483 ] +484 +485 # ctrl-n - switch focus +486 # todo: test this +487 +488 after <global-type> [ +489 { +490 switch-side?:bool <- equal c, 14/ctrl-n +491 break-unless switch-side? +492 sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset +493 sandbox-in-focus? <- not sandbox-in-focus? +494 *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus? +495 screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +496 loop +next-event +497 } +498 ] +499 +500 ## helpers +501 +502 def draw-vertical screen:&:screen, col:num, y:num, bottom:num -> screen:&:screen [ +503 local-scope +504 load-inputs +505 style:char, style-found?:bool <- next-input +506 { +507 break-if style-found? +508 style <- copy 9474/vertical +509 } +510 color:num, color-found?:bool <- next-input +511 { +512 # default color to white +513 break-if color-found? +514 color <- copy 245/grey +515 } +516 { +517 continue?:bool <- lesser-than y, bottom +518 break-unless continue? +519 screen <- move-cursor screen, y, col +520 print screen, style, color +521 y <- add y, 1 +522 loop +523 } +524 ] +525 +526 scenario backspace-over-text [ +527 local-scope +528 trace-until 100/app # trace too long +529 assume-screen 50/width, 15/height +530 # recipes.mu is empty +531 assume-resources [ +532 ] +533 # sandbox editor contains an instruction without storing outputs +534 env:&:environment <- new-programming-environment resources, screen, [] +535 # run the code in the editors +536 assume-console [ +537 type [a] +538 press backspace +539 ] +540 run [ +541 event-loop screen, console, env, resources +542 10:num/raw <- get *screen, cursor-row:offset +543 11:num/raw <- get *screen, cursor-column:offset +544 ] +545 memory-should-contain [ +546 10 <- 1 +547 11 <- 0 548 ] -549 memory-should-contain [ -550 10 <- 1 -551 11 <- 0 -552 ] -553 ] +549 ] -- cgit 1.4.1-2-gfad0