about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--baremetal/shell/gap-buffer.mu20
-rw-r--r--baremetal/shell/word.mu32
2 files changed, 28 insertions, 24 deletions
diff --git a/baremetal/shell/gap-buffer.mu b/baremetal/shell/gap-buffer.mu
index fa1b83a0..3f31e096 100644
--- a/baremetal/shell/gap-buffer.mu
+++ b/baremetal/shell/gap-buffer.mu
@@ -85,17 +85,21 @@ fn render-gap-buffer screen: (addr screen), _gap: (addr gap-buffer), x: int, y:
   var right/ecx: (addr grapheme-stack) <- get gap, right
   x2 <- render-stack-from-top screen, right, x2, y, render-cursor?
   var x3/ebx: int <- copy x2
-  # if we must render cursor and the right side is empty, print a grapheme anyway
+  # decide whether we still need to print a cursor
+  var bg/edx: int <- copy 0
+  compare render-cursor?, 0/false
   {
-    compare render-cursor?, 0/false
     break-if-=
+    # if the right side is empty, grapheme stack didn't print the cursor
     var empty?/eax: boolean <- grapheme-stack-empty? right
     compare empty?, 0/false
     break-if-=
-    var space/eax: grapheme <- copy 0x20
-    draw-grapheme screen, space, x3, y, 3/fg=cyan, 7/bg
-    x3 <- increment
+    bg <- copy 7/cursor
   }
+  # print a grapheme either way so that cursor position doesn't affect printed width
+  var space/eax: grapheme <- copy 0x20
+  draw-grapheme screen, space, x3, y, 3/fg=cyan, bg
+  x3 <- increment
   return x3
 }
 
@@ -463,7 +467,7 @@ fn test-render-gap-buffer-without-cursor {
   #
   var x/eax: int <- render-gap-buffer screen, gap, 0/x, 0/y, 0/no-cursor
   check-screen-row screen, 0/y, "abc ", "F - test-render-gap-buffer-without-cursor"
-  check-ints-equal x, 3, "F - test-render-gap-buffer-without-cursor: result"
+  check-ints-equal x, 4, "F - test-render-gap-buffer-without-cursor: result"
                                                                 # abc
   check-background-color-in-screen-row screen, 7/bg=cursor, 0/y, "    ", "F - test-render-gap-buffer-without-cursor: bg"
 }
@@ -501,7 +505,7 @@ fn test-render-gap-buffer-with-cursor-in-middle {
   #
   var x/eax: int <- render-gap-buffer screen, gap, 0/x, 0/y, 1/show-cursor
   check-screen-row screen, 0/y, "abc ", "F - test-render-gap-buffer-with-cursor-in-middle"
-  check-ints-equal x, 3, "F - test-render-gap-buffer-with-cursor-in-middle: result"
+  check-ints-equal x, 4, "F - test-render-gap-buffer-with-cursor-in-middle: result"
                                                                 # abc
   check-background-color-in-screen-row screen, 7/bg=cursor, 0/y, "  | ", "F - test-render-gap-buffer-with-cursor-in-middle: bg"
 }
@@ -518,7 +522,7 @@ fn test-render-gap-buffer-with-cursor-at-start {
   #
   var x/eax: int <- render-gap-buffer screen, gap, 0/x, 0/y, 1/show-cursor
   check-screen-row screen, 0/y, "abc ", "F - test-render-gap-buffer-with-cursor-at-start"
-  check-ints-equal x, 3, "F - test-render-gap-buffer-with-cursor-at-start: result"
+  check-ints-equal x, 4, "F - test-render-gap-buffer-with-cursor-at-start: result"
                                                                 # abc
   check-background-color-in-screen-row screen, 7/bg=cursor, 0/y, "|   ", "F - test-render-gap-buffer-with-cursor-at-start: bg"
 }
diff --git a/baremetal/shell/word.mu b/baremetal/shell/word.mu
index b6c73264..44407b28 100644
--- a/baremetal/shell/word.mu
+++ b/baremetal/shell/word.mu
@@ -320,47 +320,47 @@ fn test-render-words-in-reverse {
   #
   var cursor-word/eax: int <- copy w
   var new-x/eax: int <- render-words-in-reverse screen, w-ah, 0/x, 0/y, cursor-word
-  check-screen-row screen, 0/y,                                   "ddd ccc bbb aaa  ", "F - test-render-words-in-reverse/0"
-  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "               | ", "F - test-render-words-in-reverse/0 cursor"
+  check-screen-row screen, 0/y,                                   "ddd  ccc  bbb  aaa  ", "F - test-render-words-in-reverse/0"
+  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "                  | ", "F - test-render-words-in-reverse/0 cursor"
   # - start moving cursor left through final word
   cursor-left w
   var cursor-word/eax: int <- copy w
   var new-x/eax: int <- render-words-in-reverse screen, w-ah, 0/x, 0/y, cursor-word
-  check-screen-row screen, 0/y,                                   "ddd ccc bbb aaa  ", "F - test-render-words-in-reverse/1"
-  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "              |  ", "F - test-render-words-in-reverse/1 cursor"
+  check-screen-row screen, 0/y,                                   "ddd  ccc  bbb  aaa  ", "F - test-render-words-in-reverse/1"
+  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "                 |  ", "F - test-render-words-in-reverse/1 cursor"
   #
   cursor-left w
   var cursor-word/eax: int <- copy w
   var new-x/eax: int <- render-words-in-reverse screen, w-ah, 0/x, 0/y, cursor-word
-  check-screen-row screen, 0/y,                                   "ddd ccc bbb aaa  ", "F - test-render-words-in-reverse/2"
-  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "             |   ", "F - test-render-words-in-reverse/2 cursor"
+  check-screen-row screen, 0/y,                                   "ddd  ccc  bbb  aaa  ", "F - test-render-words-in-reverse/2"
+  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "                |   ", "F - test-render-words-in-reverse/2 cursor"
   #
   cursor-left w
   var cursor-word/eax: int <- copy w
   var new-x/eax: int <- render-words-in-reverse screen, w-ah, 0/x, 0/y, cursor-word
-  check-screen-row screen, 0/y,                                   "ddd ccc bbb aaa  ", "F - test-render-words-in-reverse/3"
-  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "            |    ", "F - test-render-words-in-reverse/3 cursor"
+  check-screen-row screen, 0/y,                                   "ddd  ccc  bbb  aaa  ", "F - test-render-words-in-reverse/3"
+  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "               |    ", "F - test-render-words-in-reverse/3 cursor"
   # further moves left within the word change nothing
   cursor-left w
   var cursor-word/eax: int <- copy w
   var new-x/eax: int <- render-words-in-reverse screen, w-ah, 0/x, 0/y, cursor-word
-  check-screen-row screen, 0/y,                                   "ddd ccc bbb aaa  ", "F - test-render-words-in-reverse/3"
-  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "            |    ", "F - test-render-words-in-reverse/3 cursor"
+  check-screen-row screen, 0/y,                                   "ddd  ccc  bbb  aaa  ", "F - test-render-words-in-reverse/4"
+  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "               |    ", "F - test-render-words-in-reverse/4 cursor"
   # - switch to next word
   var w2-ah/eax: (addr handle word) <- get w, next
   var _w/eax: (addr word) <- lookup *w2-ah
   var w/ecx: (addr word) <- copy _w
   var cursor-word/eax: int <- copy w
   var new-x/eax: int <- render-words-in-reverse screen, w-ah, 0/x, 0/y, cursor-word
-  check-screen-row screen, 0/y,                                   "ddd ccc bbb  aaa  ", "F - test-render-words-in-reverse/4"
-  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "           |      ", "F - test-render-words-in-reverse/4 cursor"
+  check-screen-row screen, 0/y,                                   "ddd  ccc  bbb  aaa  ", "F - test-render-words-in-reverse/5"
+  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "             |      ", "F - test-render-words-in-reverse/5 cursor"
   # now speed up a little
   cursor-left w
   cursor-left w
   var cursor-word/eax: int <- copy w
   var new-x/eax: int <- render-words-in-reverse screen, w-ah, 0/x, 0/y, cursor-word
-  check-screen-row screen, 0/y,                                   "ddd ccc bbb aaa  ", "F - test-render-words-in-reverse/5"
-  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "         |       ", "F - test-render-words-in-reverse/5 cursor"
+  check-screen-row screen, 0/y,                                   "ddd  ccc  bbb  aaa  ", "F - test-render-words-in-reverse/6"
+  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "           |        ", "F - test-render-words-in-reverse/6 cursor"
   #
   var w2-ah/eax: (addr handle word) <- get w, next
   var _w/eax: (addr word) <- lookup *w2-ah
@@ -368,8 +368,8 @@ fn test-render-words-in-reverse {
   cursor-left w
   var cursor-word/eax: int <- copy w
   var new-x/eax: int <- render-words-in-reverse screen, w-ah, 0/x, 0/y, cursor-word
-  check-screen-row screen, 0/y,                                   "ddd ccc bbb aaa  ", "F - test-render-words-in-reverse/6"
-  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "      |          ", "F - test-render-words-in-reverse/6 cursor"
+  check-screen-row screen, 0/y,                                   "ddd  ccc  bbb  aaa  ", "F - test-render-words-in-reverse/7"
+  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y,  "       |            ", "F - test-render-words-in-reverse/7 cursor"
 }
 
 # Gotcha with some word operations: ensure dest-ah isn't in the middle of some