aboutsummaryrefslogtreecommitdiff
path: root/test/unit/fixtures/vterm_test.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2025-01-03 10:43:22 +0100
committerGitHub <noreply@github.com>2025-01-03 10:43:22 +0100
commit6aceab7c201f93d96b4359f0e1d97bd6f2f29ea6 (patch)
treee48d52290f6123315ccf29cd782cc757e1097137 /test/unit/fixtures/vterm_test.c
parent43d552c56648bc3125c7509b3d708b6bf6c0c09c (diff)
parente3bfcf2fd4a4ebf00b104b082cfe83c8144a842d (diff)
downloadrneovim-6aceab7c201f93d96b4359f0e1d97bd6f2f29ea6.tar.gz
rneovim-6aceab7c201f93d96b4359f0e1d97bd6f2f29ea6.tar.bz2
rneovim-6aceab7c201f93d96b4359f0e1d97bd6f2f29ea6.zip
Merge pull request #31635 from bfredl/vtermpirates
feat(terminal): support grapheme clusters, including emoji
Diffstat (limited to 'test/unit/fixtures/vterm_test.c')
-rw-r--r--test/unit/fixtures/vterm_test.c37
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;