about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--072scenario_screen.cc2
-rw-r--r--edit.mu41
-rw-r--r--makefile2
-rw-r--r--termbox/termbox.c8
-rw-r--r--termbox/termbox.h1
5 files changed, 51 insertions, 3 deletions
diff --git a/072scenario_screen.cc b/072scenario_screen.cc
index a2824a07..b95e99eb 100644
--- a/072scenario_screen.cc
+++ b/072scenario_screen.cc
@@ -330,7 +330,7 @@ void dump_screen() {
 //?     cerr << curr << ":\n"; //? 2
     for (long long int col = 0; col < screen_width; ++col) {
       if (Memory[curr])
-        cerr << static_cast<char>(Memory[curr]);
+        cerr << to_unicode(Memory[curr]);
       else
         cerr << ' ';
       curr += /*size of screen-cell*/2;
diff --git a/edit.mu b/edit.mu
index ef545d18..3d267266 100644
--- a/edit.mu
+++ b/edit.mu
@@ -21,7 +21,9 @@ recipe edit [
   top:number <- next-ingredient
   left:number <- next-ingredient
   bottom:number <- next-ingredient
+  bottom:number <- subtract bottom:number, 1:literal
   right:number <- next-ingredient
+  right:number <- subtract right:number, 1:literal
   keyboard:address <- next-ingredient
   # traversing inside s
   len:number <- length s:address:array:character/deref
@@ -34,7 +36,7 @@ recipe edit [
     +next-character
     done?:boolean <- greater-or-equal i:number, len:number
     break-if done?:boolean
-    off-screen?:boolean <- greater-or-equal row:number, bottom:number
+    off-screen?:boolean <- greater-than row:number, bottom:number
     break-if off-screen?:boolean
     c:character <- index s:address:array:character/deref, i:number
     {
@@ -47,6 +49,24 @@ recipe edit [
       i:number <- add i:number, 1:literal
       loop +next-character:label
     }
+    {
+      # at right? more than one letter left in the line? wrap
+      at-right?:boolean <- equal column:number, right:number
+      break-unless at-right?:boolean
+      next-index:number <- add i:number, 1:literal
+      next-at-end?:boolean <- greater-or-equal next-index:number, len:number
+      break-if next-at-end?:boolean
+      next:character <- index s:address:array:character/deref, next-index:number
+      next-character-is-newline?:boolean <- equal next:character, 10:literal/newline
+      break-if next-character-is-newline?:boolean
+      # wrap
+      print-character screen:address, 8617:literal/loop-back-to-left, 245:literal/grey
+      column:number <- copy left:number
+      row:number <- add row:number, 1:literal
+      move-cursor screen:address, row:number, column:number
+      # don't increment i
+      loop +next-character:label
+    }
     print-character screen:address, c:character
     i:number <- add i:number, 1:literal
     column:number <- add column:number, 1:literal
@@ -97,3 +117,22 @@ def]
     .     .
   ]
 ]
+
+scenario edit-wraps-long-lines [
+  assume-screen 5:literal/width, 3:literal/height
+  assume-keyboard []
+  run [
+    s:address:array:character <- new [abc def]
+    s2:address:array:character, screen:address, keyboard:address <- edit s:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/bottom, 5:literal/right, keyboard:address
+  ]
+  screen-should-contain [
+    .abc ↩.
+    .def  .
+    .     .
+  ]
+  screen-should-contain-in-color, 245:literal/grey [
+    .    ↩.
+    .     .
+    .     .
+  ]
+]
diff --git a/makefile b/makefile
index 9b357d5e..2ccf8f2c 100644
--- a/makefile
+++ b/makefile
@@ -14,7 +14,7 @@ enumerate/enumerate:
 tangle/tangle:
 	cd tangle && make && ./tangle test
 
-termbox/libtermbox.a:
+termbox/libtermbox.a: termbox/*.c termbox/*.h termbox/*.inl
 	cd termbox && make
 
 .PHONY: autogenerated_lists test valgrind clang opt clang+opt clena
diff --git a/termbox/termbox.c b/termbox/termbox.c
index eed9681d..ee10cd49 100644
--- a/termbox/termbox.c
+++ b/termbox/termbox.c
@@ -427,6 +427,14 @@ static void send_char(int x, int y, uint32_t c)
   bytebuffer_puts(&output_buffer, buf);
 }
 
+const char* to_unicode(uint32_t c)
+{
+  static char buf[7];
+  int bw = tb_utf8_unicode_to_char(buf, c);
+  buf[bw] = '\0';
+  return buf;
+}
+
 static void send_clear(void)
 {
   send_attr(foreground, background);
diff --git a/termbox/termbox.h b/termbox/termbox.h
index 9b7fd772..50a8b5e1 100644
--- a/termbox/termbox.h
+++ b/termbox/termbox.h
@@ -203,6 +203,7 @@ int tb_poll_event(struct tb_event *event);
 int tb_utf8_char_length(char c);
 int tb_utf8_char_to_unicode(uint32_t *out, const char *c);
 int tb_utf8_unicode_to_char(char *out, uint32_t c);
+const char* to_unicode(uint32_t c);
 
 #ifdef __cplusplus
 }