From 7e664cbeb3d3402f057753d178cf770a017dc384 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 25 Apr 2014 22:59:43 -0400 Subject: handle wide characters --- src/screen.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/screen.c') diff --git a/src/screen.c b/src/screen.c index 9d77ea3..1b460e6 100644 --- a/src/screen.c +++ b/src/screen.c @@ -69,6 +69,7 @@ void runes_screen_show_string_ascii(RunesTerm *t, char *buf, size_t len) cell->contents[0] = buf[i]; cell->contents[1] = '\0'; cell->attrs = scr->attrs; + cell->is_wide = 0; runes_screen_move_to(t, scr->cur.row, scr->cur.col + 1); } @@ -83,17 +84,23 @@ void runes_screen_show_string_utf8(RunesTerm *t, char *buf, size_t len) * cell */ while ((next = g_utf8_next_char(c))) { struct runes_cell *cell; + int is_wide; - if (scr->cur.col >= scr->max.col) { + /* XXX handle zero width characters */ + is_wide = g_unichar_iswide(g_utf8_get_char(c)); + + if (scr->cur.col + (is_wide ? 2 : 1) > scr->max.col) { runes_screen_move_to(t, scr->cur.row + 1, 0); } cell = &scr->rows[scr->cur.row].cells[scr->cur.col]; + cell->is_wide = is_wide; cell->len = next - c; strncpy(cell->contents, c, cell->len); cell->attrs = scr->attrs; - runes_screen_move_to(t, scr->cur.row, scr->cur.col + 1); + runes_screen_move_to( + t, scr->cur.row, scr->cur.col + (is_wide ? 2 : 1)); c = next; if ((size_t)(c - buf) >= len) { break; -- cgit v1.2.3-54-g00ecf