aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-04-19 00:16:09 -0400
committerJesse Luehrs <doy@tozt.net>2014-04-19 00:16:09 -0400
commit4ee6445e6abd50823505a818272f0328aa436eac (patch)
treeba8fd56255cdc05b353ccef6b4f78ba6511a36d9
parent693cfd3e7e46fa3288677ffd962b2ead758ae2c8 (diff)
downloadrunes-4ee6445e6abd50823505a818272f0328aa436eac.tar.gz
runes-4ee6445e6abd50823505a818272f0328aa436eac.zip
handle wide characters
the cursor doesn't handle wide characters though - this won't be possible until i actually do start keeping a logical layout of the terminal screen rather than just the image
-rw-r--r--display.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/display.c b/display.c
index fc76c8d..959e2ad 100644
--- a/display.c
+++ b/display.c
@@ -182,22 +182,33 @@ void runes_display_show_string_utf8(RunesTerm *t, char *buf, size_t len)
pos = 0;
for (i = 1; i < char_len + 1; ++i) {
if (attrs[i].is_cursor_position) {
- char *startpos;
+ char *startpos, *c;
size_t cluster_len;
+ char width = 1;
runes_display_paint_rectangle(
t, t->cr, t->bgcolor, t->col, t->row, 1, 1);
startpos = g_utf8_offset_to_pointer(buf, pos);
cluster_len = g_utf8_offset_to_pointer(buf, i) - startpos;
+
pango_layout_set_text(t->layout, startpos, cluster_len);
pango_cairo_update_layout(t->cr, t->layout);
pango_cairo_show_layout(t->cr, t->layout);
- if (t->col + 1 >= t->cols) {
+
+ for (c = startpos;
+ (size_t)(c - startpos) < cluster_len;
+ c = g_utf8_next_char(c)) {
+ if (g_unichar_iswide(g_utf8_get_char(c))) {
+ width = 2;
+ }
+ }
+
+ if (t->col + width >= t->cols) {
runes_display_move_to(t, t->row + 1, 0);
}
else {
- runes_display_move_to(t, t->row, t->col + 1);
+ runes_display_move_to(t, t->row, t->col + width);
}
pos = i;
}