aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-04-25 00:47:18 -0400
committerJesse Luehrs <doy@tozt.net>2014-04-25 00:48:09 -0400
commit380ff5c7d4af746185026086a4fc5e9a97655465 (patch)
tree265f84d226376cdf71c7241bc487168a18f962cf
parentc59379881c47b5b803fb14865cfe7d04a536e6f2 (diff)
downloadrunes-380ff5c7d4af746185026086a4fc5e9a97655465.tar.gz
runes-380ff5c7d4af746185026086a4fc5e9a97655465.zip
handle utf8 characters
still only codepoints at the moment, still need to handle glyph clusters
-rw-r--r--src/screen.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/screen.c b/src/screen.c
index 5014474..98236a8 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -61,9 +61,9 @@ void runes_screen_show_string_ascii(RunesTerm *t, char *buf, size_t len)
}
cell = &scr->rows[scr->cur.row].cells[scr->cur.col];
+ cell->len = 1;
cell->contents[0] = buf[i];
cell->contents[1] = '\0';
- cell->len = 1;
scr->cur.col++;
}
@@ -71,10 +71,29 @@ void runes_screen_show_string_ascii(RunesTerm *t, char *buf, size_t len)
void runes_screen_show_string_utf8(RunesTerm *t, char *buf, size_t len)
{
- UNUSED(t);
- UNUSED(buf);
- UNUSED(len);
- fprintf(stderr, "show_string_utf8 nyi\n");
+ RunesScreen *scr = &t->scr;
+ char *c = buf, *next;
+
+ /* XXX need to detect combining characters and append them to the previous
+ * cell */
+ while ((next = g_utf8_next_char(c))) {
+ struct runes_cell *cell;
+
+ if (scr->cur.col >= scr->max.col) {
+ scr->cur.col = 0;
+ scr->cur.row++;
+ }
+ cell = &scr->rows[scr->cur.row].cells[scr->cur.col];
+
+ cell->len = next - c;
+ strncpy(cell->contents, c, cell->len);
+
+ scr->cur.col++;
+ c = next;
+ if ((size_t)(c - buf) >= len) {
+ break;
+ }
+ }
}
void runes_screen_move_to(RunesTerm *t, int row, int col)