recipe main [
default-space:address:array:location <- new location:type, 30:literal
open-console
width:number <- display-width
height:number <- display-height
divider:number, _ <- divide-with-remainder width:number, 2:literal
draw-vertical 0:literal/screen, divider:number, 0:literal/top, height:number
left:address:array:character <- new [abcde]
left-editor:address:editor-data <- new-editor left:address:array:character, 0:literal/screen, 0:literal/top, 0:literal/left, 5:literal/right
right:address:array:character <- new [def]
new-left:number <- add divider:number/right, 1:literal
right-editor:address:editor-data <- new-editor right:address:array:character, 0:literal/screen, 0:literal/top, new-left:number, width:number
x:address:address:editor-data <- get-address left-editor:address:editor-data/deref, next-editor:offset
x:address:address:editor-data/deref <- copy right-editor:address:editor-data
reset-focus left-editor:address:editor-data
cursor-row:number <- get left-editor:address:editor-data/deref, cursor-row:offset
cursor-column:number <- get left-editor:address:editor-data/deref, cursor-column:offset
move-cursor 0:literal/screen, cursor-row:number, cursor-column:number
event-loop 0:literal/screen, 0:literal/events, left-editor:address:editor-data
close-console
]
scenario editor-initially-prints-string-to-screen [
assume-screen 10:literal/width, 5:literal/height
run [
1:address:array:character <- new [abc]
new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
]
screen-should-contain [
.abc .
. .
]
]
container editor-data [
data:address:duplex-list
top-of-screen:address:duplex-list
before-cursor:address:duplex-list
screen:address:screen
top:number
left:number
bottom:number
right:number
cursor-row:number
cursor-column:number
next-editor:address:editor-data
in-focus?:boolean
]
recipe new-editor [
default-space:address:array:location <- new location:type, 30:literal
s:address:array:character <- next-ingredient
screen:address <- next-ingredient
top:number <- next-ingredient
left:number <- next-ingredient
right:number <- next-ingredient
right:number <- subtract right:number, 1:literal
result:address:editor-data <- new editor-data:type
sc:address:address:screen <- get-address result:address:editor-data/deref, screen:offset
sc:address:address:screen/deref <- copy screen:address
x:address:number <- get-address result:address:editor-data/deref, top:offset
x:address:number/deref <- copy top:number
x:address:number <- get-address result:address:editor-data/deref, left:offset
x:address:number/deref <- copy left:number
x:address:number <- get-address result:address:editor-data/deref, right:offset
x:address:number/deref <- copy right:number
x:address:number <- get-address result:address:editor-data/deref, bottom:offset
x:address:number/deref <- copy top:number
x:address:number <- get-address result:address:editor-data/deref, cursor-row:offset
x:address:number/deref <- copy top:number
x:address:number <- get-address result:address:editor-data/deref, cursor-column:offset
x:address:number/deref <- copy left:number
d:address:address:duplex-list <- get-address result:address:editor-data/deref, data:offset
d:address:address:duplex-list/deref <- push-duplex 167:literal/§, 0:literal/tail
y:address:address:duplex-list <- get-address result:address:editor-data/deref, before-cursor:offset
y:address:address:duplex-list/deref <- copy d:address:address:duplex-list/deref
init:address:address:duplex-list <- get-address result:address:editor-data/deref, top-of-screen:offset
init:address:address:duplex-list/deref <- copy d:address:address:duplex-list/deref
b:address:boolean <- get-address result:address:editor-data/deref, in-focus?:offset
b:address:boolean/deref <- copy 1:literal/true
reply-unless s:address:array:character, result:address:editor-data
len:number <- length s:address:array:character/deref
reply-unless len:number, result:address:editor-data
idx:number <- copy 0:literal
curr:address:duplex-list <- copy init:address:address:duplex-list/deref
{
done?:boolean <- greater-or-equal idx:number, len:number
break-if done?:boolean
c:character <- index s:address:array:character/deref, idx:number
insert-duplex c:character, curr:address:duplex-list
curr:address:duplex-list <- next-duplex curr:address:duplex-list
idx:number <- add idx:number, 1:literal
loop
}
y:address:address:duplex-list <- get-address result:address:editor-data/deref, before-cursor:offset
y:address:address:duplex-list/deref <- copy init:address:address:duplex-list/deref
bottom:address:number <- get-address result:address:editor-data/deref, bottom:offset
result:address:editor-data <- render result:address:editor-data
reply result:address:editor-data
]
scenario editor-initializes-without-data [
assume-screen 5:literal/width, 3:literal/height
run [
1:address:editor-data <- new-editor 0:literal/data, screen:address, 1:literal/top, 2:literal/left, 5:literal/right
2:editor-data <- copy 1:address:editor-data/deref
]
memory-should-contain [
6 <- 1
7 <- 2
8 <- 1
9 <- 4
10 <- 1
11 <- 2
]
screen-should-contain [
. .
. .
. .
]
]
recipe render [
default-space:address:array:location <- new location:type, 40:literal
editor:address:editor-data <- next-ingredient
screen:address <- get editor:address:editor-data/deref, screen:offset
top:number <- get editor:address:editor-data/deref, top:offset
left:number <- get editor:address:editor-data/deref, left:offset
screen-height:number <- screen-height screen:address
right:number <- get editor:address:editor-data/deref, right:offset
hide-screen screen:address
curr:address:duplex-list <- get editor:address:editor-data/deref, top-of-screen:offset
prev:address:duplex-list <- copy curr:address:duplex-list
curr:address:duplex-list <- next-duplex curr:address:duplex-list
row:number <- copy top:number
column:number <- copy left:number
cursor-row:address:number <- get-address editor:address:editor-data/deref, cursor-row:offset
cursor-column:address:number <- get-address editor:address:editor-data/deref, cursor-column:offset
before-cursor:address:address:duplex-list <- get-address editor:address:editor-data/deref, before-cursor:offset
move-cursor screen:address, row:number, column:number
{
+next-character
break-unless curr:address:duplex-list
off-screen?:boolean <- greater-or-equal row:number, screen-height:number
break-if off-screen?:boolean
{
at-cursor-row?:boolean <- equal row:number, cursor-row:address:number/deref
break-unless at-cursor-row?:boolean
at-cursor?:boolean <- equal column:number, cursor-column:address:number/deref
break-unless at-cursor?:boolean
before-cursor:address:address:duplex-list/deref <- prev-duplex curr:address:duplex-list
}
c:character <- get curr:address:duplex-list/deref, value:offset
{
newline?:boolean <- equal c:character, 10:literal/newline
break-unless newline?:boolean
{
at-cursor-row?:boolean <- equal row:number, cursor-row:address:number/deref
break-unless at-cursor-row?:boolean
left-of-cursor?:boolean <- lesser-than column:number, cursor-column:address:number/deref
break-unless left-of-cursor?:boolean
cursor-column:address:number/deref <- copy column:number
before-cursor:address:address:duplex-list/deref <- prev-duplex curr:address:duplex-list
}
{
done?:boolean <- greater-than column:number, right:number
break-if done?:boolean
print-character screen:address, 32:literal/space
column:number <- add column:number, 1:literal
loop
}
row:number <- add row:number, 1:literal
column:number <- copy left:number
move-cursor screen:address, row:number, column:number
curr:address:duplex-list <- next-duplex curr:address:duplex-list
prev:address:duplex-list <- next-duplex prev:address:duplex-list
loop +next-character:label
}
{
at-right?:boolean <- equal column:number, right:number
break-unless at-right?:boolean
next-node:address:duplex-list <- next-duplex curr:address:duplex-list
break-unless next-node:address:duplex-list
next:character <- get next-node:address:duplex-list/deref, value:offset
next-character-is-newline?:boolean <- equal next:character, 10:literal/newline
break-if next-character-is-newline?:boolean
print-character screen:address, 8617:literal/loop-back-to-left, 245:literal/grey
column:number <- copy left:number
row:number <- add row:number, 1:literal
move-cursor screen:address, row:number, column:number
loop +next-character:label
}
print-character screen:address, c:character
curr:address:duplex-list <- next-duplex curr:address:duplex-list
prev:address:duplex-list <- next-duplex prev:address:duplex-list
column:number <- add column:number, 1:literal
loop
}
bottom:address:number <- get-address editor:address:editor-data/deref, bottom:offset
bottom:address:number/deref <- copy row:number
{
at-cursor-row?:boolean <- equal row:number, cursor-row:address:number/deref
cursor-outside-line?:boolean <- lesser-or-equal column:number, cursor-column:address:number/deref
before-cursor-on-same-line?:boolean <- and at-cursor-row?:boolean, cursor-outside-line?:boolean
above-cursor-row?:boolean <- lesser-than row:number, cursor-row:address:number/deref
before-cursor?:boolean <- or before-cursor-on-same-line?:boolean, above-cursor-row?:boolean
break-unless before-cursor?:boolean
cursor-row:address:number/deref <- copy row:number
cursor-column:address:number/deref <- copy column:number
{
too-far-right?:boolean <- greater-than cursor-column:address:number/deref, right:number
break-unless too-far-right?:boolean
cursor-column:address:number/deref <- copy left:number
cursor-row:address:number/deref <- add cursor-row:address:number/deref, 1:literal
above-screen-bottom?:boolean <- lesser-than cursor-row:address:number/deref, screen-height:number
assert above-screen-bottom?:boolean, [unimplemented: wrapping cursor past bottom of screen]
}
before-cursor:address:address:duplex-list/deref <- copy prev:address:duplex-list
}
{
done?:boolean <- greater-or-equal row:number, screen-height:number
break-if done?:boolean
{
line-done?:boolean <- greater-than column:number, right:number
break-if line-done?:boolean
print-character screen:address, 32:literal/space
column:number <- add column:number, 1:literal
loop
}
row:number <- add row:number, 1:literal
column:number <- copy left:number
done?:boolean <- greater-or-equal row:number, screen-height:number
break-if done?:boolean
move-cursor screen:address, row:number, column:number
{
line-done?:boolean <- greater-or-equal column:number, right:number
break-if line-done?:boolean
print-character screen:address, 32:literal/space
column:number <- add column:number, 1:literal
loop
}
}
{
in-focus?:boolean <- get editor:address:editor-data/deref, in-focus?:offset
break-unless in-focus?:boolean
cursor-inside-right-margin?:boolean <- lesser-or-equal cursor-column:address:number/deref, right:number
assert cursor-inside-right-margin?:boolean, [cursor outside right margin]
cursor-inside-left-margin?:boolean <- greater-or-equal cursor-column:address:number/deref, left:number
assert cursor-inside-left-margin?:boolean, [cursor outside left margin]
move-cursor screen:address, cursor-row:address:number/deref, cursor-column:address:number/deref
}
show-screen screen:address
reply editor:address:editor-data/same-as-ingredient:0
]
scenario editor-initially-prints-multiple-lines [
assume-screen 5:literal/width, 3:literal/height
run [
s:address:array:character <- new [abc
def]
new-editor s:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
]
screen-should-contain [
.abc .
.def .
. .
]
]
scenario editor-initially-handles-offsets [
assume-screen 5:literal/width, 3:literal/height
run [
s:address:array:character <- new [abc]
new-editor s:address:array:character, screen:address, 0:literal/top, 1:literal/left, 5:literal/right
]
screen-should-contain [
. abc .
. .
. .
]
]
scenario editor-initially-prints-multiple-lines-at-offset [
assume-screen 5:literal/width, 3:literal/height
run [
s:address:array:character <- new [abc
def]
new-editor s:address:array:character, screen:address, 0:literal/top, 1:literal/left, 5:literal/right
]
screen-should-contain [
. abc .
. def .
. .
]
]
scenario editor-initially-wraps-long-lines [
assume-screen 5:literal/width, 3:literal/height
run [
s:address:array:character <- new [abc def]
new-editor s:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
]
screen-should-contain [
.abc ↩.
.def .
. .
]
screen-should-contain-in-color, 245:literal/grey [
. ↩.
. .
. .
]
]
scenario editor-initializes-empty-text [
assume-screen 5:literal/width, 3:literal/height
run [
1:address:array:character <- new []
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
screen-should-contain [
. .
. .
. .
]
memory-should-contain [
3 <- 0
4 <- 0
]
]
recipe event-loop [
default-space:address:array:location <- new location:type, 30:literal
screen:address <- next-ingredient
console:address <- next-ingredient
editor:address:editor-data <- next-ingredient
{
e:event, console:address, found?:boolean, quit?:boolean <- read-event console:address
loop-unless found?:boolean
break-if quit?:boolean
trace [app], [next-event]
curr:address:editor-data <- copy editor:address:editor-data
{
break-unless curr:address:editor-data
handle-event screen:address, console:address, curr:address:editor-data, e:event
curr:address:editor-data <- get curr:address:editor-data/deref, next-editor:offset
loop
}
curr:address:editor-data <- copy editor:address:editor-data
{
break-unless curr:address:editor-data
render curr:address:editor-data
curr:address:editor-data <- get curr:address:editor-data/deref, next-editor:offset
loop
}
curr:address:editor-data <- copy editor:address:editor-data
{
break-unless curr:address:editor-data
{
in-focus?:boolean <- get curr:address:editor-data/deref, in-focus?:offset
break-unless in-focus?:boolean
cursor-row:number <- get curr:address:editor-data/deref, cursor-row:offset
cursor-column:number <- get curr:address:editor-data/deref, cursor-column:offset
move-cursor screen:address, cursor-row:number, cursor-column:number
}
curr:address:editor-data <- get curr:address:editor-data/deref, next-editor:offset
loop
}
loop
}
]
recipe handle-event [
default-space:address:array:location <- new location:type, 50:literal
screen:address <- next-ingredient
console:address <- next-ingredient
editor:address:editor-data <- next-ingredient
e:event <- next-ingredient
{
t:address:touch-event <- maybe-convert e:event, touch:variant
break-unless t:address:touch-event
move-cursor-in-editor editor:address:editor-data, t:address:touch-event/deref
reply
}
in-focus?:address:boolean <- get-address editor:address:editor-data/deref, in-focus?:offset
reply-unless in-focus?:address:boolean/deref
{
c:address:character <- maybe-convert e:event, text:variant
break-unless c:address:character
{
backspace?:boolean <- equal c:address:character/deref, 8:literal/backspace
break-unless backspace?:boolean
delete-before-cursor editor:address:editor-data
reply
}
insert-at-cursor editor:address:editor-data, c:address:character/deref
reply
}
k:address:number <- maybe-convert e:event, keycode:variant
assert k:address:number, [event was of unknown type; neither keyboard nor mouse]
d:address:duplex-list <- get editor:address:editor-data/deref, data:offset
before-cursor:address:address:duplex-list <- get-address editor:address:editor-data/deref, before-cursor:offset
cursor-row:address:number <- get-address editor:address:editor-data/deref, cursor-row:offset
cursor-column:address:number <- get-address editor:address:editor-data/deref, cursor-column:offset
screen-height:number <- screen-height screen:address
top:number <- get editor:address:editor-data/deref, top:offset
{
move-to-next-character?:boolean <- equal k:address:number/deref, 65514:literal/right-arrow
break-unless move-to-next-character?:boolean
old-cursor:address:duplex-list <- next-duplex before-cursor:address:address:duplex-list/deref
break-unless old-cursor:address:duplex-list
before-cursor:address:address:duplex-list/deref <- copy old-cursor:address:duplex-list
{
old-cursor-character:character <- get before-cursor:address:address:duplex-list/deref/deref, value:offset
was-at-newline?:boolean <- equal old-cursor-character:character, 10:literal/newline
break-unless was-at-newline?:boolean
cursor-row:address:number/deref <- add cursor-row:address:number/deref, 1:literal
cursor-column:address:number/deref <- copy 0:literal
screen-height:number <- screen-height screen:address
above-screen-bottom?:boolean <- lesser-than cursor-row:address:number/deref, screen-height:number
assert above-screen-bottom?:boolean, [unimplemented: moving past bottom of screen]
reply
}
{
right:number <- get editor:address:editor-data/deref, right:offset
wrap-column:number <- subtract right:number, 1:literal
at-wrap?:boolean <- equal cursor-column:address:number/deref, wrap-column:number
break-unless at-wrap?:boolean
new-cursor:address:duplex-list <- next-duplex old-cursor:address:duplex-list
break-unless new-cursor:address:duplex-list
next:address:duplex-list <- next-duplex new-cursor:address:duplex-list
break-unless next:address:duplex-list
next-character:character <- get next:address:duplex-list/deref, value:offset
newline?:boolean <- equal next-character:character, 10:literal/newline
break-if newline?:boolean
cursor-row:address:number/deref <- add cursor-row:address:number/deref, 1:literal
cursor-column:address:number/deref <- copy 0:literal
above-screen-bottom?:boolean <- lesser-than cursor-row:address:number/deref, screen-height:number
assert above-screen-bottom?:boolean, [unimplemented: moving past bottom of screen]
reply
}
cursor-column:address:number/deref <- add cursor-column:address:number/deref, 1:literal
}
{
move-to-previous-character?:boolean <- equal k:address:number/deref, 65515:literal/left-arrow
break-unless move-to-previous-character?:boolean
prev:address:duplex-list <- prev-duplex before-cursor:address:address:duplex-list/deref
break-unless prev:address:duplex-list
{
at-left-margin?:boolean <- equal cursor-column:address:number/deref, 0:literal
break-if at-left-margin?:boolean
cursor-column:address:number/deref <- subtract cursor-column:address:number/deref, 1:literal
reply
}
{
prevc:character <- get before-cursor:address:address:duplex-list/deref/deref, value:offset
previous-character-is-newline?:boolean <- equal prevc:character, 10:literal/newline
break-unless previous-character-is-newline?:boolean
end-of-line:number <- previous-line-length before-cursor:address:address:duplex-list/deref, d:address:duplex-list
cursor-row:address:number/deref <- subtract cursor-row:address:number/deref, 1:literal
cursor-column:address:number/deref <- copy end-of-line:number
reply
}
assert cursor-row:address:number/deref, [unimplemented: moving cursor above top of screen]
cursor-row:address:number/deref <- subtract cursor-row:address:number/deref, 1:literal
right:number <- get editor:address:editor-data/deref, right:offset
cursor-column:address:number/deref <- subtract right:number, 1:literal
}
{
move-to-next-line?:boolean <- equal k:address:number/deref, 65516:literal/down-arrow
break-unless move-to-next-line?:boolean
already-at-bottom?:boolean <- greater-or-equal cursor-row:address:number/deref, screen-height:number
break-if already-at-bottom?:boolean
cursor-row:address:number/deref <- add cursor-row:address:number/deref, 1:literal
}
{
move-to-previous-line?:boolean <- equal k:address:number/deref, 65517:literal/up-arrow
break-unless move-to-previous-line?:boolean
already-at-top?:boolean <- lesser-or-equal cursor-row:address:number/deref, top:number
break-if already-at-top?:boolean
cursor-row:address:number/deref <- subtract cursor-row:address:number/deref, 1:literal
}
]
recipe move-cursor-in-editor [
default-space:address:array:location <- new location:type, 30:literal
editor:address:editor-data <- next-ingredient
t:touch-event <- next-ingredient
in-focus?:address:boolean <- get-address editor:address:editor-data/deref, in-focus?:offset
in-focus?:address:boolean/deref <- copy 0:literal/true
click-column:number <- get t:touch-event, column:offset
left:number <- get editor:address:editor-data/deref, left:offset
too-far-left?:boolean <- lesser-than click-column:number, left:number
reply-if too-far-left?:boolean
right:number <- get editor:address:editor-data/deref, right:offset
too-far-right?:boolean <- greater-than click-column:number, right:number
reply-if too-far-right?:boolean
in-focus?:address:boolean/deref <- copy 1:literal/true
cursor-row:address:number <- get-address editor:address:editor-data/deref, cursor-row:offset
cursor-row:address:number/deref <- get t:touch-event, row:offset
cursor-column:address:number <- get-address editor:address:editor-data/deref, cursor-column:offset
cursor-column:address:number/deref <- get t:touch-event, column:offset
]
recipe insert-at-cursor [
default-space:address:array:location <- new location:type, 30:literal
editor:address:editor-data <- next-ingredient
c:character <- next-ingredient
before-cursor:address:address:duplex-list <- get-address editor:address:editor-data/deref, before-cursor:offset
d:address:duplex-list <- get editor:address:editor-data/deref, data:offset
insert-duplex c:character, before-cursor:address:address:duplex-list/deref
screen:address <- get editor:address:editor-data/deref, screen:offset
cursor-row:address:number <- get-address editor:address:editor-data/deref, cursor-row:offset
cursor-column:address:number <- get-address editor:address:editor-data/deref, cursor-column:offset
{
newline?:boolean <- equal c:character, 10:literal/newline
break-unless newline?:boolean
cursor-row:address:number/deref <- add cursor-row:address:number/deref, 1:literal
cursor-column:address:number/deref <- copy 0:literal
reply
}
{
right:number <- get editor:address:editor-data/deref, right:offset
wrap-column:number <- subtract right:number, 1:literal
at-wrap?:boolean <- greater-or-equal cursor-column:address:number/deref, wrap-column:number
break-unless at-wrap?:boolean
cursor-column:address:number/deref <- subtract cursor-column:address:number/deref, wrap-column:number
cursor-row:address:number/deref <- add cursor-row:address:number/deref, 1:literal
screen-height:number <- screen-height screen:address
above-screen-bottom?:boolean <- lesser-than cursor-row:address:number/deref, screen-height:number
assert above-screen-bottom?:boolean, [unimplemented: typing past bottom of screen]
reply
}
cursor-column:address:number/deref <- add cursor-column:address:number/deref, 1:literal
]
recipe delete-before-cursor [
default-space:address:array:location <- new location:type, 30:literal
editor:address:editor-data <- next-ingredient
before-cursor:address:address:duplex-list <- get-address editor:address:editor-data/deref, before-cursor:offset
d:address:duplex-list <- get editor:address:editor-data/deref, data:offset
at-start?:boolean <- equal before-cursor:address:address:duplex-list/deref, d:address:duplex-list
reply-if at-start?:boolean
prev:address:duplex-list <- prev-duplex before-cursor:address:address:duplex-list/deref
remove-duplex before-cursor:address:address:duplex-list/deref
before-cursor:address:address:duplex-list/deref <- copy prev:address:duplex-list
cursor-column:address:number <- get-address editor:address:editor-data/deref, cursor-column:offset
cursor-column:address:number/deref <- subtract cursor-column:address:number/deref, 1:literal
]
recipe previous-line-length [
default-space:address:array:location <- new location:type, 30:literal
curr:address:duplex-list <- next-ingredient
start:address:duplex-list <- next-ingredient
result:number <- copy 0:literal
reply-unless curr:address:duplex-list, result:number
at-start?:boolean <- equal curr:address:duplex-list, start:address:duplex-list
reply-if at-start?:boolean, result:number
{
curr:address:duplex-list <- prev-duplex curr:address:duplex-list
break-unless curr:address:duplex-list
at-start?:boolean <- equal curr:address:duplex-list, start:address:duplex-list
break-if at-start?:boolean
c:character <- get curr:address:duplex-list/deref, value:offset
at-newline?:boolean <- equal c:character 10:literal/newline
break-if at-newline?:boolean
result:number <- add result:number, 1:literal
loop
}
reply result:number
]
scenario editor-handles-empty-event-queue [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console []
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.abc .
. .
]
]
scenario editor-handles-mouse-clicks [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 0, 1
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
screen-should-contain [
.abc .
. .
]
memory-should-contain [
3 <- 0
4 <- 1
]
]
scenario editor-handles-mouse-clicks-outside-text [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 0, 7
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
memory-should-contain [
3 <- 0
4 <- 3
]
]
scenario editor-handles-mouse-clicks-outside-text-2 [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc
def]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 0, 7
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
memory-should-contain [
3 <- 0
4 <- 3
]
]
scenario editor-handles-mouse-clicks-outside-text-3 [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc
def]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 2, 7
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
memory-should-contain [
3 <- 1
4 <- 3
]
]
scenario editor-handles-mouse-clicks-outside-column [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
assume-console [
left-click 3, 8
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
screen-should-contain [
.abc .
. .
]
memory-should-contain [
3 <- 0
4 <- 0
]
]
scenario editor-inserts-characters-into-empty-editor [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new []
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
assume-console [
type [abc]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.abc .
. .
]
]
scenario editor-inserts-characters-at-cursor [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
type [0]
left-click 0, 2
type [d]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.0adbc .
. .
]
]
scenario editor-inserts-characters-at-cursor-2 [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 0, 5
type [d]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.abcd .
. .
]
]
scenario editor-inserts-characters-at-cursor-3 [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 3, 5
type [d]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.abcd .
. .
]
]
scenario editor-inserts-characters-at-cursor-4 [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc
d]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 3, 5
type [e]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.abc .
.de .
. .
]
]
scenario editor-inserts-characters-at-cursor-5 [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc
d]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 3, 5
type [ef]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.abc .
.def .
. .
]
]
scenario editor-inserts-characters-at-cursor-6 [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abcde]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
assume-console [
left-click 3, 0
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
screen-should-contain [
.abcde .
. .
]
memory-should-contain [
3 <- 1
4 <- 0
]
]
scenario editor-wraps-line-on-insert [
assume-screen 5:literal/width, 3:literal/height
1:address:array:character <- new [abcd]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
assume-console [
type [e]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.eabcd.
. .
]
assume-console [
type [f]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.efab↩.
.cd .
. .
]
]
scenario editor-moves-cursor-after-inserting-characters [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
assume-console [
type [01]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.01abc .
. .
]
]
scenario editor-wraps-cursor-after-inserting-characters [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abcde]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
assume-console [
left-click 0, 4
type [f]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
screen-should-contain [
.abcd↩ .
.fe .
. .
]
memory-should-contain [
3 <- 1
4 <- 1
]
]
scenario editor-wraps-cursor-after-inserting-characters-2 [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abcde]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
assume-console [
left-click 0, 3
type [f]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
screen-should-contain [
.abcf↩ .
.de .
. .
]
memory-should-contain [
3 <- 1
4 <- 0
]
]
scenario editor-moves-cursor-down-after-inserting-newline [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
type [0
1]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.0 .
.1abc .
. .
]
]
scenario editor-clears-previous-line-completely-after-inserting-newline [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abcde]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
assume-console [
type [
]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
. .
.abcde .
. .
]
]
scenario editor-handles-backspace-key [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 0, 1
type [«]
]
3:event/backspace <- merge 0:literal/text, 8:literal/backspace, 0:literal/dummy, 0:literal/dummy
replace-in-console 171:literal/«, 3:event/backspace
run [
event-loop screen:address, console:address, 2:address:editor-data
4:number <- get 2:address:editor-data/deref, cursor-row:offset
5:number <- get 2:address:editor-data/deref, cursor-column:offset
]
screen-should-contain [
.bc .
. .
]
memory-should-contain [
4 <- 0
5 <- 0
]
]
scenario editor-clears-last-line-on-backspace [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc
d]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
assume-console [
left-click 1, 0
type [«]
]
3:event/backspace <- merge 0:literal/text, 8:literal/backspace, 0:literal/dummy, 0:literal/dummy
replace-in-console 171:literal/«, 3:event/backspace
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.abcd .
. .
]
]
scenario editor-handles-backspace-key-at-right-margin [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abcde]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
assume-console [
left-click 1, 3
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
memory-should-contain [
3 <- 1
4 <- 0
]
assume-console [
type [«]
]
5:event/backspace <- merge 0:literal/text, 8:literal/backspace, 0:literal/dummy, 0:literal/dummy
replace-in-console 171:literal/«, 5:event/backspace
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
memory-should-contain [
3 <- 0
4 <- 4
]
screen-should-contain [
.abcd .
. .
]
]
scenario editor-moves-cursor-right-with-key [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
press 65514
type [0]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.a0bc .
. .
]
]
scenario editor-moves-cursor-to-next-line-with-right-arrow [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc
d]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
press 65514
press 65514
press 65514
press 65514
type [0]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.abc .
.0d .
. .
]
]
scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abcdef]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
assume-console [
left-click 0, 3
press 65514
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
screen-should-contain [
.abcd↩ .
.ef .
. .
]
memory-should-contain [
3 <- 1
4 <- 0
]
]
scenario editor-does-not-wrap-cursor-when-line-does-not-wrap [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abcde]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
assume-console [
left-click 0, 3
press 65514
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
memory-should-contain [
3 <- 0
4 <- 4
]
]
scenario editor-does-not-wrap-cursor-when-line-does-not-wrap-2 [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abcde
f]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
assume-console [
left-click 0, 3
press 65514
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
memory-should-contain [
3 <- 0
4 <- 4
]
]
scenario editor-moves-cursor-to-next-line-with-right-arrow-at-end-of-line [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc
d]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 0, 3
press 65514
type [0]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.abc .
.0d .
. .
]
]
scenario editor-moves-cursor-left-with-key [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 0, 2
press 65515
type [0]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.a0bc .
. .
]
]
scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc
d]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 1, 0
press 65515
type [0]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.abc0 .
.d .
. .
]
]
scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-2 [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc
def
g]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 2, 0
press 65515
type [0]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.abc .
.def0 .
.g .
. .
]
]
scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-3 [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc
def
g]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 0, 0
press 65515
type [0]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.0abc .
.def .
.g .
. .
]
]
scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-4 [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc
d]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 2, 0
press 65515
type [0]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
]
screen-should-contain [
.abc .
.0 .
.d .
. .
]
]
scenario editor-moves-across-screen-lines-across-wrap-with-left-arrow [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abcdef]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
screen-should-contain [
.abcd↩ .
.ef .
. .
]
assume-console [
left-click 1, 0
press 65515
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
memory-should-contain [
3 <- 0
4 <- 3
]
]
scenario editor-moves-to-previous-line-with-up-arrow [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc
def]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 1, 1
press 65517
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
memory-should-contain [
3 <- 0
4 <- 1
]
]
scenario editor-moves-to-next-line-with-down-arrow [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc
def]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
press 65516
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
memory-should-contain [
3 <- 1
4 <- 0
]
]
scenario editor-adjusts-column-at-previous-line [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [ab
def]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 1, 3
press 65517
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
memory-should-contain [
3 <- 0
4 <- 2
]
]
scenario editor-adjusts-column-at-next-line [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc
de]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
assume-console [
left-click 0, 3
press 65516
]
run [
event-loop screen:address, console:address, 2:address:editor-data
3:number <- get 2:address:editor-data/deref, cursor-row:offset
4:number <- get 2:address:editor-data/deref, cursor-column:offset
]
memory-should-contain [
3 <- 1
4 <- 2
]
]
scenario point-at-multiple-editors [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
3:address:array:character <- new [def]
4:address:address:editor-data <- get-address 2:address:editor-data/deref, next-editor:offset
4:address:address:editor-data/deref <- new-editor 3:address:array:character, screen:address, 0:literal/top, 5:literal/left, 10:literal/right
assume-console [
left-click 0, 1
left-click 0, 8
]
run [
event-loop screen:address, console:address, 2:address:editor-data
5:number <- get 2:address:editor-data/deref, cursor-column:offset
6:number <- get 4:address:address:editor-data/deref/deref, cursor-column:offset
]
memory-should-contain [
5 <- 1
6 <- 8
]
]
scenario editors-chain-to-cover-multiple-columns [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
3:address:array:character <- new [def]
4:address:address:editor-data <- get-address 2:address:editor-data/deref, next-editor:offset
4:address:address:editor-data/deref <- new-editor 3:address:array:character, screen:address, 0:literal/top, 5:literal/left, 10:literal/right
reset-focus 2:address:editor-data
assume-console [
left-click 0, 1
type [0]
left-click 0, 6
type [1]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
5:number <- get 2:address:editor-data/deref, cursor-column:offset
6:number <- get 4:address:address:editor-data/deref/deref, cursor-column:offset
]
screen-should-contain [
.a0bc d1ef .
. .
]
memory-should-contain [
5 <- 2
6 <- 7
]
run [
screen:address <- print-character screen:address, 9251:literal/␣
]
screen-should-contain [
.a0bc d1␣f .
. .
]
]
scenario multiple-editors-cover-only-their-own-areas [
assume-screen 10:literal/width, 5:literal/height
run [
draw-vertical screen:address, 5:literal/divider, 0:literal/top, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
3:address:array:character <- new [def]
4:address:address:editor-data <- get-address 2:address:editor-data/deref, next-editor:offset
4:address:address:editor-data/deref <- new-editor 3:address:array:character, screen:address, 0:literal/top, 6:literal/left, 10:literal/right
]
screen-should-contain [
.abc │def .
. │ .
. │ .
. │ .
. │ .
]
]
scenario editor-in-focus-keeps-cursor [
assume-screen 10:literal/width, 5:literal/height
1:address:array:character <- new [abc]
2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
3:address:array:character <- new [def]
4:address:address:editor-data <- get-address 2:address:editor-data/deref, next-editor:offset
4:address:address:editor-data/deref <- new-editor 3:address:array:character, screen:address, 0:literal/top, 5:literal/left, 10:literal/right
run [
reset-focus 2:address:editor-data
5:number <- get 2:address:editor-data/deref, cursor-row:offset
6:number <- get 2:address:editor-data/deref, cursor-column:offset
move-cursor screen:address, 5:number, 6:number
screen:address <- print-character screen:address, 9251:literal/␣
]
screen-should-contain [
.␣bc def .
. .
]
assume-console [
type [z]
]
run [
event-loop screen:address, console:address, 2:address:editor-data
screen:address <- print-character screen:address, 9251:literal/␣
]
screen-should-contain [
.z␣bc def .
. .
]
]
recipe reset-focus [
default-space:address:array:location <- new location:type, 30:literal
editor:address:editor-data <- next-ingredient
in-focus:address:boolean <- get-address editor:address:editor-data/deref, in-focus?:offset
in-focus:address:boolean/deref <- copy 1:literal/true
e:address:editor-data <- get editor:address:editor-data/deref, next-editor:offset
{
break-unless e:address:editor-data
x:address:boolean <- get-address e:address:editor-data/deref, in-focus?:offset
x:address:boolean/deref <- copy 0:literal/false
e:address:editor-data <- get e:address:editor-data/deref, next-editor:offset
loop
}
]
recipe draw-box [
default-space:address:array:location <- new location:type, 30:literal
screen:address <- next-ingredient
top:number <- next-ingredient
left:number <- next-ingredient
bottom:number <- next-ingredient
right:number <- next-ingredient
color:number, color-found?:boolean <- next-ingredient
{
break-if color-found?:boolean
color:number <- copy 245:literal/grey
}
draw-horizontal screen:address, top:number, left:number, right:number, color:number
draw-horizontal screen:address, bottom:number, left:number, right:number, color:number
draw-vertical screen:address, left:number, top:number, bottom:number, color:number
draw-vertical screen:address, right:number, top:number, bottom:number, color:number
draw-top-left screen:address, top:number, left:number, color:number
draw-top-right screen:address, top:number, right:number, color:number
draw-bottom-left screen:address, bottom:number, left:number, color:number
draw-bottom-right screen:address, bottom:number, right:number, color:number
move-cursor screen:address, top:number, left:number
cursor-down screen:address
cursor-right screen:address
]
recipe draw-horizontal [
default-space:address:array:location <- new location:type, 30:literal
screen:address <- next-ingredient
row:number <- next-ingredient
x:number <- next-ingredient
right:number <- next-ingredient
color:number, color-found?:boolean <- next-ingredient
{
break-if color-found?:boolean
color:number <- copy 245:literal/grey
}
move-cursor screen:address, row:number, x:number
{
continue?:boolean <- lesser-than x:number, right:number
break-unless continue?:boolean
print-character screen:address, 9472:literal/horizontal, color:number
x:number <- add x:number, 1:literal
loop
}
]
recipe draw-vertical [
default-space:address:array:location <- new location:type, 30:literal
screen:address <- next-ingredient
col:number <- next-ingredient
x:number <- next-ingredient
bottom:number <- next-ingredient
color:number, color-found?:boolean <- next-ingredient
{
break-if color-found?:boolean
color:number <- copy 245:literal/grey
}
{
continue?:boolean <- lesser-than x:number, bottom:number
break-unless continue?:boolean
move-cursor screen:address, x:number, col:number
print-character screen:address, 9474:literal/vertical, color:number
x:number <- add x:number, 1:literal
loop
}
]
recipe draw-top-left [
default-space:address:array:location <- new location:type, 30:literal
screen:address <- next-ingredient
top:number <- next-ingredient
left:number <- next-ingredient
color:number, color-found?:boolean <- next-ingredient
{
break-if color-found?:boolean
color:number <- copy 245:literal/grey
}
move-cursor screen:address, top:number, left:number
print-character screen:address, 9484:literal/down-right, color:number
]
recipe draw-top-right [
default-space:address:array:location <- new location:type, 30:literal
screen:address <- next-ingredient
top:number <- next-ingredient
right:number <- next-ingredient
color:number, color-found?:boolean <- next-ingredient
{
break-if color-found?:boolean
color:number <- copy 245:literal/grey
}
move-cursor screen:address, top:number, right:number
print-character screen:address, 9488:literal/down-left, color:number
]
recipe draw-bottom-left [
default-space:address:array:location <- new location:type, 30:literal
screen:address <- next-ingredient
bottom:number <- next-ingredient
left:number <- next-ingredient
color:number, color-found?:boolean <- next-ingredient
{
break-if color-found?:boolean
color:number <- copy 245:literal/grey
}
move-cursor screen:address, bottom:number, left:number
print-character screen:address, 9492:literal/up-right, color:number
]
recipe draw-bottom-right [
default-space:address:array:location <- new location:type, 30:literal
screen:address <- next-ingredient
bottom:number <- next-ingredient
right:number <- next-ingredient
color:number, color-found?:boolean <- next-ingredient
{
break-if color-found?:boolean
color:number <- copy 245:literal/grey
}
move-cursor screen:address, bottom:number, right:number
print-character screen:address, 9496:literal/up-left, color:number
]