diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2017-05-19 00:09:18 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2017-05-19 00:09:18 -0700 |
commit | 537ad74cccc709b14418114e177d595ce3812627 (patch) | |
tree | fd0f7779e54c207a6debee0e806f29820375222d /termbox | |
parent | b6fa632e2f46467c76c7fb39c731cb17e8558ee0 (diff) | |
download | mu-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')
-rw-r--r-- | termbox/termbox.c | 25 | ||||
-rw-r--r-- | termbox/termbox.h | 8 |
2 files changed, 16 insertions, 17 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]; diff --git a/termbox/termbox.h b/termbox/termbox.h index 97306142..43b326cb 100644 --- a/termbox/termbox.h +++ b/termbox/termbox.h @@ -37,16 +37,16 @@ int tb_is_active(void); int tb_width(void); int tb_height(void); -/* Clear the internal screen state using either TB_DEFAULT or the - * color/attributes set by tb_set_clear_attributes(). */ +/* Clear the screen using either TB_DEFAULT or the color/attributes set by + * tb_set_clear_attributes(). */ void tb_clear(void); void tb_set_clear_attributes(uint16_t fg, uint16_t bg); /* Move the cursor. Upper-left character is (0, 0). */ void tb_set_cursor(int cx, int cy); -/* Modify a specific cell of the screen. */ -void tb_change_cell(int x, int y, uint32_t ch, uint16_t fg, uint16_t bg); +/* Modify the screen at the cursor. */ +void tb_print(uint32_t ch, uint16_t fg, uint16_t bg); /*** 2. Controlling keyboard events. */ |