aboutsummaryrefslogtreecommitdiff
path: root/vt.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-05-27 18:07:28 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-06-24 15:30:45 +0000
commit0a9531ac6caff2ad6abfbb804ec27cade4a92e7a (patch)
tree33cdf629fe3e99d1e2afe3cc181b100af8fb9a67 /vt.c
parentwip: grapheme shaping (diff)
vt: cache grapheme cluster width in composed struct
* Use regular wcswidth() to calculate the width * Explicitly set to ‘2’ if we see a emoji variant selector * Cache the result in the composed struct
Diffstat (limited to 'vt.c')
-rw-r--r--vt.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/vt.c b/vt.c
index 496333d7..6ad539d7 100644
--- a/vt.c
+++ b/vt.c
@@ -716,9 +716,8 @@ action_utf8_print(struct terminal *term, wchar_t wc)
if (cc->chars[wanted_count - 1] != wc)
continue;
- int grapheme_width = my_wcswidth(cc->chars, cc->count);
- if (grapheme_width > 0)
- term_print(term, CELL_COMB_CHARS_LO + i, grapheme_width);
+ if (cc->width > 0)
+ term_print(term, CELL_COMB_CHARS_LO + i, cc->width);
return;
}
@@ -732,11 +731,18 @@ action_utf8_print(struct terminal *term, wchar_t wc)
new_cc.chars[wanted_count - 1] = wc;
if (term->composed_count < CELL_COMB_CHARS_HI) {
+ /* TODO: grapheme cluster width */
+ int grapheme_width = wcswidth(new_cc.chars, new_cc.count);
+ if (new_cc.chars[new_cc.count - 1] == 0xfe0f) {
+ /* Emoji selector */
+ grapheme_width = 2;
+ }
+ new_cc.width = grapheme_width;
+
term->composed_count++;
term->composed = xrealloc(term->composed, term->composed_count * sizeof(term->composed[0]));
term->composed[term->composed_count - 1] = new_cc;
- int grapheme_width = my_wcswidth(new_cc.chars, new_cc.count);
if (grapheme_width > 0)
term_print(term, CELL_COMB_CHARS_LO + term->composed_count - 1, grapheme_width);
return;