about summary refs log tree commit diff stats
path: root/termbox/termbox.c
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-05-19 00:09:18 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-05-19 00:09:18 -0700
commit537ad74cccc709b14418114e177d595ce3812627 (patch)
treefd0f7779e54c207a6debee0e806f29820375222d /termbox/termbox.c
parentb6fa632e2f46467c76c7fb39c731cb17e8558ee0 (diff)
downloadmu-537ad74cccc709b14418114e177d595ce3812627.tar.gz
3862
As the finishing touch on commit 3860, completely decouple the termbox
API between moving the cursor and printing at the cursor.
Diffstat (limited to 'termbox/termbox.c')
-rw-r--r--termbox/termbox.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/termbox/termbox.c b/termbox/termbox.c
index 46584a19..c97f03d5 100644
--- a/termbox/termbox.c
+++ b/termbox/termbox.c
@@ -45,7 +45,6 @@ static uint16_t foreground = TB_WHITE;
 static void update_size(void);
 static void update_term_size(void);
 static void send_attr(uint16_t fg, uint16_t bg);
-static void send_char(int x, int y, uint32_t c);
 static void send_clear(void);
 static void sigwinch_handler(int xxx);
 static int wait_fill_event(struct tb_event *event, struct timeval *timeout);
@@ -99,6 +98,7 @@ int tb_init(void)
   bytebuffer_puts(&output_buffer, funcs[T_ENTER_KEYPAD]);
   bytebuffer_puts(&output_buffer, funcs[T_ENTER_MOUSE]);
   bytebuffer_puts(&output_buffer, funcs[T_ENTER_BRACKETED_PASTE]);
+  bytebuffer_flush(&output_buffer, inout);
 
   update_term_size();
   return 0;
@@ -130,11 +130,20 @@ int tb_is_active(void)
   return termw != -1;
 }
 
-void tb_change_cell(int x, int y, uint32_t ch, uint16_t fg, uint16_t bg)
+void tb_print(uint32_t ch, uint16_t fg, uint16_t bg)
 {
   assert(termw != -1);
   send_attr(fg, bg);
-  send_char(x, y, ch);
+  if (ch == 0) {
+    // replace 0 with whitespace
+    bytebuffer_puts(&output_buffer, " ");
+  }
+  else {
+    char buf[7];
+    int bw = tb_utf8_unicode_to_char(buf, ch);
+    buf[bw] = '\0';
+    bytebuffer_puts(&output_buffer, buf);
+  }
   bytebuffer_flush(&output_buffer, inout);
 }
 
@@ -265,16 +274,6 @@ static void send_attr(uint16_t fg, uint16_t bg)
   }
 }
 
-static void send_char(int x, int y, uint32_t c)
-{
-  char buf[7];
-  int bw = tb_utf8_unicode_to_char(buf, c);
-  buf[bw] = '\0';
-  tb_set_cursor(x, y);
-  if(!c) buf[0] = ' '; // replace 0 with whitespace
-  bytebuffer_puts(&output_buffer, buf);
-}
-
 const char* to_unicode(uint32_t c)
 {
   static char buf[7];