diff options
Diffstat (limited to 'sandbox/001-editor.mu')
-rw-r--r-- | sandbox/001-editor.mu | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/sandbox/001-editor.mu b/sandbox/001-editor.mu index fd44d493..773b7d77 100644 --- a/sandbox/001-editor.mu +++ b/sandbox/001-editor.mu @@ -2,7 +2,7 @@ # temporary main for this layer: just render the given text at the given # screen dimensions, then stop -recipe! main text:address:array:character [ +recipe! main text:address:shared:array:character [ local-scope load-ingredients open-console @@ -16,8 +16,8 @@ recipe! main text:address:array:character [ scenario editor-initially-prints-text-to-screen [ assume-screen 10/width, 5/height run [ - 1:address:array:character <- new [abc] - new-editor 1:address:array:character, screen:address:screen, 0/left, 10/right + 1:address:shared:array:character <- new [abc] + new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 10/right ] screen-should-contain [ # top line of screen reserved for menu @@ -29,11 +29,11 @@ scenario editor-initially-prints-text-to-screen [ container editor-data [ # editable text: doubly linked list of characters (head contains a special sentinel) - data:address:duplex-list:character - top-of-screen:address:duplex-list:character - bottom-of-screen:address:duplex-list:character + data:address:shared:duplex-list:character + top-of-screen:address:shared:duplex-list:character + bottom-of-screen:address:shared:duplex-list:character # location before cursor inside data - before-cursor:address:duplex-list:character + before-cursor:address:shared:duplex-list:character # raw bounds of display area on screen # always displays from row 1 (leaving row 0 for a menu) and at most until bottom of screen @@ -47,7 +47,7 @@ container editor-data [ # creates a new editor widget and renders its initial appearance to screen # top/left/right constrain the screen area available to the new editor # right is exclusive -recipe new-editor s:address:array:character, screen:address:screen, left:number, right:number -> result:address:editor-data, screen:address:screen [ +recipe new-editor s:address:shared:array:character, screen:address:shared:screen, left:number, right:number -> result:address:shared:editor-data, screen:address:shared:screen [ local-scope load-ingredients # no clipping of bounds @@ -63,11 +63,11 @@ recipe new-editor s:address:array:character, screen:address:screen, left:number, *x <- copy 1/top x <- get-address *result, cursor-column:offset *x <- copy left - init:address:address:duplex-list:character <- get-address *result, data:offset + init:address:address:shared:duplex-list:character <- get-address *result, data:offset *init <- push 167/§, 0/tail - top-of-screen:address:address:duplex-list:character <- get-address *result, top-of-screen:offset + top-of-screen:address:address:shared:duplex-list:character <- get-address *result, top-of-screen:offset *top-of-screen <- copy *init - y:address:address:duplex-list:character <- get-address *result, before-cursor:offset + y:address:address:shared:duplex-list:character <- get-address *result, before-cursor:offset *y <- copy *init result <- insert-text result, s # initialize cursor to top of screen @@ -78,7 +78,7 @@ recipe new-editor s:address:array:character, screen:address:screen, left:number, <editor-initialization> ] -recipe insert-text editor:address:editor-data, text:address:array:character -> editor:address:editor-data [ +recipe insert-text editor:address:shared:editor-data, text:address:shared:array:character -> editor:address:shared:editor-data [ local-scope load-ingredients # early exit if text is empty @@ -87,7 +87,7 @@ recipe insert-text editor:address:editor-data, text:address:array:character -> e reply-unless len, editor/same-as-ingredient:0 idx:number <- copy 0 # now we can start appending the rest, character by character - curr:address:duplex-list:character <- get *editor, data:offset + curr:address:shared:duplex-list:character <- get *editor, data:offset { done?:boolean <- greater-or-equal idx, len break-if done? @@ -104,8 +104,8 @@ recipe insert-text editor:address:editor-data, text:address:array:character -> e scenario editor-initializes-without-data [ assume-screen 5/width, 3/height run [ - 1:address:editor-data <- new-editor 0/data, screen:address:screen, 2/left, 5/right - 2:editor-data <- copy *1:address:editor-data + 1:address:shared:editor-data <- new-editor 0/data, screen:address:shared:screen, 2/left, 5/right + 2:editor-data <- copy *1:address:shared:editor-data ] memory-should-contain [ # 2 (data) <- just the § sentinel @@ -127,7 +127,7 @@ scenario editor-initializes-without-data [ # Assumes cursor should be at coordinates (cursor-row, cursor-column) and # updates before-cursor to match. Might also move coordinates if they're # outside text. -recipe render screen:address:screen, editor:address:editor-data -> last-row:number, last-column:number, screen:address:screen, editor:address:editor-data [ +recipe render screen:address:shared:screen, editor:address:shared:editor-data -> last-row:number, last-column:number, screen:address:shared:screen, editor:address:shared:editor-data [ local-scope load-ingredients reply-unless editor, 1/top, 0/left, screen/same-as-ingredient:0, editor/same-as-ingredient:1 @@ -135,8 +135,8 @@ recipe render screen:address:screen, editor:address:editor-data -> last-row:numb screen-height:number <- screen-height screen right:number <- get *editor, right:offset # traversing editor - 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:address:shared:duplex-list:character <- get *editor, top-of-screen:offset + prev:address:shared:duplex-list:character <- copy curr # just in case curr becomes null and we can't compute prev curr <- next curr # traversing screen +render-loop-initialization @@ -145,7 +145,7 @@ recipe render screen:address:screen, editor:address:editor-data -> last-row:numb column:number <- copy left cursor-row:address:number <- get-address *editor, cursor-row:offset cursor-column:address:number <- get-address *editor, cursor-column:offset - before-cursor:address:address:duplex-list:character <- get-address *editor, before-cursor:offset + before-cursor:address:address:shared:duplex-list:character <- get-address *editor, before-cursor:offset screen <- move-cursor screen, row, column { +next-character @@ -208,7 +208,7 @@ recipe render screen:address:screen, editor:address:editor-data -> last-row:numb loop } # save first character off-screen - bottom-of-screen:address:address:duplex-list:character <- get-address *editor, bottom-of-screen:offset + bottom-of-screen:address:address:shared:duplex-list:character <- get-address *editor, bottom-of-screen:offset *bottom-of-screen <- copy curr # is cursor to the right of the last line? move to end { @@ -225,7 +225,7 @@ recipe render screen:address:screen, editor:address:editor-data -> last-row:numb reply row, column, screen/same-as-ingredient:0, editor/same-as-ingredient:1 ] -recipe clear-line-delimited screen:address:screen, column:number, right:number -> screen:address:screen [ +recipe clear-line-delimited screen:address:shared:screen, column:number, right:number -> screen:address:shared:screen [ local-scope load-ingredients space:character <- copy 32/space @@ -238,7 +238,7 @@ recipe clear-line-delimited screen:address:screen, column:number, right:number - } ] -recipe clear-screen-from screen:address:screen, row:number, column:number, left:number, right:number -> screen:address:screen [ +recipe clear-screen-from screen:address:shared:screen, row:number, column:number, left:number, right:number -> screen:address:shared:screen [ local-scope load-ingredients # if it's the real screen, use the optimized primitive @@ -254,7 +254,7 @@ recipe clear-screen-from screen:address:screen, row:number, column:number, left: reply screen/same-as-ingredient:0 ] -recipe clear-rest-of-screen screen:address:screen, row:number, left:number, right:number -> screen:address:screen [ +recipe clear-rest-of-screen screen:address:shared:screen, row:number, left:number, right:number -> screen:address:shared:screen [ local-scope load-ingredients row <- add row, 1 @@ -273,9 +273,9 @@ recipe clear-rest-of-screen screen:address:screen, row:number, left:number, righ scenario editor-initially-prints-multiple-lines [ assume-screen 5/width, 5/height run [ - s:address:array:character <- new [abc + s:address:shared:array:character <- new [abc def] - new-editor s:address:array:character, screen:address:screen, 0/left, 5/right + new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right ] screen-should-contain [ . . @@ -288,8 +288,8 @@ def] scenario editor-initially-handles-offsets [ assume-screen 5/width, 5/height run [ - s:address:array:character <- new [abc] - new-editor s:address:array:character, screen:address:screen, 1/left, 5/right + s:address:shared:array:character <- new [abc] + new-editor s:address:shared:array:character, screen:address:shared:screen, 1/left, 5/right ] screen-should-contain [ . . @@ -301,9 +301,9 @@ scenario editor-initially-handles-offsets [ scenario editor-initially-prints-multiple-lines-at-offset [ assume-screen 5/width, 5/height run [ - s:address:array:character <- new [abc + s:address:shared:array:character <- new [abc def] - new-editor s:address:array:character, screen:address:screen, 1/left, 5/right + new-editor s:address:shared:array:character, screen:address:shared:screen, 1/left, 5/right ] screen-should-contain [ . . @@ -316,8 +316,8 @@ def] scenario editor-initially-wraps-long-lines [ assume-screen 5/width, 5/height run [ - s:address:array:character <- new [abc def] - new-editor s:address:array:character, screen:address:screen, 0/left, 5/right + s:address:shared:array:character <- new [abc def] + new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right ] screen-should-contain [ . . @@ -336,8 +336,8 @@ scenario editor-initially-wraps-long-lines [ scenario editor-initially-wraps-barely-long-lines [ assume-screen 5/width, 5/height run [ - s:address:array:character <- new [abcde] - new-editor s:address:array:character, screen:address:screen, 0/left, 5/right + s:address:shared:array:character <- new [abcde] + new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right ] # still wrap, even though the line would fit. We need room to click on the # end of the line @@ -358,10 +358,10 @@ scenario editor-initially-wraps-barely-long-lines [ scenario editor-initializes-empty-text [ assume-screen 5/width, 5/height run [ - 1:address:array:character <- new [] - 2:address:editor-data <- new-editor 1:address:array:character, screen:address:screen, 0/left, 5/right - 3:number <- get *2:address:editor-data, cursor-row:offset - 4:number <- get *2:address:editor-data, cursor-column:offset + 1:address:shared:array:character <- new [] + 2:address:shared:editor-data <- new-editor 1:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right + 3:number <- get *2:address:shared:editor-data, cursor-row:offset + 4:number <- get *2:address:shared:editor-data, cursor-column:offset ] screen-should-contain [ . . @@ -379,10 +379,10 @@ scenario editor-initializes-empty-text [ scenario render-colors-comments [ assume-screen 5/width, 5/height run [ - s:address:array:character <- new [abc + s:address:shared:array:character <- new [abc # de f] - new-editor s:address:array:character, screen:address:screen, 0/left, 5/right + new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 5/right ] screen-should-contain [ . . @@ -460,10 +460,10 @@ recipe get-color color:number, c:character -> color:number [ scenario render-colors-assignment [ assume-screen 8/width, 5/height run [ - s:address:array:character <- new [abc + s:address:shared:array:character <- new [abc d <- e f] - new-editor s:address:array:character, screen:address:screen, 0/left, 8/right + new-editor s:address:shared:array:character, screen:address:shared:screen, 0/left, 8/right ] screen-should-contain [ . . |