scenario sandbox-click-on-result-toggles-color-to-green [
trace-until 100/app
assume-screen 100/width, 10/height
1:text <- new [
recipe foo [
reply 4
]]
2:text <- new [foo]
assume-console [
press F4
]
3:&:environment <- new-programming-environment screen:&:screen, 1:text, 2:text
event-loop screen:&:screen, console:&:console, 3:&:environment
screen-should-contain [
. run (F4) .
. ┊ .
.recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. reply 4 ┊0 edit copy delete .
.] ┊foo .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊4 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
assume-console [
left-click 5, 51
]
run [
event-loop screen:&:screen, console:&:console, 3:&:environment
]
screen-should-contain-in-color 2/green, [
. .
. .
. .
. .
. .
. 4 .
. .
. .
]
run [
4:char/cursor <- copy 9251/␣
print screen:&:screen, 4:char/cursor
]
screen-should-contain [
. run (F4) .
.␣ ┊ .
.recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. reply 4 ┊0 edit copy delete .
.] ┊foo .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊4 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
. ┊ .
. ┊ .
]
assume-console [
left-click 3, 11
press backspace
type [3]
press F4
]
run [
event-loop screen:&:screen, console:&:console, 3:&:environment
]
screen-should-contain-in-color 1/red, [
. .
. .
. .
. .
. .
. 3 .
. .
. .
]
]
container sandbox [
response-starting-row-on-screen:num
expected-response:text
]
before <end-save-sandbox> [
{
expected-response:text <- get *curr, expected-response:offset
break-unless expected-response
filename <- append filename, [.out]
save filename, expected-response
}
]
before <end-restore-sandbox> [
{
filename <- append filename, [.out]
contents <- restore filename
break-unless contents
*curr <- put *curr, expected-response:offset, contents
}
]
after <global-touch> [
{
sandbox-left-margin:num <- get *current-sandbox, left:offset
click-column:num <- get t, column:offset
on-sandbox-side?:bool <- greater-or-equal click-column, sandbox-left-margin
break-unless on-sandbox-side?
first-sandbox:&:sandbox <- get *env, sandbox:offset
break-unless first-sandbox
first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset
click-row:num <- get t, row:offset
below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins
break-unless below-sandbox-editor?
sandbox:&:sandbox <- find-click-in-sandbox-output env, click-row
break-unless sandbox
sandbox <- toggle-expected-response sandbox
save-sandboxes env
hide-screen screen
screen <- render-sandbox-side screen, env, render
screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env
show-screen screen
loop +next-event:label
}
]
def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:sandbox [
local-scope
load-ingredients
sandbox:&:sandbox <- get *env, sandbox:offset
start:num <- get *sandbox, starting-row-on-screen:offset
clicked-on-sandboxes?:bool <- greater-or-equal click-row, start
assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor]
{
next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset
break-unless next-sandbox
next-start:num <- get *next-sandbox, starting-row-on-screen:offset
found?:bool <- lesser-than click-row, next-start
break-if found?
sandbox <- copy next-sandbox
loop
}
response-starting-row:num <- get *sandbox, response-starting-row-on-screen:offset
return-unless response-starting-row, 0/no-click-in-sandbox-output
click-in-response?:bool <- greater-or-equal click-row, response-starting-row
return-unless click-in-response?, 0/no-click-in-sandbox-output
return sandbox
]
def toggle-expected-response sandbox:&:sandbox -> sandbox:&:sandbox [
local-scope
load-ingredients
expected-response:text <- get *sandbox, expected-response:offset
{
break-unless expected-response
*sandbox <- put *sandbox, expected-response:offset, 0
}
{
break-if expected-response
response:text <- get *sandbox, response:offset
*sandbox <- put *sandbox, expected-response:offset, response
}
]
after <render-sandbox-response> [
{
break-unless sandbox-response
*sandbox <- put *sandbox, response-starting-row-on-screen:offset, row
expected-response:text <- get *sandbox, expected-response:offset
break-unless expected-response
response-is-expected?:bool <- equal expected-response, sandbox-response
{
break-if response-is-expected?:bool
row, screen <- render-text screen, sandbox-response, left, right, 1/red, row
}
{
break-unless response-is-expected?:bool
row, screen <- render-text screen, sandbox-response, left, right, 2/green, row
}
jump +render-sandbox-end:label
}
]
before <end-render-sandbox-reset-hidden> [
*sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0
]