def! main [
local-scope
open-console
initial-recipe:address:array:character <- restore [recipes.mu]
initial-sandbox:address:array:character <- new []
hide-screen 0/screen
env:address:programming-environment-data <- new-programming-environment 0/screen, initial-recipe, initial-sandbox
env <- restore-sandboxes env
render-all 0/screen, env, render
event-loop 0/screen, 0/console, env
]
container programming-environment-data [
sandbox:address:sandbox-data
render-from:number
number-of-sandboxes:number
]
after <programming-environment-initialization> [
*result <- put *result, render-from:offset, -1
]
container sandbox-data [
data:address:array:character
response:address:array:character
starting-row-on-screen:number
code-ending-row-on-screen:number
screen:address:screen
next-sandbox:address:sandbox-data
]
scenario run-and-show-results [
trace-until 100/app
assume-screen 100/width, 15/height
1:address:array:character <- new []
2:address:array:character <- new [divide-with-remainder 11, 3]
3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character
assume-console [
press F4
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
]
screen-should-contain [
. run (F4) .
. ┊ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊0 edit copy delete .
. ┊divide-with-remainder 11, 3 .
. ┊3 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
screen-should-contain-in-color 7/white, [
. .
. .
. .
. .
. divide-with-remainder 11, 3 .
. .
. .
. .
. .
]
screen-should-contain-in-color 245/grey, [
. .
. ┊ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
. ┊ .
. ┊3 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
screen-should-contain-in-color 232/black, [
. .
. .
. .
. 0 edit copy delete .
]
assume-console [
left-click 1, 80
type [add 2, 2]
press F4
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
]
screen-should-contain [
. run (F4) .
. ┊ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊0 edit copy delete .
. ┊add 2, 2 .
. ┊4 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊1 edit copy delete .
. ┊divide-with-remainder 11, 3 .
. ┊3 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
]
after <global-keypress> [
{
do-run?:boolean <- equal k, 65532/F4
break-unless do-run?
screen <- update-status screen, [running... ], 245/grey
error?:boolean, env, screen <- run-sandboxes env, screen
screen <- render-all screen, env, render
{
break-if error?
screen <- update-status screen, [ ], 245/grey
}
screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env
loop +next-event:label
}
]
def run-sandboxes env:address:programming-environment-data, screen:address:screen -> errors-found?:boolean, env:address:programming-environment-data, screen:address:screen [
local-scope
load-ingredients
errors-found?:boolean, env, screen <- update-recipes env, screen
return-if errors-found?
<run-sandboxes-begin>
current-sandbox:address:editor-data <- get *env, current-sandbox:offset
{
sandbox-contents:address:array:character <- editor-contents current-sandbox
break-unless sandbox-contents
new-sandbox:address:sandbox-data <- new sandbox-data:type
*new-sandbox <- put *new-sandbox, data:offset, sandbox-contents
dest:address:sandbox-data <- get *env, sandbox:offset
*new-sandbox <- put *new-sandbox, next-sandbox:offset, dest
*env <- put *env, sandbox:offset, new-sandbox
sandbox-count:number <- get *env, number-of-sandboxes:offset
sandbox-count <- add sandbox-count, 1
*env <- put *env, number-of-sandboxes:offset, sandbox-count
init:address:duplex-list:character <- push 167/§, 0/tail
*current-sandbox <- put *current-sandbox, data:offset, init
*current-sandbox <- put *current-sandbox, top-of-screen:offset, init
}
save-sandboxes env
curr:address:sandbox-data <- get *env, sandbox:offset
idx:number <- copy 0
{
break-unless curr
curr <- update-sandbox curr, env, idx
curr <- get *curr, next-sandbox:offset
idx <- add idx, 1
loop
}
<run-sandboxes-end>
]
def update-recipes env:address:programming-environment-data, screen:address:screen -> errors-found?:boolean, env:address:programming-environment-data, screen:address:screen [
local-scope
load-ingredients
recipes:address:editor-data <- get *env, recipes:offset
in:address:array:character <- editor-contents recipes
save [recipes.mu], in
reload in
errors-found? <- copy 0/false
]
def! update-sandbox sandbox:address:sandbox-data, env:address:programming-environment-data, idx:number -> sandbox:address:sandbox-data, env:address:programming-environment-data [
local-scope
load-ingredients
data:address:array:character <- get *sandbox, data:offset
response:address:array:character, _, fake-screen:address:screen <- run-sandboxed data
*sandbox <- put *sandbox, response:offset, response
*sandbox <- put *sandbox, screen:offset, fake-screen
]
def update-status screen:address:screen, msg:address:array:character, color:number -> screen:address:screen [
local-scope
load-ingredients
screen <- move-cursor screen, 0, 2
screen <- print screen, msg, color, 238/grey/background
]
def save-sandboxes env:address:programming-environment-data [
local-scope
load-ingredients
current-sandbox:address:editor-data <- get *env, current-sandbox:offset
$system [rm lesson/[0-9]* >/dev/null 2>/dev/null]
curr:address:sandbox-data <- get *env, sandbox:offset
idx:number <- copy 0
{
break-unless curr
data:address:array:character <- get *curr, data:offset
filename:address:array:character <- to-text idx
save filename, data
<end-save-sandbox>
idx <- add idx, 1
curr <- get *curr, next-sandbox:offset
loop
}
]
def! render-sandbox-side screen:address:screen, env:address:programming-environment-data, {render-editor: (recipe (address screen) (address editor-data) -> number number (address screen) (address editor-data))} -> screen:address:screen, env:address:programming-environment-data [
local-scope
load-ingredients
trace 11, [app], [render sandbox side]
current-sandbox:address:editor-data <- get *env, current-sandbox:offset
row:number, column:number <- copy 1, 0
left:number <- get *current-sandbox, left:offset
right:number <- get *current-sandbox, right:offset
render-from:number <- get *env, render-from:offset
{
render-current-sandbox?:boolean <- equal render-from, -1
break-unless render-current-sandbox?
row, column, screen, current-sandbox <- call render-editor, screen, current-sandbox
clear-screen-from screen, row, column, left, right
row <- add row, 1
}
draw-horizontal screen, row, left, right, 9473/horizontal-double
sandbox:address:sandbox-data <- get *env, sandbox:offset
row, screen <- render-sandboxes screen, sandbox, left, right, row, render-from
clear-rest-of-screen screen, row, left, right
]
def render-sandboxes screen:address:screen, sandbox:address:sandbox-data, left:number, right:number, row:number, render-from:number, idx:number -> row:number, screen:address:screen, sandbox:address:sandbox-data [
local-scope
load-ingredients
return-unless sandbox
screen-height:number <- screen-height screen
at-bottom?:boolean <- greater-or-equal row, screen-height
return-if at-bottom?:boolean
hidden?:boolean <- lesser-than idx, render-from
{
break-if hidden?
row <- add row, 1
screen <- move-cursor screen, row, left
screen <- render-sandbox-menu screen, idx, left, right
*sandbox <- put *sandbox, starting-row-on-screen:offset, row
row <- add row, 1
screen <- move-cursor screen, row, left
sandbox-data:address:array:character <- get *sandbox, data:offset
row, screen <- render-code screen, sandbox-data, left, right, row
*sandbox <- put *sandbox, code-ending-row-on-screen:offset, row
sandbox-response:address:array:character <- get *sandbox, response:offset
<render-sandbox-results>
{
sandbox-screen:address:screen <- get *sandbox, screen:offset
empty-screen?:boolean <- fake-screen-is-empty? sandbox-screen
break-if empty-screen?
row, screen <- render-screen screen, sandbox-screen, left, right, row
}
{
break-unless empty-screen?
<render-sandbox-response>
row, screen <- render-text screen, sandbox-response, left, right, 245/grey, row
}
+render-sandbox-end
at-bottom?:boolean <- greater-or-equal row, screen-height
return-if at-bottom?
draw-horizontal screen, row, left, right, 9473/horizontal-double
}
{
break-unless hidden?
*sandbox <- put *sandbox, starting-row-on-screen:offset, 0
*sandbox <- put *sandbox, code-ending-row-on-screen:offset, 0
<end-render-sandbox-reset-hidden>
}
next-sandbox:address:sandbox-data <- get *sandbox, next-sandbox:offset
next-idx:number <- add idx, 1
row, screen <- render-sandboxes screen, next-sandbox, left, right, row, render-from, next-idx
]
def render-sandbox-menu screen:address:screen, sandbox-index:number, left:number, right:number -> screen:address:screen [
local-scope
load-ingredients
move-cursor-to-column screen, left
edit-button-left:number, edit-button-right:number, copy-button-left:number, copy-button-right:number, delete-button-left:number <- sandbox-menu-columns left, right
print screen, sandbox-index, 232/dark-grey, 245/grey
start-buttons:number <- subtract edit-button-left, 1
clear-line-until screen, start-buttons, 245/grey
print screen, [edit], 232/black, 94/background-orange
clear-line-until screen, edit-button-right, 94/background-orange
_, col:number <- cursor-position screen
at-start-of-copy-button?:boolean <- equal col, copy-button-left
assert at-start-of-copy-button?, [aaa]
print screen, [copy], 232/black, 58/background-green
clear-line-until screen, copy-button-right, 58/background-green
_, col:number <- cursor-position screen
at-start-of-delete-button?:boolean <- equal col, delete-button-left
assert at-start-of-delete-button?, [bbb]
print screen, [delete], 232/black, 52/background-red
clear-line-until screen, right, 52/background-red
]
def sandbox-menu-columns left:number, right:number -> edit-button-left:number, edit-button-right:number, copy-button-left:number, copy-button-right:number, delete-button-left:number [
local-scope
load-ingredients
start-buttons:number <- add left, 4/space-for-sandbox-index
buttons-space:number <- subtract right, start-buttons
button-width:number <- divide-with-remainder buttons-space, 3
buttons-wide-enough?:boolean <- greater-or-equal button-width, 8
assert buttons-wide-enough?, [sandbox must be at least 30 or so characters wide]
edit-button-left:number <- copy start-buttons
copy-button-left:number <- add start-buttons, button-width
edit-button-right:number <- subtract copy-button-left, 1
delete-button-left:number <- subtract right, button-width
copy-button-right:number <- subtract delete-button-left, 1
]
def render-text screen:address:screen, s:address:array:character, left:number, right:number, color:number, row:number -> row:number, screen:address:screen [
local-scope
load-ingredients
return-unless s
column:number <- copy left
screen <- move-cursor screen, row, column
screen-height:number <- screen-height screen
i:number <- copy 0
len:number <- length *s
{
+next-character
done?:boolean <- greater-or-equal i, len
break-if done?
done? <- greater-or-equal row, screen-height
break-if done?
c:character <- index *s, i
{
at-right?:boolean <- equal column, right
break-unless at-right?
wrap-icon:character <- copy 8617/loop-back-to-left
print screen, wrap-icon, 245/grey
column <- copy left
row <- add row, 1
screen <- move-cursor screen, row, column
loop +next-character:label
}
i <- add i, 1
{
newline?:boolean <- equal c, 10/newline
break-unless newline?
{
done?:boolean <- greater-than column, right
break-if done?
space:character <- copy 32/space
print screen, space
column <- add column, 1
loop
}
row <- add row, 1
column <- copy left
screen <- move-cursor screen, row, column
loop +next-character:label
}
print screen, c, color
column <- add column, 1
loop
}
was-at-left?:boolean <- equal column, left
clear-line-until screen, right
{
break-if was-at-left?
row <- add row, 1
}
move-cursor screen, row, left
]
def restore-sandboxes env:address:programming-environment-data -> env:address:programming-environment-data [
local-scope
load-ingredients
idx:number <- copy 0
curr:address:sandbox-data <- copy 0
prev:address:sandbox-data <- copy 0
{
filename:address:array:character <- to-text idx
contents:address:array:character <- restore filename
break-unless contents
curr <- new sandbox-data:type
*curr <- put *curr, data:offset, contents
<end-restore-sandbox>
{
break-if idx
*env <- put *env, sandbox:offset, curr
}
{
break-unless idx
*prev <- put *prev, next-sandbox:offset, curr
}
idx <- add idx, 1
prev <- copy curr
loop
}
*env <- put *env, number-of-sandboxes:offset, idx
]
def render-screen screen:address:screen, sandbox-screen:address:screen, left:number, right:number, row:number -> row:number, screen:address:screen [
local-scope
load-ingredients
return-unless sandbox-screen
row <- render-text screen, [screen:], left, right, 245/grey, row
screen <- move-cursor screen, row, left
column:number <- copy left
s-width:number <- screen-width sandbox-screen
s-height:number <- screen-height sandbox-screen
buf:address:array:screen-cell <- get *sandbox-screen, data:offset
stop-printing:number <- add left, s-width, 3
max-column:number <- min stop-printing, right
i:number <- copy 0
len:number <- length *buf
screen-height:number <- screen-height screen
{
done?:boolean <- greater-or-equal i, len
break-if done?
done? <- greater-or-equal row, screen-height
break-if done?
column <- copy left
screen <- move-cursor screen, row, column
space:character <- copy 32/space
print screen, space, 245/grey
print screen, space, 245/grey
full-stop:character <- copy 46/period
print screen, full-stop, 245/grey
column <- add left, 3
{
row-done?:boolean <- greater-or-equal column, max-column
break-if row-done?
curr:screen-cell <- index *buf, i
c:character <- get curr, contents:offset
color:number <- get curr, color:offset
{
white?:boolean <- equal color, 7/white
break-unless white?
color <- copy 245/grey
}
print screen, c, color
column <- add column, 1
i <- add i, 1
loop
}
print screen, full-stop, 245/grey
column <- add column, 1
{
line-done?:boolean <- greater-than column, right
break-if line-done?
print screen, space
column <- add column, 1
loop
}
row <- add row, 1
loop
}
]
scenario run-updates-results [
trace-until 100/app
assume-screen 100/width, 12/height
1:address:array:character <- new [
recipe foo [
local-scope
z:number <- add 2, 2
reply z
]]
2:address:array:character <- new [foo]
3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character
assume-console [
press F4
]
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
screen-should-contain [
. run (F4) .
. ┊ .
.recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.local-scope ┊0 edit copy delete .
.z:number <- add 2, 2 ┊foo .
.reply z ┊4 .
.] ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ .
. ┊ .
]
assume-console [
left-click 4, 28
press backspace
type [3]
press F4
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
]
screen-should-contain [
. run (F4) .
. ┊ .
.recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.local-scope ┊0 edit copy delete .
.z:number <- add 2, 3 ┊foo .
.reply z ┊5 .
.] ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ .
. ┊ .
]
]
scenario run-instruction-manages-screen-per-sandbox [
trace-until 100/app
assume-screen 100/width, 20/height
1:address:array:character <- new []
2:address:array:character <- new [print-integer screen, 4]
3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character
assume-console [
press F4
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
]
screen-should-contain [
. run (F4) .
. ┊ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊0 edit copy delete .
. ┊print-integer screen, 4 .
. ┊screen: .
. ┊ .4 . .
. ┊ . . .
. ┊ . . .
. ┊ . . .
. ┊ . . .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
]
def editor-contents editor:address:editor-data -> result:address:array:character [
local-scope
load-ingredients
buf:address:buffer <- new-buffer 80
curr:address:duplex-list:character <- get *editor, data:offset
assert curr, [editor without data is illegal; must have at least a sentinel]
curr <- next curr
return-unless curr, 0
{
break-unless curr
c:character <- get *curr, value:offset
buf <- append buf, c
curr <- next curr
loop
}
result <- buffer-to-array buf
]
scenario editor-provides-edited-contents [
assume-screen 10/width, 5/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right
assume-console [
left-click 1, 2
type [def]
]
run [
editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data
3:address:array:character <- editor-contents 2:address:editor-data
4:array:character <- copy *3:address:array:character
]
memory-should-contain [
4:array:character <- [abdefc]
]
]
scenario scrolling-down-past-bottom-of-recipe-editor [
local-scope
trace-until 100/app
assume-screen 100/width, 10/height
env:address:programming-environment-data <- new-programming-environment screen:address:screen, [], []
render-all screen, env, render
assume-console [
press enter
press down-arrow
]
event-loop screen, console:address:console, env
screen-should-contain [
. run (F4) .
. ┊ .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ .
. ┊ .
]
]
scenario cursor-down-in-recipe-editor [
local-scope
trace-until 100/app
assume-screen 100/width, 10/height
env:address:programming-environment-data <- new-programming-environment screen:address:screen, [], []
render-all screen, env, render
assume-console [
press enter
press up-arrow
press down-arrow
]
event-loop screen, console:address:console, env
cursor:character <- copy 9251/␣
print screen:address:screen, cursor
screen-should-contain [
. run (F4) .
. ┊ .
.␣ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ .
. ┊ .
]
]
container programming-environment-data [
recipe-bottom:number
]
after <render-recipe-components-end> [
*env <- put *env, recipe-bottom:offset, row
]
after <global-keypress> [
{
break-if sandbox-in-focus?
down-arrow?:boolean <- equal k, 65516/down-arrow
break-unless down-arrow?
recipe-editor:address:editor-data <- get *env, recipes:offset
recipe-cursor-row:number <- get *recipe-editor, cursor-row:offset
recipe-editor-bottom:number <- get *recipe-editor, bottom:offset
at-bottom-of-editor?:boolean <- greater-or-equal recipe-cursor-row, recipe-editor-bottom
break-unless at-bottom-of-editor?
more-to-scroll?:boolean <- more-to-scroll? env, screen
break-if more-to-scroll?
loop +next-event:label
}
{
break-if sandbox-in-focus?
page-down?:boolean <- equal k, 65518/page-down
break-unless page-down?
more-to-scroll?:boolean <- more-to-scroll? env, screen
break-if more-to-scroll?
loop +next-event:label
}
]
after <global-type> [
{
break-if sandbox-in-focus?
page-down?:boolean <- equal k, 6/ctrl-f
break-unless page-down?
more-to-scroll?:boolean <- more-to-scroll? env, screen
break-if more-to-scroll?
loop +next-event:label
}
]
def more-to-scroll? env:address:programming-environment-data, screen:address:screen -> result:boolean [
local-scope
load-ingredients
recipe-bottom:number <- get *env, recipe-bottom:offset
height:number <- screen-height screen
result <- greater-or-equal recipe-bottom, height
]
scenario scrolling-down-past-bottom-of-recipe-editor-2 [
local-scope
trace-until 100/app
assume-screen 100/width, 10/height
env:address:programming-environment-data <- new-programming-environment screen:address:screen, [], []
render-all screen, env, render
assume-console [
press enter
press up-arrow
press page-down
]
event-loop screen, console:address:console, env
screen-should-contain [
. run (F4) .
. ┊ .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ .
. ┊ .
]
]
scenario scrolling-down-past-bottom-of-recipe-editor-3 [
local-scope
trace-until 100/app
assume-screen 100/width, 10/height
env:address:programming-environment-data <- new-programming-environment screen:address:screen, [], [ab
cd]
render-all screen, env, render
assume-console [
press enter
press ctrl-n
press down-arrow
]
event-loop screen, console:address:console, env
cursor:character <- copy 9251/␣
print screen:address:screen, cursor
screen-should-contain [
. run (F4) .
. ┊ab .
. ┊␣d .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
]
scenario scrolling-down-past-bottom-of-sandbox-editor [
trace-until 100/app
assume-screen 100/width, 10/height
1:address:array:character <- new []
2:address:array:character <- new [add 2, 2]
3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character
render-all screen, 3:address:programming-environment-data, render
assume-console [
press F4
]
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
screen-should-contain [
. run (F4) .
. ┊ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊0 edit copy delete .
. ┊add 2, 2 .
]
assume-console [
press ctrl-n
press page-down
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
4:character/cursor <- copy 9251/␣
print screen:address:screen, 4:character/cursor
]
screen-should-contain [
. run (F4) .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊␣ edit copy delete .
. ┊add 2, 2 .
. ┊4 .
]
assume-console [
press page-up
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
4:character/cursor <- copy 9251/␣
print screen:address:screen, 4:character/cursor
]
screen-should-contain [
. run (F4) .
. ┊␣ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊0 edit copy delete .
. ┊add 2, 2 .
]
]
after <global-keypress> [
{
break-unless sandbox-in-focus?
page-down?:boolean <- equal k, 65518/page-down
break-unless page-down?
sandbox:address:sandbox-data <- get *env, sandbox:offset
break-unless sandbox
{
render-from:number <- get *env, render-from:offset
number-of-sandboxes:number <- get *env, number-of-sandboxes:offset
max:number <- subtract number-of-sandboxes, 1
at-end?:boolean <- greater-or-equal render-from, max
jump-if at-end?, +finish-event:label
render-from <- add render-from, 1
*env <- put *env, render-from:offset, render-from
}
hide-screen screen
screen <- render-sandbox-side screen, env, render
show-screen screen
jump +finish-event:label
}
]
after <update-cursor-special-cases> [
{
break-unless sandbox-in-focus?
render-from:number <- get *env, render-from:offset
scrolling?:boolean <- greater-or-equal render-from, 0
break-unless scrolling?
cursor-column:number <- get *current-sandbox, left:offset
screen <- move-cursor screen, 2/row, cursor-column
return
}
]
after <global-keypress> [
{
break-unless sandbox-in-focus?
page-up?:boolean <- equal k, 65519/page-up
break-unless page-up?
render-from:number <- get *env, render-from:offset
at-beginning?:boolean <- equal render-from, -1
break-if at-beginning?
render-from <- subtract render-from, 1
*env <- put *env, render-from:offset, render-from
hide-screen screen
screen <- render-sandbox-side screen, env, render
show-screen screen
jump +finish-event:label
}
]
def previous-sandbox env:address:programming-environment-data, in:address:sandbox-data -> out:address:sandbox-data [
local-scope
load-ingredients
curr:address:sandbox-data <- get *env, sandbox:offset
return-unless curr, 0/nil
next:address:sandbox-data <- get *curr, next-sandbox:offset
{
return-unless next, 0/nil
found?:boolean <- equal next, in
break-if found?
curr <- copy next
next <- get *curr, next-sandbox:offset
loop
}
return curr
]
scenario scrolling-down-on-recipe-side [
trace-until 100/app
assume-screen 100/width, 10/height
1:address:array:character <- new [
]
2:address:array:character <- new [add 2, 2]
3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character
render-all screen, 3:address:programming-environment-data, render
assume-console [
press F4
]
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
assume-console [
press page-down
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
4:character/cursor <- copy 9251/␣
print screen:address:screen, 4:character/cursor
]
screen-should-contain [
. run (F4) .
.␣ ┊ .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊0 edit copy delete .
. ┊add 2, 2 .
]
]
scenario scrolling-through-multiple-sandboxes [
trace-until 100/app
assume-screen 100/width, 10/height
1:address:array:character <- new []
2:address:array:character <- new []
3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character
render-all screen, 3:address:programming-environment-data, render
assume-console [
press ctrl-n
type [add 2, 2]
press F4
type [add 1, 1]
press F4
]
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
4:character/cursor <- copy 9251/␣
print screen:address:screen, 4:character/cursor
screen-should-contain [
. run (F4) .
. ┊␣ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊0 edit copy delete .
. ┊add 1, 1 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊1 edit copy delete .
. ┊add 2, 2 .
. ┊4 .
]
assume-console [
press page-down
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
4:character/cursor <- copy 9251/␣
print screen:address:screen, 4:character/cursor
]
screen-should-contain [
. run (F4) .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊␣ edit copy delete .
. ┊add 1, 1 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊1 edit copy delete .
. ┊add 2, 2 .
. ┊4 .
]
assume-console [
press page-down
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
]
screen-should-contain [
. run (F4) .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊1 edit copy delete .
. ┊add 2, 2 .
. ┊4 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
assume-console [
press page-down
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
]
screen-should-contain [
. run (F4) .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊1 edit copy delete .
. ┊add 2, 2 .
. ┊4 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
assume-console [
press page-up
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
]
screen-should-contain [
. run (F4) .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊0 edit copy delete .
. ┊add 1, 1 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊1 edit copy delete .
. ┊add 2, 2 .
. ┊4 .
]
assume-console [
press page-up
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
4:character/cursor <- copy 9251/␣
print screen:address:screen, 4:character/cursor
]
screen-should-contain [
. run (F4) .
. ┊␣ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊0 edit copy delete .
. ┊add 1, 1 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊1 edit copy delete .
. ┊add 2, 2 .
. ┊4 .
]
assume-console [
press page-up
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
4:character/cursor <- copy 9251/␣
print screen:address:screen, 4:character/cursor
]
screen-should-contain [
. run (F4) .
. ┊␣ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊0 edit copy delete .
. ┊add 1, 1 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊1 edit copy delete .
. ┊add 2, 2 .
. ┊4 .
]
]
scenario scrolling-manages-sandbox-index-correctly [
trace-until 100/app
assume-screen 100/width, 10/height
1:address:array:character <- new []
2:address:array:character <- new []
3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character
render-all screen, 3:address:programming-environment-data, render
assume-console [
press ctrl-n
type [add 1, 1]
press F4
]
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
screen-should-contain [
. run (F4) .
. ┊ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊0 edit copy delete .
. ┊add 1, 1 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
assume-console [
press page-down
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
]
screen-should-contain [
. run (F4) .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊0 edit copy delete .
. ┊add 1, 1 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
assume-console [
press page-up
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
]
screen-should-contain [
. run (F4) .
. ┊ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊0 edit copy delete .
. ┊add 1, 1 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
assume-console [
press page-down
]
run [
event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
]
screen-should-contain [
. run (F4) .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊0 edit copy delete .
. ┊add 1, 1 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
]