about summary refs log tree commit diff stats
path: root/405screen.mu
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-06 22:06:12 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-06 22:06:12 -0700
commit05b9b2ab9c89652b845e0f89bd87b2d56b961822 (patch)
tree420b78715a5536f9ba2ecde418e1a0bfed4a9a4c /405screen.mu
parent454e345e498d6340833c9f8ad881e5baf796f3a6 (diff)
downloadmu-05b9b2ab9c89652b845e0f89bd87b2d56b961822.tar.gz
6740
Diffstat (limited to '405screen.mu')
-rw-r--r--405screen.mu19
1 files changed, 19 insertions, 0 deletions
diff --git a/405screen.mu b/405screen.mu
index 041858a0..ffa9fbb4 100644
--- a/405screen.mu
+++ b/405screen.mu
@@ -216,6 +216,16 @@ $print-grapheme:body: {
     # fake screen
     var screen-addr/esi: (addr screen) <- copy screen
     var cursor-col-addr/edx: (addr int) <- get screen-addr, cursor-col
+    # adjust cursor if necessary
+    {
+      var num-cols-addr/eax: (addr int) <- get screen-addr, num-cols
+      var num-cols/eax: int <- copy *num-cols-addr
+      compare *cursor-col-addr, num-cols
+      break-if-<=
+      copy-to *cursor-col-addr, 1
+      var cursor-row-addr/eax: (addr int) <- get screen-addr, cursor-row
+      increment *cursor-row-addr
+    }
     var idx/ecx: int <- current-screen-cell-index screen-addr
     var data-ah/eax: (addr handle array screen-cell) <- get screen-addr, data
     var data/eax: (addr array screen-cell) <- lookup *data-ah
@@ -622,6 +632,15 @@ fn test-check-screen-row-from {
   check-screen-row-from screen, 1, 4, "a", "F - test-check-screen-row-from"
 }
 
+fn test-print-string-overflows-to-next-row {
+  var screen-on-stack: screen
+  var screen/esi: (addr screen) <- address screen-on-stack
+  initialize-screen screen, 5, 4  # 5 rows, 4 columns
+  print-string screen, "abcdefg"
+  check-screen-row screen, 1, "abcd", "F - test-print-string-overflows-to-next-row"
+  check-screen-row screen, 2, "efg", "F - test-print-string-overflows-to-next-row"
+}
+
 fn main -> exit-status/ebx: int {
   run-tests
   exit-status <- copy 0