diff options
author | bfredl <bjorn.linse@gmail.com> | 2024-12-18 14:49:38 +0100 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2025-01-02 12:55:11 +0100 |
commit | e3bfcf2fd4a4ebf00b104b082cfe83c8144a842d (patch) | |
tree | 8c4e09f0995db6668e13b3508b112779bea1312d /test/unit/fixtures | |
parent | 9d9ee3476e6478850ce8822c85154f0c98570371 (diff) | |
download | rneovim-e3bfcf2fd4a4ebf00b104b082cfe83c8144a842d.tar.gz rneovim-e3bfcf2fd4a4ebf00b104b082cfe83c8144a842d.tar.bz2 rneovim-e3bfcf2fd4a4ebf00b104b082cfe83c8144a842d.zip |
feat(terminal): support grapheme clusters, including emoji
Diffstat (limited to 'test/unit/fixtures')
-rw-r--r-- | test/unit/fixtures/vterm_test.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/test/unit/fixtures/vterm_test.c b/test/unit/fixtures/vterm_test.c index f227ae4591..8755e32e7a 100644 --- a/test/unit/fixtures/vterm_test.c +++ b/test/unit/fixtures/vterm_test.c @@ -1,4 +1,6 @@ #include <stdio.h> +#include "nvim/grid.h" +#include "nvim/mbyte.h" #include "vterm_test.h" @@ -202,6 +204,26 @@ int selection_query(VTermSelectionMask mask, void *user) return 1; } +static void print_schar(FILE *f, schar_T schar) { + char buf[MAX_SCHAR_SIZE]; + schar_get(buf, schar); + StrCharInfo ci = utf_ptr2StrCharInfo(buf); + bool did = false; + while (*ci.ptr != 0) { + if (did) { + fprintf(f, ","); + } + + if (ci.chr.len == 1 && ci.chr.value >= 0x80) { + fprintf(f, "??%x", ci.chr.value); + } else { + fprintf(f, "%x", ci.chr.value); + } + did = true; + ci = utf_ptr2StrCharInfo(ci.ptr + ci.chr.len); + } +} + bool want_state_putglyph; int state_putglyph(VTermGlyphInfo *info, VTermPos pos, void *user) { @@ -211,9 +233,7 @@ int state_putglyph(VTermGlyphInfo *info, VTermPos pos, void *user) FILE *f = fopen(VTERM_TEST_FILE, "a"); fprintf(f, "putglyph "); - for (int i = 0; i < VTERM_MAX_CHARS_PER_CELL && info->chars[i]; i++) { - fprintf(f, i ? ",%x" : "%x", info->chars[i]); - } + print_schar(f, info->schar); fprintf(f, " %d %d,%d", info->width, pos.row, pos.col); if (info->protected_cell) { fprintf(f, " prot"); @@ -443,14 +463,15 @@ int screen_sb_pushline(int cols, const VTermScreenCell *cells, void *user) } int eol = cols; - while (eol && !cells[eol - 1].chars[0]) { + while (eol && !cells[eol-1].schar) { eol--; } FILE *f = fopen(VTERM_TEST_FILE, "a"); fprintf(f, "sb_pushline %d =", cols); for (int c = 0; c < eol; c++) { - fprintf(f, " %02X", cells[c].chars[0]); + fprintf(f, " "); + print_schar(f, cells[c].schar); } fprintf(f, "\n"); @@ -467,10 +488,10 @@ int screen_sb_popline(int cols, VTermScreenCell *cells, void *user) // All lines of scrollback contain "ABCDE" for (int col = 0; col < cols; col++) { - if (col < 5) { - cells[col].chars[0] = (uint32_t)('A' + col); + if(col < 5) { + cells[col].schar = schar_from_ascii((uint32_t)('A' + col)); } else { - cells[col].chars[0] = 0; + cells[col].schar = 0; } cells[col].width = 1; |