diff options
-rw-r--r-- | 081print.mu | 78 | ||||
-rw-r--r-- | edit/001-editor.mu | 1 | ||||
-rw-r--r-- | edit/002-typing.mu | 9 | ||||
-rw-r--r-- | edit/004-programming-environment.mu | 2 | ||||
-rw-r--r-- | edit/005-sandbox.mu | 33 | ||||
-rw-r--r-- | sandbox/005-sandbox.mu | 36 |
6 files changed, 6 insertions, 153 deletions
diff --git a/081print.mu b/081print.mu index 465d228a..c28513dd 100644 --- a/081print.mu +++ b/081print.mu @@ -1,16 +1,5 @@ # Wrappers around print primitives that take a 'screen' object and are thus # easier to test. -# -# Screen objects are intended to exactly mimic the behavior of traditional -# terminals. Moving a cursor too far write wraps it to the next line, -# scrolling if necessary. The details are subtle: -# -# a) Rows can take unbounded values, and such values are preserved rather than -# clamped or wrapped around. -# -# b) If you print to a square (row, right) on the right margin, the cursor -# position depends on whether 'row' is in range. If it is, the new cursor -# position is (row+1, 0). If it isn't, the new cursor position is (row, 0). container screen [ num-rows:num @@ -18,7 +7,6 @@ container screen [ cursor-row:num cursor-column:num data:&:@:screen-cell # capacity num-rows*num-columns - pending-scroll?:bool top-idx:num # index inside data that corresponds to top-left of screen # modified on scroll, wrapping around to the top of data ] @@ -28,32 +16,6 @@ container screen-cell [ color:num ] -def main [ - local-scope - open-console - clear-screen - print 0/screen [a] -#? a:char <- copy 97 -#? i:num <- copy 0 -#? { -#? done?:bool <- greater-or-equal i, 6 -#? break-if done? -#? move-cursor 0/screen i, 2527 -#? print 0/screen a -#? a <- add a, 1 -#? i <- add i, 1 -#? loop -#? } - move-cursor 0/screen 5, 2527 - a:num b:num <- cursor-position 0/screen - print 0/screen [f] - c:num d:num <- cursor-position 0/screen - wait-for-some-interaction - close-console - $print a [ ] b 10/newline - $print c [ ] d 10/newline -] - def new-fake-screen w:num, h:num -> result:&:screen [ local-scope load-ingredients @@ -64,7 +26,7 @@ def new-fake-screen w:num, h:num -> result:&:screen [ assert non-zero-height?, [screen can't have zero height] bufsize:num <- multiply w, h data:&:@:screen-cell <- new screen-cell:type, bufsize - *result <- merge h/num-rows, w/num-columns, 0/cursor-row, 0/cursor-column, data, 0/pending-scroll?, 0/top-idx + *result <- merge h/num-rows, w/num-columns, 0/cursor-row, 0/cursor-column, data, 0/top-idx result <- clear-screen result ] @@ -137,8 +99,6 @@ def print screen:&:screen, c:char -> screen:&:screen [ { # real screen break-if screen -#? x:num y:num <- cursor-position-on-display -#? stash [print] x y print-character-to-display c, color, bg-color return } @@ -188,13 +148,9 @@ def print screen:&:screen, c:char -> screen:&:screen [ { at-bottom?:bool <- equal row, height break-unless at-bottom? - $dump-screen - $print [scroll1] 10/newline scroll-fake-screen screen row <- subtract height, 1 *screen <- put *screen, cursor-row:offset, row - *screen <- put *screen, pending-scroll?:offset, 0/false - $dump-screen } # if row is below bottom margin (error), reset to bottom margin { @@ -204,18 +160,6 @@ def print screen:&:screen, c:char -> screen:&:screen [ *screen <- put *screen, cursor-row:offset, row } # } - # if there's a pending scroll, perform it - { - pending-scroll?:bool <- get *screen, pending-scroll?:offset -#? $print pending-scroll? 10/newline - break-unless pending-scroll? - $print [scroll2] 10/newline - $dump-screen - scroll-fake-screen screen - *screen <- put *screen, pending-scroll?:offset, 0/false - $dump-screen - } -#? stash [print] row column #? $print [print-character (], row, [, ], column, [): ], c, 10/newline # special-case: newline { @@ -248,23 +192,9 @@ def print screen:&:screen, c:char -> screen:&:screen [ index:num <- data-index row, column, width, height, top-idx cursor:screen-cell <- merge c, color *buf <- put-index *buf, index, cursor - # move cursor to next character, wrapping as necessary - # however, don't scroll just yet + # move cursor to next character # (but don't bother making it valid; we'll do that before the next print) column <- add column, 1 - { - past-right?:bool <- greater-or-equal column, width - break-unless past-right? - column <- copy 0 - row <- add row, 1 - past-bottom?:bool <- greater-or-equal row, height - break-unless past-bottom? - # queue up a scroll - $print [pending scroll] 10/newline - *screen <- put *screen, pending-scroll?:offset, 1/true - row <- subtract row, 1 # update cursor as if scroll already happened - } - *screen <- put *screen, cursor-row:offset, row *screen <- put *screen, cursor-column:offset, column ] @@ -576,7 +506,7 @@ def assert-no-scroll screen:&:screen, old-top-idx:num [ return-unless screen new-top-idx:num <- get *screen, top-idx:offset no-scroll?:bool <- equal old-top-idx, new-top-idx -#? assert no-scroll?, [render should never use screen's scrolling capabilities] + assert no-scroll?, [render should never use screen's scrolling capabilities] ] def clear-line screen:&:screen -> screen:&:screen [ @@ -659,8 +589,6 @@ def move-cursor screen:&:screen, new-row:num, new-column:num -> screen:&:screen # fake screen *screen <- put *screen, cursor-row:offset, new-row *screen <- put *screen, cursor-column:offset, new-column - $print [move cursor ] new-row [ ] new-column 10/newline - *screen <- put *screen, pending-scroll?:offset, 0/false ] scenario clear-line-erases-printed-characters [ diff --git a/edit/001-editor.mu b/edit/001-editor.mu index d4e0a479..9e136b7e 100644 --- a/edit/001-editor.mu +++ b/edit/001-editor.mu @@ -218,7 +218,6 @@ def clear-screen-from screen:&:screen, row:num, column:num, left:num, right:num screen <- move-cursor screen, row, column clear-line-until screen, right clear-rest-of-screen screen, row, left, right -#? screen <- move-cursor screen, row, column ] def clear-rest-of-screen screen:&:screen, row:num, left:num, right:num -> screen:&:screen [ diff --git a/edit/002-typing.mu b/edit/002-typing.mu index acb0a53c..3b29c322 100644 --- a/edit/002-typing.mu +++ b/edit/002-typing.mu @@ -1116,11 +1116,8 @@ after <handle-special-key> [ def draw-horizontal screen:&:screen, row:num, x:num, right:num -> screen:&:screen [ local-scope load-ingredients -#? a:num, b:num <- cursor-position screen -#? stash [draw-horizontal] row [--] a b height:num <- screen-height screen past-bottom?:bool <- greater-or-equal row, height -#? stash [ past-bottom?] past-bottom? return-if past-bottom? style:char, style-found?:bool <- next-ingredient { @@ -1138,18 +1135,12 @@ def draw-horizontal screen:&:screen, row:num, x:num, right:num -> screen:&:scree break-if bg-color-found? bg-color <- copy 0/black } -#? stash [aa] x screen <- move-cursor screen, row, x { continue?:bool <- lesser-or-equal x, right # right is inclusive, to match editor semantics break-unless continue? -#? a b <- cursor-position screen -#? stash [bb] x [--] a b print screen, style, color, bg-color -#? a b <- cursor-position screen -#? stash [cc] x [--] a b x <- add x, 1 loop } -#? stash [draw-horizontal done] ] diff --git a/edit/004-programming-environment.mu b/edit/004-programming-environment.mu index 021d9d73..897f2923 100644 --- a/edit/004-programming-environment.mu +++ b/edit/004-programming-environment.mu @@ -447,7 +447,6 @@ def render-recipes screen:&:screen, env:&:environment, render-editor:render-reci clear-screen-from screen, row, left, left, right # assert-no-scroll screen, old-top-idx -#? stash [render recipes done] ] # replaced in a later layer @@ -468,7 +467,6 @@ def render-sandbox-side screen:&:screen, env:&:environment, render-editor:render clear-screen-from screen, row, left, left, right # assert-no-scroll screen, old-top-idx -#? stash [render sandbox side0 done] ] def update-cursor screen:&:screen, recipes:&:editor, current-sandbox:&:editor, sandbox-in-focus?:bool, env:&:environment -> screen:&:screen [ diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu index f27c1a2c..9970bbae 100644 --- a/edit/005-sandbox.mu +++ b/edit/005-sandbox.mu @@ -14,8 +14,6 @@ def! main [ env:&:environment <- new-programming-environment 0/filesystem, 0/screen env <- restore-sandboxes env, 0/filesystem render-all 0/screen, env, render - wait-for-some-interaction - $exit event-loop 0/screen, 0/console, env, 0/filesystem ] @@ -270,15 +268,12 @@ def! render-sandbox-side screen:&:screen, env:&:environment, render-editor:rende clear-rest-of-screen screen, row, left, right # assert-no-scroll screen, old-top-idx -#? stash [render sandbox side done] ] def render-sandboxes screen:&:screen, sandbox:&:sandbox, left:num, right:num, row:num, render-from:num, idx:num -> row:num, screen:&:screen, sandbox:&:sandbox [ local-scope load-ingredients return-unless sandbox -#? a:num b:num <- cursor-position screen -#? stash [render-sandboxes] idx [:] row [--] a b screen-height:num <- screen-height screen at-bottom?:bool <- greater-or-equal row, screen-height return-if at-bottom? @@ -287,8 +282,6 @@ def render-sandboxes screen:&:screen, sandbox:&:sandbox, left:num, right:num, ro break-if hidden? # render sandbox menu row <- add row, 1 -#? at-bottom?:bool <- greater-or-equal row, screen-height -#? return-if at-bottom? screen <- move-cursor screen, row, left screen <- render-sandbox-menu screen, idx, left, right # save menu row so we can detect clicks to it later @@ -350,32 +343,6 @@ def render-sandbox-menu screen:&:screen, sandbox-index:num, left:num, right:num clear-line-until screen, right, 52/background-red ] -scenario skip-rendering-sandbox-menu-past-bottom-row [ - trace-until 100/app # trace too long - assume-screen 100/width, 6/height - # recipe editor is empty - assume-resources [ - [lesson/0] <- [|add 2, 2|] - [lesson/1] <- [|add 1, 1|] - ] - # create two sandboxes such that the top one just barely fills the screen - env:&:environment <- new-programming-environment resources, screen, [] - env <- restore-sandboxes env, resources -#? $clear-trace - run [ - render-all screen, env, render - ] -#? $dump-trace [app] - screen-should-contain [ - . run (F4) . - . ┊ . - .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊─────────────────────────────────────────────────. - . ┊0 edit copy to recipe delete . - . ┊add 2, 2 . - . ┊─────────────────────────────────────────────────. - ] -] - # divide up the menu bar for a sandbox into 3 segments, for edit/copy/delete buttons # delete-button-right == right # all left/right pairs are inclusive diff --git a/sandbox/005-sandbox.mu b/sandbox/005-sandbox.mu index 3d06b7d9..cc7892d6 100644 --- a/sandbox/005-sandbox.mu +++ b/sandbox/005-sandbox.mu @@ -12,7 +12,7 @@ def! main [ open-console clear-screen 0/screen # non-scrolling app env:&:environment <- new-programming-environment 0/filesystem, 0/screen - env <- restore-sandboxes env + env <- restore-sandboxes env, 0/filesystem render-all 0/screen, env, render event-loop 0/screen, 0/console, env, 0/filesystem ] @@ -260,13 +260,13 @@ def render-sandboxes screen:&:screen, sandbox:&:sandbox, left:num, right:num, ro env:&:environment, _/optional <- next-ingredient return-unless sandbox screen-height:num <- screen-height screen + at-bottom?:bool <- greater-or-equal row, screen-height + return-if at-bottom? hidden?:bool <- lesser-than idx, render-from { break-if hidden? # render sandbox menu row <- add row, 1 - at-bottom?:bool <- greater-or-equal row, screen-height - return-if at-bottom? screen <- move-cursor screen, row, left screen <- render-sandbox-menu screen, idx, left, right # save menu row so we can detect clicks to it later @@ -326,36 +326,6 @@ def render-sandbox-menu screen:&:screen, sandbox-index:num, left:num, right:num clear-line-until screen, right, 52/background-red ] -scenario skip-rendering-sandbox-menu-past-bottom-row [ - trace-until 100/app # trace too long - assume-screen 50/width, 7/height - # recipes.mu is empty - assume-resources [ - ] - # create two sandboxes such that the top one just barely fills the screen - env:&:environment <- new-programming-environment resources, screen, [] - render-all screen, env, render - assume-console [ - left-click 1, 75 - type [add 1, 1] - press F4 - type [add 2, 2] - press F4 - ] - run [ - event-loop screen, console, env, resources - ] - screen-should-contain [ - . run (F4) . - . . - .──────────────────────────────────────────────────. - .0 edit copy delete . - .add 2, 2 . - .4 . - .──────────────────────────────────────────────────. - ] -] - # divide up the menu bar for a sandbox into 3 segments, for edit/copy/delete buttons # delete-button-right == right # all left/right pairs are inclusive |