about summary refs log tree commit diff stats
path: root/edit
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-03-14 11:21:22 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-03-14 11:21:22 -0700
commitfadb576efca5586fc67bdc3f69fc32e86fc3bb01 (patch)
tree16c664ee22094b5916cbf55b2c09afc5a1ac800e /edit
parent7b38bc8ece46b92855c6363fde53d59011d9f0a4 (diff)
downloadmu-fadb576efca5586fc67bdc3f69fc32e86fc3bb01.tar.gz
3796
Standardize the order of some common blocks in `render`, `render-text`
and `render-code`. This is preparation for trying to reorganize them to
reduce duplicate code.
Diffstat (limited to 'edit')
-rw-r--r--edit/005-sandbox.mu71
1 files changed, 45 insertions, 26 deletions
diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu
index c896667e..94abe175 100644
--- a/edit/005-sandbox.mu
+++ b/edit/005-sandbox.mu
@@ -375,19 +375,6 @@ def render-text screen:&:screen, s:text, left:num, right:num, color:num, row:num
     break-if done?
     c:char <- index *s, i
     {
-      # at right? wrap.
-      at-right?:bool <- equal column, right
-      break-unless at-right?
-      # print wrap icon
-      wrap-icon:char <- copy 8617/loop-back-to-left
-      print screen, wrap-icon, 245/grey
-      column <- copy left
-      row <- add row, 1
-      screen <- move-cursor screen, row, column
-      loop +next-character  # retry i
-    }
-    i <- add i, 1
-    {
       # newline? move to left rather than 0
       newline?:bool <- equal c, 10/newline
       break-unless newline?
@@ -403,8 +390,23 @@ def render-text screen:&:screen, s:text, left:num, right:num, color:num, row:num
       row <- add row, 1
       column <- copy left
       screen <- move-cursor screen, row, column
+      i <- add i, 1
+      loop +next-character
+    }
+    {
+      # at right? wrap.
+      at-right?:bool <- equal column, right
+      break-unless at-right?
+      # print wrap icon
+      wrap-icon:char <- copy 8617/loop-back-to-left
+      print screen, wrap-icon, 245/grey
+      column <- copy left
+      row <- add row, 1
+      screen <- move-cursor screen, row, column
+      # don't increment i
       loop +next-character
     }
+    i <- add i, 1
     print screen, c, color
     column <- add column, 1
     loop
@@ -418,6 +420,21 @@ def render-text screen:&:screen, s:text, left:num, right:num, color:num, row:num
   move-cursor screen, row, left
 ]
 
+scenario read-text-wraps-barely-long-lines [
+  local-scope
+  assume-screen 5/width, 5/height
+  s:text <- new [abcde]
+  run [
+    render-text screen, s, 0/left, 4/right, 7/white, 1/row
+  ]
+  screen-should-contain [
+    .     .
+    .abcd↩.
+    .e    .
+    .     .
+  ]
+]
+
 # like 'render-text', but with colorization for comments like in the editor
 def render-code screen:&:screen, s:text, left:num, right:num, row:num -> row:num, screen:&:screen [
   local-scope
@@ -438,19 +455,6 @@ def render-code screen:&:screen, s:text, left:num, right:num, row:num -> row:num
     c:char <- index *s, i
     <character-c-received>  # only line different from 'render-text'
     {
-      # at right? wrap.
-      at-right?:bool <- equal column, right
-      break-unless at-right?
-      # print wrap icon
-      wrap-icon:char <- copy 8617/loop-back-to-left
-      print screen, wrap-icon, 245/grey
-      column <- copy left
-      row <- add row, 1
-      screen <- move-cursor screen, row, column
-      loop +next-character  # retry i
-    }
-    i <- add i, 1
-    {
       # newline? move to left rather than 0
       newline?:bool <- equal c, 10/newline
       break-unless newline?
@@ -466,8 +470,23 @@ def render-code screen:&:screen, s:text, left:num, right:num, row:num -> row:num
       row <- add row, 1
       column <- copy left
       screen <- move-cursor screen, row, column
+      i <- add i, 1
+      loop +next-character
+    }
+    {
+      # at right? wrap.
+      at-right?:bool <- equal column, right
+      break-unless at-right?
+      # print wrap icon
+      wrap-icon:char <- copy 8617/loop-back-to-left
+      print screen, wrap-icon, 245/grey
+      column <- copy left
+      row <- add row, 1
+      screen <- move-cursor screen, row, column
+      # don't increment i
       loop +next-character
     }
+    i <- add i, 1
     print screen, c, color
     column <- add column, 1
     loop