diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-06-20 17:21:16 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-06-20 17:40:26 -0700 |
commit | 91619b98b7e032ce07808649f21fbf005aaf0261 (patch) | |
tree | 5735772db8a084885eca0b532a63845815359d88 | |
parent | 7d154c495ae4855d71f52ed00c725d22aa62f3da (diff) | |
download | mu-91619b98b7e032ce07808649f21fbf005aaf0261.tar.gz |
1606
Rip out keyboard for now, add notion of cursor.
-rw-r--r-- | edit.mu | 75 |
1 files changed, 43 insertions, 32 deletions
diff --git a/edit.mu b/edit.mu index 600d94d5..fd9b0577 100644 --- a/edit.mu +++ b/edit.mu @@ -12,21 +12,16 @@ def ghi jkl ] - bottom:number <- edit in:address:array:character, 0:literal/screen, 0:literal/top, 0:literal/left, 5:literal/bottom, divider:number/right, 0:literal/keyboard - # shorten bottom border and darken to make it seem thinner - border-left:number <- multiply divider:number, 0.2 - border-right:number <- multiply divider:number, 0.8 - draw-horizontal 0:literal/screen, bottom:number/row, border-left:number, border-right:number, 241:literal/grey + bottom:number, editor:address:editor-data <- edit in:address:array:character, 0:literal/screen, 0:literal/top, 0:literal/left, 5:literal/bottom, divider:number/right wait-for-key-from-keyboard return-to-console ] scenario edit-prints-string-to-screen [ assume-screen 10:literal/width, 5:literal/height - assume-keyboard [] run [ s:address:array:character <- new [abc] - edit s:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right, keyboard:address + edit s:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right ] screen-should-contain [ .abc . @@ -37,6 +32,7 @@ scenario edit-prints-string-to-screen [ container editor-data [ data:address:duplex-list # doubly linked list of characters top-of-screen:address:duplex-list # pointer to character at top-left + cursor:address:duplex-list ] recipe new-editor-data [ @@ -59,14 +55,27 @@ recipe new-editor-data [ curr:address:duplex-list <- copy init:address:address:duplex-list/deref # now we can start appending the rest, character by character { +#? $print idx:number, [ vs ], len:number, [ +#? ] #? 1 done?:boolean <- greater-or-equal idx:number, len:number break-if done?:boolean c:character <- index s:address:array:character/deref, idx:number +#? $print [aa: ], c:character, [ +#? ] #? 1 insert-duplex c:character, curr:address:duplex-list # next iter curr:address:duplex-list <- next-duplex curr:address:duplex-list idx:number <- add idx:number, 1:literal + loop } + # initialize cursor to top of screen + x:address:address:duplex-list <- get-address result:address:editor-data/deref, cursor:offset + x:address:address:duplex-list/deref <- copy init:address:address:duplex-list/deref + # playing with moving the cursor around +#? x:address:address:duplex-list/deref <- next-duplex x:address:address:duplex-list/deref +#? x:address:address:duplex-list/deref <- next-duplex x:address:address:duplex-list/deref +#? x:address:address:duplex-list/deref <- next-duplex x:address:address:duplex-list/deref +#? x:address:address:duplex-list/deref <- next-duplex x:address:address:duplex-list/deref reply result:address:editor-data ] @@ -79,34 +88,40 @@ recipe edit [ left:number <- next-ingredient right:number <- next-ingredient right:number <- subtract right:number, 1:literal - keyboard:address <- next-ingredient edit:address:editor-data <- new-editor-data s:address:array:character, screen:address - bottom:number, screen:address <- render s:address:array:character, screen:address, top:number, left:number, right:number + bottom:number, screen:address <- render edit:address:editor-data, screen:address, top:number, left:number, right:number reply bottom:number, edit:address:editor-data ] recipe render [ default-space:address:array:location <- new location:type, 30:literal - s:address:array:character <- next-ingredient + editor:address:editor-data <- next-ingredient screen:address <- next-ingredient top:number <- next-ingredient left:number <- next-ingredient screen-height:number <- screen-height screen:address right:number <- next-ingredient - # traversing inside s - len:number <- length s:address:array:character/deref - i:number <- copy 0:literal - # traversing inside screen + cursor:address:duplex-list <- get editor:address:editor-data/deref, cursor:offset + # traversing editor + curr:address:duplex-list <- get editor:address:editor-data/deref, top-of-screen:offset + # traversing screen row:number <- copy top:number column:number <- copy left:number move-cursor screen:address, row:number, column:number { +next-character - done?:boolean <- greater-or-equal i:number, len:number - break-if done?:boolean +#? $print curr:address:duplex-list, [ +#? ] #? 1 + break-unless curr:address:duplex-list off-screen?:boolean <- greater-or-equal row:number, screen-height:number break-if off-screen?:boolean - c:character <- index s:address:array:character/deref, i:number + { + at-cursor?:boolean <- equal curr:address:duplex-list, cursor:address:duplex-list + break-unless at-cursor?:boolean + cursor-row:number <- copy row:number + cursor-column:number <- copy column:number + } + c:character <- get curr:address:duplex-list/deref, value:offset { # newline? move to left rather than 0 newline?:boolean <- equal c:character, 10:literal/newline @@ -114,17 +129,16 @@ recipe render [ row:number <- add row:number, 1:literal column:number <- copy left:number move-cursor screen:address, row:number, column:number - i:number <- add i:number, 1:literal + curr:address:duplex-list <- next-duplex curr:address:duplex-list loop +next-character:label } { # at right? more than one letter left in the line? wrap at-right?:boolean <- equal column:number, right:number break-unless at-right?:boolean - next-index:number <- add i:number, 1:literal - next-at-end?:boolean <- greater-or-equal next-index:number, len:number - break-if next-at-end?:boolean - next:character <- index s:address:array:character/deref, next-index:number + 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 # wrap @@ -132,24 +146,24 @@ recipe render [ column:number <- copy left:number row:number <- add row:number, 1:literal move-cursor screen:address, row:number, column:number - # don't increment i + # don't increment curr loop +next-character:label } print-character screen:address, c:character - i:number <- add i:number, 1:literal + curr:address:duplex-list <- next-duplex curr:address:duplex-list column:number <- add column:number, 1:literal loop } + move-cursor screen:address, cursor-row:number, cursor-column:number reply row:number, screen:address/same-as-ingredient:1 ] scenario edit-prints-multiple-lines [ assume-screen 5:literal/width, 3:literal/height - assume-keyboard [] run [ s:address:array:character <- new [abc def] - edit s:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right, keyboard:address + edit s:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right ] screen-should-contain [ .abc . @@ -160,10 +174,9 @@ def] scenario edit-handles-offsets [ assume-screen 5:literal/width, 3:literal/height - assume-keyboard [] run [ s:address:array:character <- new [abc] - edit s:address:array:character, screen:address, 0:literal/top, 1:literal/left, 5:literal/right, keyboard:address + edit s:address:array:character, screen:address, 0:literal/top, 1:literal/left, 5:literal/right ] screen-should-contain [ . abc . @@ -174,11 +187,10 @@ scenario edit-handles-offsets [ scenario edit-prints-multiple-lines-at-offset [ assume-screen 5:literal/width, 3:literal/height - assume-keyboard [] run [ s:address:array:character <- new [abc def] - edit s:address:array:character, screen:address, 0:literal/top, 1:literal/left, 5:literal/right, keyboard:address + edit s:address:array:character, screen:address, 0:literal/top, 1:literal/left, 5:literal/right ] screen-should-contain [ . abc . @@ -189,10 +201,9 @@ def] scenario edit-wraps-long-lines [ assume-screen 5:literal/width, 3:literal/height - assume-keyboard [] run [ s:address:array:character <- new [abc def] - edit s:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right, keyboard:address + edit s:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right ] screen-should-contain [ .abc ↩. |