From f344b250f6f062a1a1902bf69b23ebf9b565de0e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2016 15:01:51 -0700 Subject: 3395 --- html/edit/002-typing.mu.html | 416 +++++++++++++++++++++---------------------- 1 file changed, 208 insertions(+), 208 deletions(-) (limited to 'html/edit/002-typing.mu.html') diff --git a/html/edit/002-typing.mu.html b/html/edit/002-typing.mu.html index bba168f6..815f5fab 100644 --- a/html/edit/002-typing.mu.html +++ b/html/edit/002-typing.mu.html @@ -41,26 +41,26 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients open-console - editor:address:editor-data <- new-editor text, 0/screen, 5/left, 45/right + editor:&:editor-data <- new-editor text, 0/screen, 5/left, 45/right editor-event-loop 0/screen, 0/console, editor close-console ] -def editor-event-loop screen:address:screen, console:address:console, editor:address:editor-data -> screen:address:screen, console:address:console, editor:address:editor-data [ +def editor-event-loop screen:&:screen, console:&:console, editor:&:editor-data -> screen:&:screen, console:&:console, editor:&:editor-data [ local-scope load-ingredients { # looping over each (keyboard or touch) event as it occurs +next-event - cursor-row:number <- get *editor, cursor-row:offset - cursor-column:number <- get *editor, cursor-column:offset + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset screen <- move-cursor screen, cursor-row, cursor-column - e:event, console:address:console, found?:boolean, quit?:boolean <- read-event console + e:event, console:&:console, found?:bool, quit?:bool <- read-event console loop-unless found? break-if quit? # only in tests trace 10, [app], [next-event] # 'touch' event - t:touch-event, is-touch?:boolean <- maybe-convert e, touch:variant + t:touch-event, is-touch?:bool <- maybe-convert e, touch:variant { break-unless is-touch? move-cursor-in-editor screen, editor, t @@ -69,7 +69,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # keyboard events { break-if is-touch? - screen, editor, go-render?:boolean <- handle-keyboard-event screen, editor, e + screen, editor, go-render?:bool <- handle-keyboard-event screen, editor, e { break-unless go-render? screen <- editor-render screen, editor @@ -80,23 +80,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # process click, return if it was on current editor -def move-cursor-in-editor screen:address:screen, editor:address:editor-data, t:touch-event -> in-focus?:boolean, editor:address:editor-data [ +def move-cursor-in-editor screen:&:screen, editor:&:editor-data, t:touch-event -> in-focus?:bool, editor:&:editor-data [ local-scope load-ingredients return-unless editor, 0/false - click-row:number <- get t, row:offset + click-row:num <- get t, row:offset return-unless click-row, 0/false # ignore clicks on 'menu' - click-column:number <- get t, column:offset - left:number <- get *editor, left:offset - too-far-left?:boolean <- lesser-than click-column, left + click-column:num <- get t, column:offset + left:num <- get *editor, left:offset + too-far-left?:bool <- lesser-than click-column, left return-if too-far-left?, 0/false - right:number <- get *editor, right:offset - too-far-right?:boolean <- greater-than click-column, right + right:num <- get *editor, right:offset + too-far-right?:bool <- greater-than click-column, right return-if too-far-right?, 0/false # position cursor <move-cursor-begin> editor <- snap-cursor screen, editor, click-row, click-column - undo-coalesce-tag:number <- copy 0/never + undo-coalesce-tag:num <- copy 0/never <move-cursor-end> # gain focus return 1/true @@ -105,50 +105,50 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # Variant of 'render' that only moves the cursor (coordinates and # before-cursor). If it's past the end of a line, it 'slides' it left. If it's # past the last line it positions at end of last line. -def snap-cursor screen:address:screen, editor:address:editor-data, target-row:number, target-column:number -> editor:address:editor-data [ +def snap-cursor screen:&:screen, editor:&:editor-data, target-row:num, target-column:num -> editor:&:editor-data [ local-scope load-ingredients return-unless editor - left:number <- get *editor, left:offset - right:number <- get *editor, right:offset - screen-height:number <- screen-height screen + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + screen-height:num <- screen-height screen # count newlines until screen row - curr:address:duplex-list:character <- get *editor, top-of-screen:offset - prev:address:duplex-list:character <- copy curr # just in case curr becomes null and we can't compute prev + curr:&:duplex-list:char <- get *editor, top-of-screen:offset + prev:&:duplex-list:char <- copy curr # just in case curr becomes null and we can't compute prev curr <- next curr - row:number <- copy 1/top - column:number <- copy left + row:num <- copy 1/top + column:num <- copy left *editor <- put *editor, cursor-row:offset, target-row - cursor-row:number <- copy target-row + cursor-row:num <- copy target-row *editor <- put *editor, cursor-column:offset, target-column - cursor-column:number <- copy target-column - before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + cursor-column:num <- copy target-column + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset { +next-character break-unless curr - off-screen?:boolean <- greater-or-equal row, screen-height + off-screen?:bool <- greater-or-equal row, screen-height break-if off-screen? # update editor-data.before-cursor # Doing so at the start of each iteration ensures it stays one step behind # the current character. { - at-cursor-row?:boolean <- equal row, cursor-row + at-cursor-row?:bool <- equal row, cursor-row break-unless at-cursor-row? - at-cursor?:boolean <- equal column, cursor-column + at-cursor?:bool <- equal column, cursor-column break-unless at-cursor? before-cursor <- copy prev *editor <- put *editor, before-cursor:offset, before-cursor } - c:character <- get *curr, value:offset + c:char <- get *curr, value:offset { # newline? move to left rather than 0 - newline?:boolean <- equal c, 10/newline + newline?:bool <- equal c, 10/newline break-unless newline? # adjust cursor if necessary { - at-cursor-row?:boolean <- equal row, cursor-row + at-cursor-row?:bool <- equal row, cursor-row break-unless at-cursor-row? - left-of-cursor?:boolean <- lesser-than column, cursor-column + left-of-cursor?:bool <- lesser-than column, cursor-column break-unless left-of-cursor? cursor-column <- copy column *editor <- put *editor, cursor-column:offset, cursor-column @@ -165,7 +165,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color { # at right? wrap. even if there's only one more letter left; we need # room for clicking on the cursor after it. - at-right?:boolean <- equal column, right + at-right?:bool <- equal column, right break-unless at-right? column <- copy left row <- add row, 1 @@ -179,11 +179,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color } # is cursor to the right of the last line? move to end { - at-cursor-row?:boolean <- equal row, cursor-row - cursor-outside-line?:boolean <- lesser-or-equal column, cursor-column - before-cursor-on-same-line?:boolean <- and at-cursor-row?, cursor-outside-line? - above-cursor-row?:boolean <- lesser-than row, cursor-row - before-cursor?:boolean <- or before-cursor-on-same-line?, above-cursor-row? + at-cursor-row?:bool <- equal row, cursor-row + cursor-outside-line?:bool <- lesser-or-equal column, cursor-column + before-cursor-on-same-line?:bool <- and at-cursor-row?, cursor-outside-line? + above-cursor-row?:bool <- lesser-than row, cursor-row + before-cursor?:bool <- or before-cursor-on-same-line?, above-cursor-row? break-unless before-cursor? cursor-row <- copy row *editor <- put *editor, cursor-row:offset, cursor-row @@ -196,39 +196,39 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # Process an event 'e' and try to minimally update the screen. # Set 'go-render?' to true to indicate the caller must perform a non-minimal update. -def handle-keyboard-event screen:address:screen, editor:address:editor-data, e:event -> screen:address:screen, editor:address:editor-data, go-render?:boolean [ +def handle-keyboard-event screen:&:screen, editor:&:editor-data, e:event -> screen:&:screen, editor:&:editor-data, go-render?:bool [ local-scope load-ingredients go-render? <- copy 0/false return-unless editor - screen-width:number <- screen-width screen - screen-height:number <- screen-height screen - left:number <- get *editor, left:offset - right:number <- get *editor, right:offset - before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset - cursor-row:number <- get *editor, cursor-row:offset - cursor-column:number <- get *editor, cursor-column:offset - save-row:number <- copy cursor-row - save-column:number <- copy cursor-column + screen-width:num <- screen-width screen + screen-height:num <- screen-height screen + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + save-row:num <- copy cursor-row + save-column:num <- copy cursor-column # character { - c:character, is-unicode?:boolean <- maybe-convert e, text:variant + c:char, is-unicode?:bool <- maybe-convert e, text:variant break-unless is-unicode? trace 10, [app], [handle-keyboard-event: special character] # exceptions for special characters go here <handle-special-character> # ignore any other special characters - regular-character?:boolean <- greater-or-equal c, 32/space + regular-character?:bool <- greater-or-equal c, 32/space go-render? <- copy 0/false return-unless regular-character? # otherwise type it in <insert-character-begin> - editor, screen, go-render?:boolean <- insert-at-cursor editor, c, screen + editor, screen, go-render?:bool <- insert-at-cursor editor, c, screen <insert-character-end> return } # special key to modify the text or move the cursor - k:number, is-keycode?:boolean <- maybe-convert e:event, keycode:variant + k:num, is-keycode?:bool <- maybe-convert e:event, keycode:variant assert is-keycode?, [event was of unknown type; neither keyboard nor mouse] # handlers for each special key will go here <handle-special-key> @@ -236,35 +236,35 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color return ] -def insert-at-cursor editor:address:editor-data, c:character, screen:address:screen -> editor:address:editor-data, screen:address:screen, go-render?:boolean [ +def insert-at-cursor editor:&:editor-data, c:char, screen:&:screen -> editor:&:editor-data, screen:&:screen, go-render?:bool [ local-scope load-ingredients - before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset insert c, before-cursor before-cursor <- next before-cursor *editor <- put *editor, before-cursor:offset, before-cursor - cursor-row:number <- get *editor, cursor-row:offset - cursor-column:number <- get *editor, cursor-column:offset - left:number <- get *editor, left:offset - right:number <- get *editor, right:offset - save-row:number <- copy cursor-row - save-column:number <- copy cursor-column - screen-width:number <- screen-width screen - screen-height:number <- screen-height screen + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + save-row:num <- copy cursor-row + save-column:num <- copy cursor-column + screen-width:num <- screen-width screen + screen-height:num <- screen-height screen # occasionally we'll need to mess with the cursor <insert-character-special-case> # but mostly we'll just move the cursor right cursor-column <- add cursor-column, 1 *editor <- put *editor, cursor-column:offset, cursor-column - next:address:duplex-list:character <- next before-cursor + next:&:duplex-list:char <- next before-cursor { # at end of all text? no need to scroll? just print the character and leave - at-end?:boolean <- equal next, 0/null + at-end?:bool <- equal next, 0/null break-unless at-end? - bottom:number <- subtract screen-height, 1 - at-bottom?:boolean <- equal save-row, bottom - at-right?:boolean <- equal save-column, right - overflow?:boolean <- and at-bottom?, at-right? + bottom:num <- subtract screen-height, 1 + at-bottom?:bool <- equal save-row, bottom + at-right?:bool <- equal save-column, right + overflow?:bool <- and at-bottom?, at-right? break-if overflow? move-cursor screen, save-row, save-column print screen, c @@ -274,20 +274,20 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color { # not at right margin? print the character and rest of line break-unless next - at-right?:boolean <- greater-or-equal cursor-column, screen-width + at-right?:bool <- greater-or-equal cursor-column, screen-width break-if at-right? - curr:address:duplex-list:character <- copy before-cursor + curr:&:duplex-list:char <- copy before-cursor move-cursor screen, save-row, save-column - curr-column:number <- copy save-column + curr-column:num <- copy save-column { # hit right margin? give up and let caller render go-render? <- copy 1/true - at-right?:boolean <- greater-than curr-column, right + at-right?:bool <- greater-than curr-column, right return-if at-right? break-unless curr # newline? done. - currc:character <- get *curr, value:offset - at-newline?:boolean <- equal currc, 10/newline + currc:char <- get *curr, value:offset + at-newline?:bool <- equal currc, 10/newline break-if at-newline? print screen, currc curr-column <- add curr-column, 1 @@ -302,12 +302,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # helper for tests -def editor-render screen:address:screen, editor:address:editor-data -> screen:address:screen, editor:address:editor-data [ +def editor-render screen:&:screen, editor:&:editor-data -> screen:&:screen, editor:&:editor-data [ local-scope load-ingredients - left:number <- get *editor, left:offset - right:number <- get *editor, right:offset - row:number, column:number <- render screen, editor + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + row:num, column:num <- render screen, editor clear-line-until screen, right row <- add row, 1 draw-horizontal screen, row, left, right, 9480/horizontal-dotted @@ -318,11 +318,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-handles-empty-event-queue [ assume-screen 10/width, 5/height 1:text <- new [abc] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 10/right - editor-render screen, 2:address:editor-data + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 10/right + editor-render screen, 2:&:editor-data assume-console [] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data ] screen-should-contain [ . . @@ -335,16 +335,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-handles-mouse-clicks [ assume-screen 10/width, 5/height 1:text <- new [abc] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 10/right - editor-render screen, 2:address:editor-data + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 10/right + editor-render screen, 2:&:editor-data $clear-trace assume-console [ left-click 1, 1 # on the 'b' ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data - 3:number <- get *2:address:editor-data, cursor-row:offset - 4:number <- get *2:address:editor-data, cursor-column:offset + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data + 3:num <- get *2:&:editor-data, cursor-row:offset + 4:num <- get *2:&:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -362,15 +362,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-handles-mouse-clicks-outside-text [ assume-screen 10/width, 5/height 1:text <- new [abc] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 10/right + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 10/right $clear-trace assume-console [ left-click 1, 7 # last line, to the right of text ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data - 3:number <- get *2:address:editor-data, cursor-row:offset - 4:number <- get *2:address:editor-data, cursor-column:offset + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data + 3:num <- get *2:&:editor-data, cursor-row:offset + 4:num <- get *2:&:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 # cursor row @@ -383,15 +383,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color assume-screen 10/width, 5/height 1:text <- new [abc def] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 10/right + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 10/right $clear-trace assume-console [ left-click 1, 7 # interior line, to the right of text ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data - 3:number <- get *2:address:editor-data, cursor-row:offset - 4:number <- get *2:address:editor-data, cursor-column:offset + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data + 3:num <- get *2:&:editor-data, cursor-row:offset + 4:num <- get *2:&:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 # cursor row @@ -404,15 +404,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color assume-screen 10/width, 5/height 1:text <- new [abc def] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 10/right + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 10/right $clear-trace assume-console [ left-click 3, 7 # below text ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data - 3:number <- get *2:address:editor-data, cursor-row:offset - 4:number <- get *2:address:editor-data, cursor-column:offset + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data + 3:num <- get *2:&:editor-data, cursor-row:offset + 4:num <- get *2:&:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 # cursor row @@ -425,17 +425,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color assume-screen 10/width, 5/height 1:text <- new [abc] # editor occupies only left half of screen - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 5/right - editor-render screen, 2:address:editor-data + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 5/right + editor-render screen, 2:&:editor-data $clear-trace assume-console [ # click on right half of screen left-click 3, 8 ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data - 3:number <- get *2:address:editor-data, cursor-row:offset - 4:number <- get *2:address:editor-data, cursor-column:offset + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data + 3:num <- get *2:&:editor-data, cursor-row:offset + 4:num <- get *2:&:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -453,17 +453,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-handles-mouse-clicks-in-menu-area [ assume-screen 10/width, 5/height 1:text <- new [abc] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 5/right - editor-render screen, 2:address:editor-data + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 5/right + editor-render screen, 2:&:editor-data $clear-trace assume-console [ # click on first, 'menu' row left-click 0, 3 ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data - 3:number <- get *2:address:editor-data, cursor-row:offset - 4:number <- get *2:address:editor-data, cursor-column:offset + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data + 3:num <- get *2:&:editor-data, cursor-row:offset + 4:num <- get *2:&:editor-data, cursor-column:offset ] # no change to cursor memory-should-contain [ @@ -475,14 +475,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-inserts-characters-into-empty-editor [ assume-screen 10/width, 5/height 1:text <- new [] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 5/right - editor-render screen, 2:address:editor-data + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 5/right + editor-render screen, 2:&:editor-data $clear-trace assume-console [ type [abc] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data ] screen-should-contain [ . . @@ -496,8 +496,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-inserts-characters-at-cursor [ assume-screen 10/width, 5/height 1:text <- new [abc] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 10/right - editor-render screen, 2:address:editor-data + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 10/right + editor-render screen, 2:&:editor-data $clear-trace # type two letters at different places assume-console [ @@ -506,7 +506,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color type [d] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data ] screen-should-contain [ . . @@ -520,15 +520,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-inserts-characters-at-cursor-2 [ assume-screen 10/width, 5/height 1:text <- new [abc] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 10/right - editor-render screen, 2:address:editor-data + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 10/right + editor-render screen, 2:&:editor-data $clear-trace assume-console [ left-click 1, 5 # right of last line type [d] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data ] screen-should-contain [ . . @@ -543,15 +543,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color assume-screen 10/width, 5/height 1:text <- new [abc d] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 10/right - editor-render screen, 2:address:editor-data + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 10/right + editor-render screen, 2:&:editor-data $clear-trace assume-console [ left-click 1, 5 # right of non-last line type [e] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data ] screen-should-contain [ . . @@ -566,15 +566,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-inserts-characters-at-cursor-3 [ assume-screen 10/width, 5/height 1:text <- new [abc] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 10/right - editor-render screen, 2:address:editor-data + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 10/right + editor-render screen, 2:&:editor-data $clear-trace assume-console [ left-click 3, 5 # below all text type [d] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data ] screen-should-contain [ . . @@ -589,15 +589,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color assume-screen 10/width, 5/height 1:text <- new [abc d] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 10/right - editor-render screen, 2:address:editor-data + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 10/right + editor-render screen, 2:&:editor-data $clear-trace assume-console [ left-click 3, 5 # below all text type [e] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data ] screen-should-contain [ . . @@ -613,15 +613,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color assume-screen 10/width, 5/height 1:text <- new [abc d] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 10/right - editor-render screen, 2:address:editor-data + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 10/right + editor-render screen, 2:&:editor-data $clear-trace assume-console [ left-click 3, 5 # below all text type [ef] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data ] screen-should-contain [ . . @@ -636,13 +636,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-moves-cursor-after-inserting-characters [ assume-screen 10/width, 5/height 1:text <- new [ab] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 5/right - editor-render screen, 2:address:editor-data + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 5/right + editor-render screen, 2:&:editor-data assume-console [ type [01] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data ] screen-should-contain [ . . @@ -657,14 +657,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-wraps-line-on-insert [ assume-screen 5/width, 5/height 1:text <- new [abc] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 5/right - editor-render screen, 2:address:editor-data + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 5/right + editor-render screen, 2:&:editor-data # type a letter assume-console [ type [e] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data ] # no wrap yet screen-should-contain [ @@ -679,7 +679,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color type [f] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data ] # now wrap screen-should-contain [ @@ -696,17 +696,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color assume-screen 10/width, 5/height 1:text <- new [abcdefg defg] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 5/right - editor-render screen, 2:address:editor-data + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 5/right + editor-render screen, 2:&:editor-data # type more text at the start assume-console [ left-click 3, 0 type [abc] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data - 3:number <- get *2:address:editor-data, cursor-row:offset - 4:number <- get *2:address:editor-data, cursor-column:offset + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data + 3:num <- get *2:&:editor-data, cursor-row:offset + 4:num <- get *2:&:editor-data, cursor-column:offset ] # cursor is not wrapped memory-should-contain [ @@ -729,26 +729,26 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # if either: # a) we're at the end of the line and at the column of the wrap indicator, or # b) we're not at end of line and just before the column of the wrap indicator - wrap-column:number <- copy right - before-wrap-column:number <- subtract wrap-column, 1 - at-wrap?:boolean <- greater-or-equal cursor-column, wrap-column - just-before-wrap?:boolean <- greater-or-equal cursor-column, before-wrap-column - next:address:duplex-list:character <- next before-cursor + wrap-column:num <- copy right + before-wrap-column:num <- subtract wrap-column, 1 + at-wrap?:bool <- greater-or-equal cursor-column, wrap-column + just-before-wrap?:bool <- greater-or-equal cursor-column, before-wrap-column + next:&:duplex-list:char <- next before-cursor # at end of line? next == 0 || next.value == 10/newline - at-end-of-line?:boolean <- equal next, 0 + at-end-of-line?:bool <- equal next, 0 { break-if at-end-of-line? - next-character:character <- get *next, value:offset + next-character:char <- get *next, value:offset at-end-of-line? <- equal next-character, 10/newline } # break unless ((eol? and at-wrap?) or (~eol? and just-before-wrap?)) - move-cursor-to-next-line?:boolean <- copy 0/false + move-cursor-to-next-line?:bool <- copy 0/false { break-if at-end-of-line? move-cursor-to-next-line? <- copy just-before-wrap? # if we're moving the cursor because it's in the middle of a wrapping # line, adjust it to left-most column - potential-new-cursor-column:number <- copy left + potential-new-cursor-column:num <- copy left } { break-unless at-end-of-line? @@ -756,7 +756,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # if we're moving the cursor because it's at the end of a wrapping line, # adjust it to one past the left-most column to make room for the # newly-inserted wrap-indicator - potential-new-cursor-column:number <- add left, 1/make-room-for-wrap-indicator + potential-new-cursor-column:num <- add left, 1/make-room-for-wrap-indicator } break-unless move-cursor-to-next-line? cursor-column <- copy potential-new-cursor-column @@ -765,7 +765,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color *editor <- put *editor, cursor-row:offset, cursor-row # if we're out of the screen, scroll down { - below-screen?:boolean <- greater-or-equal cursor-row, screen-height + below-screen?:bool <- greater-or-equal cursor-row, screen-height break-unless below-screen? <scroll-down> } @@ -777,15 +777,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-wraps-cursor-after-inserting-characters-in-middle-of-line [ assume-screen 10/width, 5/height 1:text <- new [abcde] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 5/right + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 5/right assume-console [ left-click 1, 3 # right before the wrap icon type [f] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data - 3:number <- get *2:address:editor-data, cursor-row:offset - 4:number <- get *2:address:editor-data, cursor-column:offset + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data + 3:num <- get *2:&:editor-data, cursor-row:offset + 4:num <- get *2:&:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -806,7 +806,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # create an editor containing two lines contents:text <- new [abc xyz] - 1:address:editor-data/raw <- new-editor contents, screen, 0/left, 5/right + 1:&:editor-data/raw <- new-editor contents, screen, 0/left, 5/right screen-should-contain [ . . .abc . @@ -818,7 +818,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color type [de] # trigger wrap ] run [ - editor-event-loop screen:address:screen, console:address:console, 1:address:editor-data/raw + editor-event-loop screen:&:screen, console:&:console, 1:&:editor-data/raw ] screen-should-contain [ . . @@ -832,15 +832,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-wraps-cursor-to-left-margin [ assume-screen 10/width, 5/height 1:text <- new [abcde] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 2/left, 7/right + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 2/left, 7/right assume-console [ left-click 1, 5 # line is full; no wrap icon yet type [01] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data - 3:number <- get *2:address:editor-data, cursor-row:offset - 4:number <- get *2:address:editor-data, cursor-column:offset + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data + 3:num <- get *2:&:editor-data, cursor-row:offset + 4:num <- get *2:&:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -858,7 +858,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # if newline, move cursor to start of next line, and maybe align indent with previous line container editor-data [ - indent?:boolean + indent?:bool ] after <editor-initialization> [ @@ -868,13 +868,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-moves-cursor-down-after-inserting-newline [ assume-screen 10/width, 5/height 1:text <- new [abc] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 10/right + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 10/right assume-console [ type [0 1] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data ] screen-should-contain [ . . @@ -887,7 +887,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <handle-special-character> [ { - newline?:boolean <- equal c, 10/newline + newline?:bool <- equal c, 10/newline break-unless newline? <insert-enter-begin> editor <- insert-new-line-and-indent editor, screen @@ -897,15 +897,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color } ] -def insert-new-line-and-indent editor:address:editor-data, screen:address:screen -> editor:address:editor-data, screen:address:screen, go-render?:boolean [ +def insert-new-line-and-indent editor:&:editor-data, screen:&:screen -> editor:&:editor-data, screen:&:screen, go-render?:bool [ local-scope load-ingredients - cursor-row:number <- get *editor, cursor-row:offset - cursor-column:number <- get *editor, cursor-column:offset - before-cursor:address:duplex-list:character <- get *editor, before-cursor:offset - left:number <- get *editor, left:offset - right:number <- get *editor, right:offset - screen-height:number <- screen-height screen + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + screen-height:num <- screen-height screen # insert newline insert 10/newline, before-cursor before-cursor <- next before-cursor @@ -916,7 +916,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color *editor <- put *editor, cursor-column:offset, cursor-column # maybe scroll { - below-screen?:boolean <- greater-or-equal cursor-row, screen-height # must be equal, never greater + below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal, never greater break-unless below-screen? <scroll-down> go-render? <- copy 1/true @@ -924,16 +924,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color *editor <- put *editor, cursor-row:offset, cursor-row } # indent if necessary - indent?:boolean <- get *editor, indent?:offset + indent?:bool <- get *editor, indent?:offset return-unless indent? - d:address:duplex-list:character <- get *editor, data:offset - end-of-previous-line:address:duplex-list:character <- prev before-cursor - indent:number <- line-indent end-of-previous-line, d - i:number <- copy 0 + d:&:duplex-list:char <- get *editor, data:offset + end-of-previous-line:&:duplex-list:char <- prev before-cursor + indent:num <- line-indent end-of-previous-line, d + i:num <- copy 0 { - indent-done?:boolean <- greater-or-equal i, indent + indent-done?:bool <- greater-or-equal i, indent break-if indent-done? - editor, screen, go-render?:boolean <- insert-at-cursor editor, 32/space, screen + editor, screen, go-render?:bool <- insert-at-cursor editor, 32/space, screen i <- add i, 1 loop } @@ -941,23 +941,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # takes a pointer 'curr' into the doubly-linked list and its sentinel, counts # the number of spaces at the start of the line containing 'curr'. -def line-indent curr:address:duplex-list:character, start:address:duplex-list:character -> result:number [ +def line-indent curr:&:duplex-list:char, start:&:duplex-list:char -> result:num [ local-scope load-ingredients - result:number <- copy 0 + result:num <- copy 0 return-unless curr - at-start?:boolean <- equal curr, start + at-start?:bool <- equal curr, start return-if at-start? { curr <- prev curr break-unless curr - at-start?:boolean <- equal curr, start + at-start?:bool <- equal curr, start break-if at-start? - c:character <- get *curr, value:offset - at-newline?:boolean <- equal c, 10/newline + c:char <- get *curr, value:offset + at-newline?:bool <- equal c, 10/newline break-if at-newline? # if c is a space, increment result - is-space?:boolean <- equal c, 32/space + is-space?:bool <- equal c, 32/space { break-unless is-space? result <- add result, 1 @@ -974,13 +974,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-moves-cursor-down-after-inserting-newline-2 [ assume-screen 10/width, 5/height 1:text <- new [abc] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 1/left, 10/right + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 1/left, 10/right assume-console [ type [0 1] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data ] screen-should-contain [ . . @@ -994,7 +994,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-clears-previous-line-completely-after-inserting-newline [ assume-screen 10/width, 5/height 1:text <- new [abcde] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 5/right + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 5/right assume-console [ press enter ] @@ -1006,7 +1006,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data ] # line should be fully cleared screen-should-contain [ @@ -1023,7 +1023,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color 1:text <- new [ab cd ef] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 10/right + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 10/right # position cursor after 'cd' and hit 'newline' assume-console [ left-click 2, 8 @@ -1031,9 +1031,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data - 3:number <- get *2:address:editor-data, cursor-row:offset - 4:number <- get *2:address:editor-data, cursor-column:offset + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data + 3:num <- get *2:&:editor-data, cursor-row:offset + 4:num <- get *2:&:editor-data, cursor-column:offset ] # cursor should be below start of previous line memory-should-contain [ @@ -1047,7 +1047,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color 1:text <- new [ab cd ef] - 2:address:editor-data <- new-editor 1:text, screen:address:screen, 0/left, 10/right + 2:&:editor-data <- new-editor 1:text, screen:&:screen, 0/left, 10/right # position cursor after 'cd' and hit 'newline' surrounded by paste markers assume-console [ left-click 2, 8 @@ -1056,9 +1056,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color press 65506 # end paste ] run [ - editor-event-loop screen:address:screen, console:address:console, 2:address:editor-data - 3:number <- get *2:address:editor-data, cursor-row:offset - 4:number <- get *2:address:editor-data, cursor-column:offset + editor-event-loop screen:&:screen, console:&:console, 2:&:editor-data + 3:num <- get *2:&:editor-data, cursor-row:offset + 4:num <- get *2:&:editor-data, cursor-column:offset ] # cursor should be below start of previous line memory-should-contain [ @@ -1069,7 +1069,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <handle-special-key> [ { - paste-start?:boolean <- equal k, 65507/paste-start + paste-start?:bool <- equal k, 65507/paste-start break-unless paste-start? *editor <- put *editor, indent?:offset, 0/false go-render? <- copy 1/true @@ -1079,7 +1079,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <handle-special-key> [ { - paste-end?:boolean <- equal k, 65506/paste-end + paste-end?:bool <- equal k, 65506/paste-end break-unless paste-end? *editor <- put *editor, indent?:offset, 1/true go-render? <- copy 1/true @@ -1089,28 +1089,28 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ## helpers -def draw-horizontal screen:address:screen, row:number, x:number, right:number -> screen:address:screen [ +def draw-horizontal screen:&:screen, row:num, x:num, right:num -> screen:&:screen [ local-scope load-ingredients - style:character, style-found?:boolean <- next-ingredient + style:char, style-found?:bool <- next-ingredient { break-if style-found? style <- copy 9472/horizontal } - color:number, color-found?:boolean <- next-ingredient + color:num, color-found?:bool <- next-ingredient { # default color to white break-if color-found? color <- copy 245/grey } - bg-color:number, bg-color-found?:boolean <- next-ingredient + bg-color:num, bg-color-found?:bool <- next-ingredient { break-if bg-color-found? bg-color <- copy 0/black } screen <- move-cursor screen, row, x { - continue?:boolean <- lesser-or-equal x, right # right is inclusive, to match editor-data semantics + continue?:bool <- lesser-or-equal x, right # right is inclusive, to match editor-data semantics break-unless continue? print screen, style, color, bg-color x <- add x, 1 -- cgit 1.4.1-2-gfad0