diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-09-07 22:09:43 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-09-07 22:14:54 -0700 |
commit | fc42975cf429a75f15b079d9d0d216311b42f7a9 (patch) | |
tree | ae438e590828e62daddc47d1d18c5e8b5a189b77 /apps/browse | |
parent | 137cde5bfae7104c97b0f48277480eb78ced4ff1 (diff) | |
download | mu-fc42975cf429a75f15b079d9d0d216311b42f7a9.tar.gz |
6751
More copypasta. I'd be able to remove this duplication if we had first-class functions, but they involve an accessibility cost.
Diffstat (limited to 'apps/browse')
-rw-r--r-- | apps/browse/main.mu | 38 | ||||
-rw-r--r-- | apps/browse/screen-position-state.mu | 9 |
2 files changed, 23 insertions, 24 deletions
diff --git a/apps/browse/main.mu b/apps/browse/main.mu index d710c1a6..8467f01f 100644 --- a/apps/browse/main.mu +++ b/apps/browse/main.mu @@ -33,13 +33,13 @@ fn render screen: (addr screen), fs: (addr buffered-file), state: (addr screen-p fn render-normal screen: (addr screen), fs: (addr buffered-file), state: (addr screen-position-state) { var newline-seen?/esi: boolean <- copy 0 # false var start-of-paragraph?/edi: boolean <- copy 1 # true - var previous-char/ebx: byte <- copy 0 + var previous-grapheme/ebx: grapheme <- copy 0 $render-normal:loop: { # if done-drawing?(state) break var done?/eax: boolean <- done-drawing? state compare done?, 0 # false break-if-!= - var c/eax: byte <- read-byte-buffered fs + var c/eax: grapheme <- read-grapheme-buffered fs $render-normal:loop-body: { # if (c == EOF) break compare c, 0xffffffff # EOF marker @@ -59,8 +59,8 @@ $render-normal:loop-body: { # otherwise render two newlines { break-if-= - add-char state, 0xa # newline - add-char state, 0xa # newline + add-grapheme state, 0xa # newline + add-grapheme state, 0xa # newline newline-seen? <- copy 0 # false start-of-paragraph? <- copy 1 # true break $render-normal:loop-body @@ -94,20 +94,20 @@ $render-normal:flush-buffered-newline: { { compare c, 0x20 break-if-!= - add-char state, 0xa # newline + add-grapheme state, 0xa # newline break $render-normal:flush-buffered-newline } - add-char state, 0x20 # space + add-grapheme state, 0x20 # space # fall through to print c } ## end soft newline support $render-normal:whitespace-separated-regions: { - # if previous-char wasn't whitespace, skip this block + # if previous-grapheme wasn't whitespace, skip this block { - compare previous-char, 0x20 # space + compare previous-grapheme, 0x20 # space break-if-= - compare previous-char, 0xa # newline + compare previous-grapheme, 0xa # newline break-if-= break $render-normal:whitespace-separated-regions } @@ -133,9 +133,9 @@ $render-normal:whitespace-separated-regions: { } } # - add-char state, c + add-grapheme state, c } # $render-normal:loop-body - previous-char <- copy c + previous-grapheme <- copy c loop } # $render-normal:loop } @@ -144,7 +144,7 @@ fn render-header-line screen: (addr screen), fs: (addr buffered-file), state: (a $render-header-line:body: { # compute color based on number of '#'s var header-level/esi: int <- copy 1 # caller already grabbed one - var c/eax: byte <- copy 0 + var c/eax: grapheme <- copy 0 { # if done-drawing?(state) return { @@ -153,7 +153,7 @@ $render-header-line:body: { break-if-!= $render-header-line:body } # - c <- read-byte-buffered fs + c <- read-grapheme-buffered fs # if (c != '#') break compare c, 0x23 # '#' break-if-!= @@ -171,7 +171,7 @@ $render-header-line:body: { break-if-!= } # - c <- read-byte-buffered fs + c <- read-grapheme-buffered fs # if (c == EOF) break compare c, 0xffffffff # EOF marker break-if-= @@ -179,7 +179,7 @@ $render-header-line:body: { compare c, 0xa # newline break-if-= # - add-char state, c + add-grapheme state, c # loop } @@ -226,7 +226,7 @@ fn render-until-asterisk fs: (addr buffered-file), state: (addr screen-position- compare done?, 0 # false break-if-!= # - var c/eax: byte <- read-byte-buffered fs + var c/eax: grapheme <- read-grapheme-buffered fs # if (c == EOF) break compare c, 0xffffffff # EOF marker break-if-= @@ -234,7 +234,7 @@ fn render-until-asterisk fs: (addr buffered-file), state: (addr screen-position- compare c, 0x2a # '*' break-if-= # - add-char state, c + add-grapheme state, c # loop } @@ -247,7 +247,7 @@ fn render-until-underscore fs: (addr buffered-file), state: (addr screen-positio compare done?, 0 # false break-if-!= # - var c/eax: byte <- read-byte-buffered fs + var c/eax: grapheme <- read-grapheme-buffered fs # if (c == EOF) break compare c, 0xffffffff # EOF marker break-if-= @@ -255,7 +255,7 @@ fn render-until-underscore fs: (addr buffered-file), state: (addr screen-positio compare c, 0x5f # '_' break-if-= # - add-char state, c + add-grapheme state, c # loop } diff --git a/apps/browse/screen-position-state.mu b/apps/browse/screen-position-state.mu index 7b53ae07..f342faab 100644 --- a/apps/browse/screen-position-state.mu +++ b/apps/browse/screen-position-state.mu @@ -61,19 +61,18 @@ fn start-drawing _self: (addr screen-position-state) { reposition-cursor self } -fn add-char _self: (addr screen-position-state), c: byte { -$add-char:body: { +fn add-grapheme _self: (addr screen-position-state), c: grapheme { +$add-grapheme:body: { var self/esi: (addr screen-position-state) <- copy _self { compare c, 0xa # newline break-if-!= next-line self reposition-cursor self - break $add-char:body + break $add-grapheme:body } # print c - var g/eax: grapheme <- copy c - print-grapheme 0, g + print-grapheme 0, c # self->col++ var tmp/eax: (addr int) <- get self, col increment *tmp |