about summary refs log tree commit diff stats
path: root/sandbox
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-03-14 08:06:07 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-03-14 08:17:27 -0700
commit16697d408cebb7e7060a76c4eb3c9a8fe1ae64e7 (patch)
tree02778b827ace2ac51215714f3e83ab9b7370a23a /sandbox
parent3b82206fd6143da6be50ff5f3c7e4c050039548a (diff)
downloadmu-16697d408cebb7e7060a76c4eb3c9a8fe1ae64e7.tar.gz
3793
Move 'render-code' to the layer where it's used.

Thanks Caleb Couch for finding this bit of ugliness.
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/004-programming-environment.mu63
-rw-r--r--sandbox/005-sandbox.mu63
2 files changed, 63 insertions, 63 deletions
diff --git a/sandbox/004-programming-environment.mu b/sandbox/004-programming-environment.mu
index 13502d2a..7d86de8c 100644
--- a/sandbox/004-programming-environment.mu
+++ b/sandbox/004-programming-environment.mu
@@ -269,69 +269,6 @@ def update-cursor screen:&:screen, current-sandbox:&:editor, env:&:environment -
   screen <- move-cursor screen, cursor-row, cursor-column
 ]
 
-# like 'render' for texts, 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
-  load-ingredients
-  return-unless s
-  color:num <- copy 7/white
-  column:num <- copy left
-  screen <- move-cursor screen, row, column
-  screen-height:num <- screen-height screen
-  i:num <- copy 0
-  len:num <- length *s
-  {
-    +next-character
-    done?:bool <- greater-or-equal i, len
-    break-if done?
-    done? <- greater-or-equal row, screen-height
-    break-if done?
-    c:char <- index *s, i
-    <character-c-received>  # only line different from render
-    {
-      # 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?
-      # clear rest of line in this window
-      {
-        done?:bool <- greater-than column, right
-        break-if done?
-        space:char <- copy 32/space
-        print screen, space
-        column <- add column, 1
-        loop
-      }
-      row <- add row, 1
-      column <- copy left
-      screen <- move-cursor screen, row, column
-      loop +next-character
-    }
-    print screen, c, color
-    column <- add column, 1
-    loop
-  }
-  was-at-left?:bool <- equal column, left
-  clear-line-until screen, right
-  {
-    break-if was-at-left?
-    row <- add row, 1
-  }
-  move-cursor screen, row, left
-]
-
 # ctrl-l - redraw screen (just in case it printed junk somehow)
 
 after <global-type> [
diff --git a/sandbox/005-sandbox.mu b/sandbox/005-sandbox.mu
index be3c1f5d..6b0098bb 100644
--- a/sandbox/005-sandbox.mu
+++ b/sandbox/005-sandbox.mu
@@ -408,6 +408,69 @@ def render-text screen:&:screen, s:text, left:num, right:num, color:num, row:num
   move-cursor screen, row, left
 ]
 
+# like 'render' for texts, 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
+  load-ingredients
+  return-unless s
+  color:num <- copy 7/white
+  column:num <- copy left
+  screen <- move-cursor screen, row, column
+  screen-height:num <- screen-height screen
+  i:num <- copy 0
+  len:num <- length *s
+  {
+    +next-character
+    done?:bool <- greater-or-equal i, len
+    break-if done?
+    done? <- greater-or-equal row, screen-height
+    break-if done?
+    c:char <- index *s, i
+    <character-c-received>  # only line different from render
+    {
+      # 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?
+      # clear rest of line in this window
+      {
+        done?:bool <- greater-than column, right
+        break-if done?
+        space:char <- copy 32/space
+        print screen, space
+        column <- add column, 1
+        loop
+      }
+      row <- add row, 1
+      column <- copy left
+      screen <- move-cursor screen, row, column
+      loop +next-character
+    }
+    print screen, c, color
+    column <- add column, 1
+    loop
+  }
+  was-at-left?:bool <- equal column, left
+  clear-line-until screen, right
+  {
+    break-if was-at-left?
+    row <- add row, 1
+  }
+  move-cursor screen, row, left
+]
+
 # assumes programming environment has no sandboxes; restores them from previous session
 def restore-sandboxes env:&:environment, resources:&:resources -> env:&:environment [
   local-scope