about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-09-01 20:31:12 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-09-01 20:31:12 -0700
commit5ca4a2af43442bf2a71255114220a2a20df7189d (patch)
treefeb5ad1a35afc088cd1ae9ad508ba6d53311ad79
parent86778aa4265a4845c8da1f3f78bdb68c14a58c4a (diff)
downloadmu-5ca4a2af43442bf2a71255114220a2a20df7189d.tar.gz
2127 - colorize sandboxes
This is really testing our premise that mu is robust to duplication. The
new routine diverges from the old in only 1 out of 68 lines.. and also
has no tests.
-rw-r--r--edit.mu71
1 files changed, 70 insertions, 1 deletions
diff --git a/edit.mu b/edit.mu
index 60545fea..31d479c2 100644
--- a/edit.mu
+++ b/edit.mu
@@ -307,6 +307,75 @@ recipe render-string [
   reply row/same-as-ingredient:5, screen/same-as-ingredient:0
 ]
 
+# row, screen <- render-code-string screen:address, s:address:array:character, left:number, right:number, row:number
+# like 'render-string' but with colorization for comments like in the editor
+recipe render-code-string [
+  local-scope
+  screen:address <- next-ingredient
+  s:address:array:character <- next-ingredient
+  left:number <- next-ingredient
+  right:number <- next-ingredient
+  row:number <- next-ingredient
+  row <- add row, 1
+  reply-unless s, row/same-as-ingredient:4, screen/same-as-ingredient:0
+  color:number <- copy 7/white
+  column:number <- copy left
+  screen <- move-cursor screen, row, column
+  screen-height:number <- screen-height screen
+  i:number <- copy 0
+  len:number <- length *s
+  {
+    +next-character
+    done?:boolean <- greater-or-equal i, len
+    break-if done?
+    done? <- greater-or-equal row, screen-height
+    break-if done?
+    c:character <- index *s, i
+    +character-c-received  # only line different from render-string
+    {
+      # at right? wrap.
+      at-right?:boolean <- equal column, right
+      break-unless at-right?
+      # print wrap icon
+      print-character screen, 8617/loop-back-to-left, 245/grey
+      column <- copy left
+      row <- add row, 1
+      screen <- move-cursor screen, row, column
+      loop +next-character:label  # retry i
+    }
+    i <- add i, 1
+    {
+      # newline? move to left rather than 0
+      newline?:boolean <- equal c, 10/newline
+      break-unless newline?
+      # clear rest of line in this window
+      {
+        done?:boolean <- greater-than column, right
+        break-if done?
+        print-character screen, 32/space
+        column <- add column, 1
+        loop
+      }
+      row <- add row, 1
+      column <- copy left
+      screen <- move-cursor screen, row, column
+      loop +next-character:label
+    }
+    print-character screen, c, color
+    column <- add column, 1
+    loop
+  }
+  {
+    # clear rest of current line
+    line-done?:boolean <- greater-than column, right
+    break-if line-done?
+    print-character screen, 32/space
+    column <- add column, 1
+    loop
+  }
+  reply row/same-as-ingredient:4, screen/same-as-ingredient:0
+]
+
 recipe clear-line-delimited [
   local-scope
   screen:address <- next-ingredient
@@ -5403,7 +5472,7 @@ recipe render-sandboxes [
   *starting-row <- copy row
   # render sandbox contents
   sandbox-data:address:array:character <- get *sandbox, data:offset
-  row, screen <- render-string screen, sandbox-data, left, right, 7/white, row
+  row, screen <- render-code-string screen, sandbox-data, left, right, row
   code-ending-row:address:number <- get-address *sandbox, code-ending-row-on-screen:offset
   *code-ending-row <- copy row
   # render sandbox warnings, screen or response, in that order