diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-11-12 22:31:49 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-11-12 22:31:49 -0800 |
commit | be422222cd20a0d68cc7600cbe373acd22ecfdc4 (patch) | |
tree | 7766fa1925c55aa5f50aa1783cf439de21c5af3f /sandbox/001-editor.mu | |
parent | b61dfa4fd3596d3095c8ff00913cc443dd751ad0 (diff) | |
download | mu-be422222cd20a0d68cc7600cbe373acd22ecfdc4.tar.gz |
2428 - sandbox/ working again
Diffstat (limited to 'sandbox/001-editor.mu')
-rw-r--r-- | sandbox/001-editor.mu | 76 |
1 files changed, 28 insertions, 48 deletions
diff --git a/sandbox/001-editor.mu b/sandbox/001-editor.mu index f89a6ab9..4b8da7a8 100644 --- a/sandbox/001-editor.mu +++ b/sandbox/001-editor.mu @@ -2,9 +2,9 @@ # temporary main for this layer: just render the given string at the given # screen dimensions, then stop -recipe! main [ +recipe! main text:address:array:character [ local-scope - text:address:array:character <- next-ingredient + load-ingredients open-console hide-screen 0/screen new-editor text, 0/screen, 0/left, 5/right @@ -44,19 +44,15 @@ container editor-data [ cursor-column:number ] -# editor:address:editor-data, screen <- new-editor s:address:array:character, screen:address:screen, left:number, right:number -# 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 [ +# 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 [ local-scope - s:address:array:character <- next-ingredient - screen:address:screen <- next-ingredient + load-ingredients # no clipping of bounds - left:number <- next-ingredient - right:number <- next-ingredient right <- subtract right, 1 - result:address:editor-data <- new editor-data:type + result <- new editor-data:type # initialize screen-related fields x:address:number <- get-address *result, left:offset *x <- copy left @@ -67,11 +63,11 @@ recipe new-editor [ *x <- copy 1/top x <- get-address *result, cursor-column:offset *x <- copy left - init:address:address:duplex-list <- get-address *result, data:offset + init:address:address:duplex-list:character <- get-address *result, data:offset *init <- push-duplex 167/§, 0/tail - top-of-screen:address:address:duplex-list <- get-address *result, top-of-screen:offset + top-of-screen:address:address:duplex-list:character <- get-address *result, top-of-screen:offset *top-of-screen <- copy *init - y:address:address:duplex-list <- get-address *result, before-cursor:offset + y:address:address:duplex-list:character <- get-address *result, before-cursor:offset *y <- copy *init result <- insert-text result, s # initialize cursor to top of screen @@ -80,20 +76,18 @@ recipe new-editor [ # initial render to screen, just for some old tests _, _, screen, result <- render screen, result <editor-initialization> - reply result ] -recipe insert-text [ +recipe insert-text editor:address:editor-data, text:address:array:character -> editor:address:editor-data [ local-scope - editor:address:editor-data <- next-ingredient - text:address:array:character <- next-ingredient + load-ingredients # early exit if text is empty reply-unless text, editor/same-as-ingredient:0 len:number <- length *text 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 <- get *editor, data:offset + curr:address:duplex-list:character <- get *editor, data:offset { done?:boolean <- greater-or-equal idx, len break-if done? @@ -130,22 +124,19 @@ scenario editor-initializes-without-data [ ] ] -# last-row:number, last-column:number, screen, editor <- render screen:address:screen, editor:address:editor-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 [ +recipe render screen:address:screen, editor:address:editor-data -> last-row:number, last-column:number, screen:address:screen, editor:address:editor-data [ local-scope - screen:address:screen <- next-ingredient - editor:address:editor-data <- next-ingredient + load-ingredients reply-unless editor, 1/top, 0/left, screen/same-as-ingredient:0, editor/same-as-ingredient:1 left:number <- get *editor, left:offset screen-height:number <- screen-height screen right:number <- get *editor, right:offset # traversing editor - curr:address:duplex-list <- get *editor, top-of-screen:offset - prev:address:duplex-list <- copy curr # just in case curr becomes null and we can't compute prev-duplex + 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-duplex curr <- next-duplex curr # traversing screen +render-loop-initialization @@ -154,7 +145,7 @@ recipe render [ 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 <- get-address *editor, before-cursor:offset + before-cursor:address:address:duplex-list:character <- get-address *editor, before-cursor:offset screen <- move-cursor screen, row, column { +next-character @@ -216,7 +207,7 @@ recipe render [ loop } # save first character off-screen - bottom-of-screen:address:address:duplex-list <- get-address *editor, bottom-of-screen:offset + bottom-of-screen:address:address: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 { @@ -233,11 +224,9 @@ recipe render [ reply row, column, screen/same-as-ingredient:0, editor/same-as-ingredient:1 ] -recipe clear-line-delimited [ +recipe clear-line-delimited screen:address:screen, column:number, right:number [ local-scope - screen:address:screen <- next-ingredient - column:number <- next-ingredient - right:number <- next-ingredient + load-ingredients { done?:boolean <- greater-than column, right break-if done? @@ -247,13 +236,9 @@ recipe clear-line-delimited [ } ] -recipe clear-screen-from [ +recipe clear-screen-from screen:address:screen, row:number, column:number, left:number, right:number -> screen:address:screen [ local-scope - screen:address:screen <- next-ingredient - row:number <- next-ingredient - column:number <- next-ingredient - left:number <- next-ingredient - right:number <- next-ingredient + load-ingredients # if it's the real screen, use the optimized primitive { break-if screen @@ -267,12 +252,9 @@ recipe clear-screen-from [ reply screen/same-as-ingredient:0 ] -recipe clear-rest-of-screen [ +recipe clear-rest-of-screen screen:address:screen, row:number, left:number, right:number [ local-scope - screen:address:screen <- next-ingredient - row:number <- next-ingredient - left:number <- next-ingredient - right:number <- next-ingredient + load-ingredients row <- add row, 1 screen <- move-cursor screen, row, left screen-height:number <- screen-height screen @@ -427,12 +409,10 @@ after <character-c-received> [ color <- get-color color, c ] -# color <- get-color color:number, c:character # so far the previous color is all the information we need; that may change -recipe get-color [ +recipe get-color color:number, c:character -> color:number [ local-scope - color:number <- next-ingredient - c:character <- next-ingredient + load-ingredients color-is-white?:boolean <- equal color, 7/white # if color is white and next character is '#', switch color to blue { |