diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-15 13:04:32 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-15 13:04:32 +0300 |
| commit | bdaedce69b17b654bd0060579dd9b9ff120009b5 (patch) | |
| tree | 0e9cd8597652263a96c48ba678fb0b66e1fc131b /tests/term_test.c | |
| parent | ba75c8b0a1bba03ad92c53375432f122ddb4cb98 (diff) | |
| parent | dcebf9c7f954a55350b68d0ead1935612c4e2e05 (diff) | |
Merge branch 'wt/rename' into api-hardening
# Conflicts:
# README.md
Diffstat (limited to 'tests/term_test.c')
| -rw-r--r-- | tests/term_test.c | 1008 |
1 files changed, 504 insertions, 504 deletions
diff --git a/tests/term_test.c b/tests/term_test.c index 235e9df..0e7d986 100644 --- a/tests/term_test.c +++ b/tests/term_test.c @@ -1,6 +1,6 @@ #include "term_api.h" -#include "term/unicode/unicode.h" -#include "term/unicode/utf8.h" +#include "wsap_vtcore/unicode/unicode.h" +#include "wsap_vtcore/unicode/utf8.h" #include <assert.h> #include <limits.h> #include <pthread.h> @@ -27,21 +27,21 @@ static void capture_title(void *ud, const char *s) (void)ud; snprintf(title, sizeof(title), "%s", s); } -static const struct term_callbacks reply_cb = { .reply = respond }; -static const struct term_callbacks title_cb = { .reply = respond, .title = capture_title }; +static const struct wsap_vtcore_callbacks reply_cb = { .reply = respond }; +static const struct wsap_vtcore_callbacks title_cb = { .reply = respond, .title = capture_title }; -static void write_seq(struct term *t, const char *s) +static void write_seq(struct wsap_vtcore *t, const char *s) { for (; *s; s++) tt_write(t, s, 1); } -static void feed_seq(struct term *t, const char *s, unsigned flags) +static void feed_seq(struct wsap_vtcore *t, const char *s, unsigned flags) { - for (; *s; s++) term_feed(t, s, 1, flags); + for (; *s; s++) wsap_vtcore_feed(t, s, 1, flags); } -static const char *row_text(struct term *t, int r, char *buf) +static const char *row_text(struct wsap_vtcore *t, int r, char *buf) { - const struct term_cell *cells = term_snapshot_row(tt_snapshot_for(t), r); + const struct wsap_vtcore_cell *cells = wsap_vtcore_snapshot_row(tt_snapshot_for(t), r); int n = 0; for (int c = 0; c < tt_cols(t); c++) { uint32_t cp = tt_cell_cp(t, &cells[c]); @@ -52,7 +52,7 @@ static const char *row_text(struct term *t, int r, char *buf) buf[n] = 0; return buf; } -static bool row_eq(struct term *t, int r, const char *want) +static bool row_eq(struct wsap_vtcore *t, int r, const char *want) { char *got = malloc((size_t)tt_cols(t) + 1); assert(got); @@ -60,7 +60,7 @@ static bool row_eq(struct term *t, int r, const char *want) free(got); return equal; } -static bool row_is(struct term *t, int r, const char *want) +static bool row_is(struct wsap_vtcore *t, int r, const char *want) { char *got = malloc((size_t)tt_cols(t) + 1); assert(got); @@ -71,7 +71,7 @@ static bool row_is(struct term *t, int r, const char *want) return equal; } -static void write_both(struct term *whole, struct term *bytes, const char *s) +static void write_both(struct wsap_vtcore *whole, struct wsap_vtcore *bytes, const char *s) { tt_write(whole, s, strlen(s)); write_seq(bytes, s); @@ -79,10 +79,10 @@ static void write_both(struct term *whole, struct term *bytes, const char *s) /* The view version of s after it copies t. A renderer redraws when the * version changes. */ -static uint64_t view_version(struct term_snapshot *s, struct term *t) +static uint64_t view_version(struct wsap_vtcore_snapshot *s, struct wsap_vtcore *t) { - term_snapshot_update(s, t); - return term_snapshot_view(s)->version; + wsap_vtcore_snapshot_update(s, t); + return wsap_vtcore_snapshot_view(s)->version; } /* @@ -102,12 +102,12 @@ static void test_skipped_cells_read_blank(void) /* row_text() reads U+2026 as '?'. */ static const char *const want[] = { "ab cd ef", "a?b c", "ab cd" }; for (size_t k = 0; k < sizeof(lines) / sizeof(lines[0]); k++) { - struct term *whole = tt_new(20, 4); - struct term *bytes = tt_new(20, 4); + struct wsap_vtcore *whole = tt_new(20, 4); + struct wsap_vtcore *bytes = tt_new(20, 4); for (int i = 0; i < 12; i++) write_both(whole, bytes, "XXXXXXXXXXXXXXXXXXXX\r\n"); write_both(whole, bytes, lines[k]); - for (struct term *t = whole; t; t = t == whole ? bytes : NULL) { + for (struct wsap_vtcore *t = whole; t; t = t == whole ? bytes : NULL) { char *got = malloc((size_t)tt_cols(t) + 1); assert(got); row_text(t, 3, got); @@ -118,39 +118,39 @@ static void test_skipped_cells_read_blank(void) } free(got); } - term_free(whole); - term_free(bytes); + wsap_vtcore_free(whole); + wsap_vtcore_free(bytes); } - struct term *whole = tt_new(20, 4); - struct term *bytes = tt_new(20, 4); + struct wsap_vtcore *whole = tt_new(20, 4); + struct wsap_vtcore *bytes = tt_new(20, 4); write_both(whole, bytes, "abcdefgh\r\033[2C\033[K\033[2CZ"); assert(row_is(whole, 0, "ab Z")); assert(row_is(bytes, 0, "ab Z")); - term_free(whole); - term_free(bytes); + wsap_vtcore_free(whole); + wsap_vtcore_free(bytes); } /* Compare the first rows of both viewports cell by cell. Each terminal gets * its own snapshot. A cluster has a different handle in each snapshot, so * the test compares its code points. */ -static void assert_same_rows(struct term *a, struct term *b, int rows) +static void assert_same_rows(struct wsap_vtcore *a, struct wsap_vtcore *b, int rows) { - struct term_snapshot *sa = term_snapshot_new(); - struct term_snapshot *sb = term_snapshot_new(); - bool copied = sa && sb && term_snapshot_update(sa, a) && term_snapshot_update(sb, b); + struct wsap_vtcore_snapshot *sa = wsap_vtcore_snapshot_new(); + struct wsap_vtcore_snapshot *sb = wsap_vtcore_snapshot_new(); + bool copied = sa && sb && wsap_vtcore_snapshot_update(sa, a) && wsap_vtcore_snapshot_update(sb, b); assert(copied); - int cols = term_snapshot_view(sa)->size.x; - assert(cols == term_snapshot_view(sb)->size.x); + int cols = wsap_vtcore_snapshot_view(sa)->size.x; + assert(cols == wsap_vtcore_snapshot_view(sb)->size.x); for (int y = 0; y < rows; y++) { - const struct term_cell *ra = term_snapshot_row(sa, y); - const struct term_cell *rb = term_snapshot_row(sb, y); + const struct wsap_vtcore_cell *ra = wsap_vtcore_snapshot_row(sa, y); + const struct wsap_vtcore_cell *rb = wsap_vtcore_snapshot_row(sb, y); assert(ra && rb); for (int x = 0; x < cols; x++) { - const struct term_cell *ac = &ra[x], *bc = &rb[x]; + const struct wsap_vtcore_cell *ac = &ra[x], *bc = &rb[x]; uint32_t acp[32], bcp[32]; - int an = term_snapshot_cluster(sa, ac->text, acp, 32); - int bn = term_snapshot_cluster(sb, bc->text, bcp, 32); + int an = wsap_vtcore_snapshot_cluster(sa, ac->text, acp, 32); + int bn = wsap_vtcore_snapshot_cluster(sb, bc->text, bcp, 32); bool same = an == bn && an <= 32 && !memcmp(acp, bcp, (size_t)an * sizeof(*acp)) && ac->fg == bc->fg && ac->bg == bc->bg && @@ -164,16 +164,16 @@ static void assert_same_rows(struct term *a, struct term *b, int rows) } } } - term_snapshot_free(sa); - term_snapshot_free(sb); + wsap_vtcore_snapshot_free(sa); + wsap_vtcore_snapshot_free(sb); } -static void assert_same_screen(struct term *a, struct term *b) +static void assert_same_screen(struct wsap_vtcore *a, struct wsap_vtcore *b) { assert(tt_cursor_x(a) == tt_cursor_x(b)); assert(tt_cursor_y(a) == tt_cursor_y(b)); assert(tt_history(a) == tt_history(b)); - assert(term_modes(a).synchronized == term_modes(b).synchronized); + assert(wsap_vtcore_modes(a).synchronized == wsap_vtcore_modes(b).synchronized); assert(tt_rows(a) == tt_rows(b)); assert_same_rows(a, b, tt_rows(a)); } @@ -187,24 +187,24 @@ static void test_read_boundaries(void) "\033[?1049halt\033[?1049lZ" "\033]11;?\007\033Pignored\033\\" "\xf0\x9f\x98\x80\xc3XQ©️界\033[2G\033[P"; - struct term *expected = tt_new(16, 4); + struct wsap_vtcore *expected = tt_new(16, 4); tt_write(expected, input, sizeof(input) - 1); for (size_t split = 0; split < sizeof(input); split++) { - struct term *actual = tt_new(16, 4); + struct wsap_vtcore *actual = tt_new(16, 4); tt_write(actual, input, split); tt_write(actual, input + split, sizeof(input) - 1 - split); assert_same_screen(actual, expected); - term_free(actual); + wsap_vtcore_free(actual); } /* The byte that ends an unfinished sequence is not lost. */ - struct term *t = tt_new(16, 4); + struct wsap_vtcore *t = tt_new(16, 4); write_seq(t, "\xc3XQ"); assert(tt_cell_cp(t, tt_cell(t, 0, 0)) == 0xFFFD); assert(tt_cell_cp(t, tt_cell(t, 1, 0)) == 'X'); assert(tt_cell_cp(t, tt_cell(t, 2, 0)) == 'Q'); - term_free(t); - term_free(expected); + wsap_vtcore_free(t); + wsap_vtcore_free(expected); } static void test_ascii_controls(void) @@ -218,8 +218,8 @@ static void test_ascii_controls(void) memcpy(input + 29, separators[c], n); memset(input + 29 + n, 'b', 173); input[202 + n] = '\0'; - struct term *bulk = tt_new(120, 6); - struct term *bytes = tt_new(120, 6); + struct wsap_vtcore *bulk = tt_new(120, 6); + struct wsap_vtcore *bytes = tt_new(120, 6); const char *setup = bottom ? "\033[6;1H\033[1;3;4;38;2;12;34;56m" : "\033[1;3;4;38;2;12;34;56m"; write_seq(bulk, setup); @@ -227,18 +227,18 @@ static void test_ascii_controls(void) tt_write(bulk, input, strlen(input)); write_seq(bytes, input); assert_same_screen(bulk, bytes); - term_scroll(bulk, 6); - term_scroll(bytes, 6); + wsap_vtcore_scroll(bulk, 6); + wsap_vtcore_scroll(bytes, 6); assert_same_screen(bulk, bytes); - term_free(bulk); - term_free(bytes); + wsap_vtcore_free(bulk); + wsap_vtcore_free(bytes); } } } static void test_esc_control_strings_and_designators(void) { - struct term *t = tt_new(32, 2); + struct wsap_vtcore *t = tt_new(32, 2); assert(t); write_seq(t, "A\033_payload ignored\033\\B"); @@ -253,13 +253,13 @@ static void test_esc_control_strings_and_designators(void) write_seq(t, "\033.Am\033*0n"); assert(row_is(t, 0, "ABCDxyz%qxmn")); - term_free(t); + wsap_vtcore_free(t); t = tt_new(8, 2); write_seq(t, "A\033_ignored\033DB"); assert(row_is(t, 0, "A")); assert(row_is(t, 1, " B")); - term_free(t); + wsap_vtcore_free(t); } static void test_random_read_boundaries(void) @@ -277,11 +277,11 @@ static void test_random_read_boundaries(void) input[i] = (char)(random >> 16); } memcpy(input + 400, embedded, sizeof(embedded) - 1); - struct term *whole = tt_new(32, 8); + struct wsap_vtcore *whole = tt_new(32, 8); tt_write(whole, input, sizeof(input)); for (size_t c = 0; c < sizeof(chunks) / sizeof(chunks[0]); c++) { - struct term *a = tt_new(32, 8); - struct term *b = tt_new(32, 8); + struct wsap_vtcore *a = tt_new(32, 8); + struct wsap_vtcore *b = tt_new(32, 8); for (size_t block = 0; block < sizeof(input); block += 128) { tt_write(a, input + block, 128); for (size_t i = block; i < block + 128;) { @@ -298,14 +298,14 @@ static void test_random_read_boundaries(void) assert_same_screen(a, b); int history = tt_history(a); for (int i = 0; i < history; i += 8) { - term_scroll(a, 8); - term_scroll(b, 8); + wsap_vtcore_scroll(a, 8); + wsap_vtcore_scroll(b, 8); assert_same_screen(a, b); } - term_free(a); - term_free(b); + wsap_vtcore_free(a); + wsap_vtcore_free(b); } - term_free(whole); + wsap_vtcore_free(whole); } } @@ -330,13 +330,13 @@ static void test_csi_recovery(void) for (size_t c = 0; c < sizeof(cases) / sizeof(cases[0]); c++) { size_t len = strlen(cases[c].input); for (size_t split = 0; split <= len; split++) { - struct term *t = tt_new(20, 4); + struct wsap_vtcore *t = tt_new(20, 4); tt_write(t, cases[c].input, split); tt_write(t, cases[c].input + split, len - split); assert(row_is(t, 0, cases[c].first)); assert(row_is(t, 1, cases[c].second)); - for (int x = 0; x < 20; x++) assert(tt_cell(t, x, 0)->fg == TERM_COLOR_FG); - term_free(t); + for (int x = 0; x < 20; x++) assert(tt_cell(t, x, 0)->fg == WSAP_VTCORE_COLOR_FG); + wsap_vtcore_free(t); } } } @@ -353,31 +353,31 @@ static void test_csi_byte_boundaries(void) static const char suffix[] = "mX\033[6n\033[?25l\033[?25h\033[0mY"; memcpy(input + n, suffix, sizeof(suffix) - 1); n += sizeof(suffix) - 1; - struct term *whole = tt_new_opts(20, 4, &reply_cb); + struct wsap_vtcore *whole = tt_new_opts(20, 4, &reply_cb); response_len = 0; tt_write(whole, input, n); char expected_response[64]; size_t expected_len = response_len; memcpy(expected_response, response, expected_len); for (size_t split = 0; split <= strlen(prefixes[p]) + 2; split++) { - struct term *parts = tt_new_opts(20, 4, &reply_cb); + struct wsap_vtcore *parts = tt_new_opts(20, 4, &reply_cb); response_len = 0; tt_write(parts, input, split); tt_write(parts, input + split, n - split); assert_same_screen(whole, parts); - assert(term_cursor(whole).visible == term_cursor(parts).visible); + assert(wsap_vtcore_cursor(whole).visible == wsap_vtcore_cursor(parts).visible); assert(response_len == expected_len); assert(!memcmp(response, expected_response, expected_len)); - term_free(parts); + wsap_vtcore_free(parts); } - term_free(whole); + wsap_vtcore_free(whole); } } } static void test_parameter_limits(void) { - struct term *t = tt_new(10, 4); + struct wsap_vtcore *t = tt_new(10, 4); write_seq(t, "\033[2;4r\033[?6h\033[999999999999999999999;1H"); assert(tt_cursor_y(t) == 3 && tt_cursor_x(t) == 0); write_seq(t, "\033[?6l\033[r"); @@ -387,26 +387,26 @@ static void test_parameter_limits(void) write_seq(t, "\033[999999999999999999999A\033[999999999999999999999D"); assert(tt_cursor_y(t) == 0 && tt_cursor_x(t) == 0); write_seq(t, "\033[38;5;999999999999999999999mX"); - assert(tt_cell(t, 0, 0)->fg == TERM_COLOR_FG); + assert(tt_cell(t, 0, 0)->fg == WSAP_VTCORE_COLOR_FG); /* A renderer sees the cursor move to another row. */ - struct term_snapshot *snap = term_snapshot_new(); + struct wsap_vtcore_snapshot *snap = wsap_vtcore_snapshot_new(); uint64_t version = view_version(snap, t); write_seq(t, "\033[3d"); assert(tt_cursor_y(t) == 2 && view_version(snap, t) != version); - term_snapshot_free(snap); + wsap_vtcore_snapshot_free(snap); write_seq(t, "\033[4;8H\0337"); tt_resize(t, 5, 2); write_seq(t, "\0338Z"); assert(tt_cursor_y(t) == 1 && tt_cursor_x(t) == 3); assert(tt_cell(t, 2, 1)->text == 'Z'); - term_free(t); + wsap_vtcore_free(t); } static void test_unterminated_control_strings_do_not_swallow_text(void) { - struct term *t = tt_new(20, 4); + struct wsap_vtcore *t = tt_new(20, 4); assert(t); write_seq(t, "A\033]0;random bytes\tgit\r\nstatus"); @@ -417,7 +417,7 @@ static void test_unterminated_control_strings_do_not_swallow_text(void) assert(row_is(t, 1, "status branch")); assert(row_is(t, 2, "next")); - term_free(t); + wsap_vtcore_free(t); char overlong[1200]; for (int intro = 0; intro < 2; intro++) { @@ -425,35 +425,35 @@ static void test_unterminated_control_strings_do_not_swallow_text(void) memset(overlong + n, 'T', 1024); overlong[n + 1024] = '\0'; - struct term *u = tt_new(20, 4); + struct wsap_vtcore *u = tt_new(20, 4); write_seq(u, overlong); write_seq(u, "\r\n[sudo] password:"); assert(row_is(u, 0, "")); assert(row_is(u, 1, "[sudo] password:")); - term_free(u); + wsap_vtcore_free(u); - struct term *d = tt_new(20, 4); + struct wsap_vtcore *d = tt_new(20, 4); write_seq(d, overlong); write_seq(d, "\033\\after"); assert(row_is(d, 0, "after")); - term_free(d); + wsap_vtcore_free(d); } } static void test_c0_controls_after_esc_are_executed(void) { - struct term *t = tt_new(20, 4); + struct wsap_vtcore *t = tt_new(20, 4); assert(t); write_seq(t, "A\033\tB"); assert(row_is(t, 0, "A B")); - term_free(t); + wsap_vtcore_free(t); } static void test_resize_reflow(void) { - struct term *t = tt_new(8, 4); + struct wsap_vtcore *t = tt_new(8, 4); write_seq(t, "abcdefghijkl"); tt_resize(t, 16, 4); assert(row_is(t, 0, "abcdefghijkl") && row_is(t, 1, "")); @@ -469,16 +469,16 @@ static void test_resize_reflow(void) free(text); tt_resize(t, 20, 4); assert(row_is(t, 0, "abcdefghijklM")); - term_free(t); + wsap_vtcore_free(t); t = tt_new(6, 6); write_seq(t, "\033[31mab cdef\033[m\r\nnext"); - term_color red = tt_cell(t, 0, 0)->fg; + wsap_vtcore_color red = tt_cell(t, 0, 0)->fg; tt_resize(t, 12, 6); assert(row_is(t, 0, "ab cdef") && row_is(t, 1, "next")); assert(tt_cell(t, 7, 0)->fg == red); - assert(tt_cell(t, 0, 1)->fg == TERM_COLOR_FG); - term_free(t); + assert(tt_cell(t, 0, 1)->fg == WSAP_VTCORE_COLOR_FG); + wsap_vtcore_free(t); t = tt_new(4, 2); write_seq(t, "abcdefghijkl"); @@ -493,7 +493,7 @@ static void test_resize_reflow(void) assert(row_is(t, 0, "ijkl") && row_is(t, 1, "M")); tt_resize(t, 20, 2); assert(row_is(t, 0, "abcdefghijklM")); - term_free(t); + wsap_vtcore_free(t); t = tt_new(4, 3); write_seq(t, "abcd"); @@ -503,7 +503,7 @@ static void test_resize_reflow(void) tt_resize(t, 5, 3); write_seq(t, "F"); assert(row_is(t, 0, "abcdE") && row_is(t, 1, "F")); - term_free(t); + wsap_vtcore_free(t); t = tt_new(4, 4); write_seq(t, "abcdefghijkl\033[?1049h12345678"); @@ -513,14 +513,14 @@ static void test_resize_reflow(void) write_seq(t, "\033[?1049lM"); assert(row_is(t, 0, "abcdefghijklM")); assert(tt_cursor_y(t) == 0 && tt_cursor_x(t) == 13); - term_free(t); + wsap_vtcore_free(t); t = tt_new(4, 2); write_seq(t, "abcd"); tt_resize(t, 4, 3); write_seq(t, "E"); assert(row_is(t, 0, "abcd") && row_is(t, 1, "E")); - term_free(t); + wsap_vtcore_free(t); t = tt_new(80, 4); for (int i = 0; i < 1000; i++) write_seq(t, "abcdefgh"); @@ -532,22 +532,22 @@ static void test_resize_reflow(void) assert(tt_cursor_x(t) < 80 && tt_cursor_y(t) < 4); write_seq(t, "Z"); assert(tt_cell(t, 0, 3)->text == 'Z'); - term_free(t); + wsap_vtcore_free(t); } static void test_resize_exposes_blank_rows(void) { - struct term *t = tt_new(20, 2); + struct wsap_vtcore *t = tt_new(20, 2); write_seq(t, "kept"); for (int pass = 0; pass < 2; pass++) { tt_resize(t, 20, 6); assert(row_is(t, 0, "kept")); for (int y = 2; y < 6; y++) { for (int x = 0; x < 20; x++) { - const struct term_cell *cell = tt_cell(t, x, y); - assert(cell->text == ' ' && cell->fg == TERM_COLOR_FG); - assert(cell->bg == TERM_COLOR_BG && cell->attrs == 0 && cell->width == 1); + const struct wsap_vtcore_cell *cell = tt_cell(t, x, y); + assert(cell->text == ' ' && cell->fg == WSAP_VTCORE_COLOR_FG); + assert(cell->bg == WSAP_VTCORE_COLOR_BG && cell->attrs == 0 && cell->width == 1); } } write_seq(t, "\033[6;1H\tfile/"); @@ -555,12 +555,12 @@ static void test_resize_exposes_blank_rows(void) write_seq(t, "\033[1;1H"); tt_resize(t, 20, 2); } - term_free(t); + wsap_vtcore_free(t); } static void test_prompt_resize(void) { - struct term *t = tt_new(80, 6); + struct wsap_vtcore *t = tt_new(80, 6); const char *prompt = "~/Documents/GitHub/clernen_pi main> "; write_seq(t, "\033]133;A;click_events=1\033\\"); write_seq(t, prompt); @@ -596,7 +596,7 @@ static void test_prompt_resize(void) tt_resize(t, 20, 6); assert(row_is(t, 0, "~/Documents/GitHub/c")); assert(row_is(t, 1, "lernen_pi main>")); - term_free(t); + wsap_vtcore_free(t); t = tt_new(20, 6); write_seq(t, "abcdefghijklmnop\r\n\033]133;A\007prompt> input\033]133;B\007"); @@ -605,12 +605,12 @@ static void test_prompt_resize(void) assert(row_is(t, 2, "prompt>")); tt_resize(t, 30, 6); assert(row_is(t, 0, "abcdefghijklmnop") && row_is(t, 1, "prompt>")); - term_free(t); + wsap_vtcore_free(t); } static void test_cursor_line_motion(void) { - struct term *t = tt_new(80, 9); + struct wsap_vtcore *t = tt_new(80, 9); assert(t); const char *lines = "one\r\ntwo\r\nthree\r\nfour\r\nfive\r\nsix\r\nseven\r\n"; tt_write(t, lines, strlen(lines)); @@ -619,12 +619,12 @@ static void test_cursor_line_motion(void) assert(row_is(t, 1, "two revised")); assert(row_is(t, 3, "four revised")); assert(row_is(t, 0, "one revised")); - term_free(t); + wsap_vtcore_free(t); } static void test_relative_cursor_motion(void) { - struct term *t = tt_new(10, 5); + struct wsap_vtcore *t = tt_new(10, 5); assert(t); const char *text = "0123456789\r\nabcdefghij\r\nklmnopqrst"; tt_write(t, text, strlen(text)); @@ -634,7 +634,7 @@ static void test_relative_cursor_motion(void) assert(tt_cell(t, 5, 2)->text == 'Y'); assert(tt_cell(t, 6, 3)->text == 'Z'); assert(tt_cell(t, 7, 1)->text == 'W'); - term_free(t); + wsap_vtcore_free(t); } static void test_top_region_scrollback(void) @@ -651,7 +651,7 @@ static void test_top_region_scrollback(void) {"\033[99S", 4}, }; for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { - struct term *t = tt_new(12, 6); + struct wsap_vtcore *t = tt_new(12, 6); write_seq(t, "one\r\ntwo\r\nthree\r\nfour\r\nPROMPT\r\nSTATUS"); write_seq(t, "\033[1;4r\033[4;1H"); write_seq(t, cases[i].scroll); @@ -660,15 +660,15 @@ static void test_top_region_scrollback(void) cases[i].lines == 2 ? "three" : "")); assert(row_is(t, 3, "")); assert(row_is(t, 4, "PROMPT") && row_is(t, 5, "STATUS")); - term_scroll(t, cases[i].lines); + wsap_vtcore_scroll(t, cases[i].lines); assert(tt_view_offset(t) == cases[i].lines); assert(row_is(t, 0, "one") && row_is(t, 1, "two")); - term_free(t); + wsap_vtcore_free(t); } /* Retain the same history as a full screen after the ring wraps. */ - struct term *t = tt_new(12, 6); - struct term *reference = tt_new(12, 4); + struct wsap_vtcore *t = tt_new(12, 6); + struct wsap_vtcore *reference = tt_new(12, 4); const char *footer = "\033[5;1H\033[31mPROMPT\r\nSTATUS\033[m\033[1;4r"; tt_write(t, footer, strlen(footer)); for (int i = 0; i < 2 * TEST_SCROLLBACK; i++) { @@ -682,19 +682,19 @@ static void test_top_region_scrollback(void) assert(tt_cursor_y(t) == tt_cursor_y(reference)); assert(row_is(t, 4, "PROMPT") && row_is(t, 5, "STATUS")); assert(tt_cell(t, 0, 4)->fg == tt_cell(t, 0, 5)->fg); - assert(tt_cell(t, 0, 4)->fg != TERM_COLOR_FG); + assert(tt_cell(t, 0, 4)->fg != WSAP_VTCORE_COLOR_FG); for (int i = 0; i <= tt_history(reference); i++) { assert_same_rows(t, reference, tt_rows(reference)); - term_scroll(t, 1); - term_scroll(reference, 1); + wsap_vtcore_scroll(t, 1); + wsap_vtcore_scroll(reference, 1); } - term_free(t); - term_free(reference); + wsap_vtcore_free(t); + wsap_vtcore_free(reference); } static void test_editor_scrolling(void) { - struct term *t = tt_new(80, 24); + struct wsap_vtcore *t = tt_new(80, 24); write_seq(t, "\033[?1049hTITLE"); for (int i = 1; i <= 20; i++) { char line[64]; @@ -711,7 +711,7 @@ static void test_editor_scrolling(void) assert(row_is(t, 22, "HELP") && row_is(t, 23, "FOOTER")); assert(tt_cursor_x(t) == 0 && tt_cursor_y(t) == 3); assert(tt_history(t) == 0); - term_free(t); + wsap_vtcore_free(t); t = tt_new(12, 6); write_seq(t, "old\r\nHEAD\r\nA\r\nB\r\nC\r\nD\r\nFOOT"); @@ -736,7 +736,7 @@ static void test_editor_scrolling(void) for (int r = 1; r <= 4; r++) { assert(row_is(t, r, "")); assert(tt_cell(t, 0, r)->bg == tt_cell(t, 11, r)->bg); - assert(tt_cell(t, 0, r)->bg != TERM_COLOR_BG); + assert(tt_cell(t, 0, r)->bg != WSAP_VTCORE_COLOR_BG); } assert(tt_history(t) == 1); @@ -746,117 +746,117 @@ static void test_editor_scrolling(void) tt_resize(t, 12, 4); write_seq(t, "\033[4;1H\033[2Kend\n"); assert(tt_cursor_y(t) == 3 && row_is(t, 2, "end")); - term_free(t); + wsap_vtcore_free(t); } static bool pending_decsca_decsed_decsel(void) { - struct term *d = tt_new(20, 3); + struct wsap_vtcore *d = tt_new(20, 3); write_seq(d, "\033[H" "AB" "\033[1\"q" "CD" "\033[0\"q" "EF"); write_seq(d, "\033[?2J"); bool ok = row_eq(d, 0, " CD"); - term_free(d); + wsap_vtcore_free(d); - struct term *l = tt_new(20, 3); + struct wsap_vtcore *l = tt_new(20, 3); write_seq(l, "\033[H" "GH" "\033[1\"q" "IJ" "\033[0\"q" "KL"); write_seq(l, "\033[H\033[?0K"); ok = ok && row_eq(l, 0, " IJ"); - term_free(l); + wsap_vtcore_free(l); return ok; } static bool pending_decfra_decera(void) { - struct term *f = tt_new(20, 3); + struct wsap_vtcore *f = tt_new(20, 3); write_seq(f, "\033[88;1;2;2;4$x"); bool ok = row_eq(f, 0, " XXX") && row_eq(f, 1, " XXX"); - term_free(f); + wsap_vtcore_free(f); - struct term *e = tt_new(20, 3); + struct wsap_vtcore *e = tt_new(20, 3); write_seq(e, "\033[Habcde\r\nfghij"); write_seq(e, "\033[1;2;2;3$z"); ok = ok && row_eq(e, 0, "a de") && row_eq(e, 1, "f ij"); - term_free(e); + wsap_vtcore_free(e); return ok; } static bool pending_deccra(void) { - struct term *t = tt_new(20, 3); + struct wsap_vtcore *t = tt_new(20, 3); write_seq(t, "\033[HAB\r\nCD"); write_seq(t, "\033[1;1;2;2;1;1;5;1$v"); bool ok = row_eq(t, 0, "AB AB") && row_eq(t, 1, "CD CD"); - term_free(t); + wsap_vtcore_free(t); return ok; } static bool pending_decrara(void) { - struct term *t = tt_new(20, 3); + struct wsap_vtcore *t = tt_new(20, 3); write_seq(t, "\033[H\033[1mAB\033[mCD"); write_seq(t, "\033[1;1;1;4;1$t"); - bool ok = !(tt_cell(t, 0, 0)->attrs & TERM_ATTR_BOLD) && - (tt_cell(t, 2, 0)->attrs & TERM_ATTR_BOLD); - term_free(t); + bool ok = !(tt_cell(t, 0, 0)->attrs & WSAP_VTCORE_ATTR_BOLD) && + (tt_cell(t, 2, 0)->attrs & WSAP_VTCORE_ATTR_BOLD); + wsap_vtcore_free(t); return ok; } static bool pending_decsera(void) { - struct term *t = tt_new(20, 3); + struct wsap_vtcore *t = tt_new(20, 3); write_seq(t, "\033[H\033[0\"qAB\033[1\"qCD"); write_seq(t, "\033[1;1;1;4${"); bool ok = row_eq(t, 0, " CD"); - term_free(t); + wsap_vtcore_free(t); return ok; } static bool pending_deccolm(void) { - struct term *t = tt_new(80, 4); + struct wsap_vtcore *t = tt_new(80, 4); write_seq(t, "\033[?40h" "keep" "\033[?3h"); bool ok = tt_cols(t) == 132 && row_eq(t, 0, "") && tt_cursor_x(t) == 0 && tt_cursor_y(t) == 0; write_seq(t, "\033[?3l"); ok = ok && tt_cols(t) == 80; - term_free(t); + wsap_vtcore_free(t); return ok; } static bool pending_decic_decdc(void) { - struct term *i = tt_new(10, 2); + struct wsap_vtcore *i = tt_new(10, 2); write_seq(i, "\033[Habcdef\033[H\033[2'}"); bool ok = row_eq(i, 0, " abcdef"); - term_free(i); + wsap_vtcore_free(i); - struct term *d = tt_new(10, 2); + struct wsap_vtcore *d = tt_new(10, 2); write_seq(d, "\033[Habcdef\033[H\033[2'~"); ok = ok && row_eq(d, 0, "cdef"); - term_free(d); + wsap_vtcore_free(d); return ok; } static bool pending_sl_sr(void) { - struct term *l = tt_new(10, 2); + struct wsap_vtcore *l = tt_new(10, 2); write_seq(l, "\033[Habcdef\033[2 @"); bool ok = row_eq(l, 0, "cdef"); - term_free(l); + wsap_vtcore_free(l); - struct term *r = tt_new(10, 2); + struct wsap_vtcore *r = tt_new(10, 2); write_seq(r, "\033[Habcdef\033[2 A"); ok = ok && row_eq(r, 0, " abcdef"); - term_free(r); + wsap_vtcore_free(r); return ok; } static bool pending_sixel(void) { - struct term *t = tt_new(20, 6); + struct wsap_vtcore *t = tt_new(20, 6); write_seq(t, "\033[H\033Pq#0;2;100;100;100#0~~~~\033\\"); bool ok = tt_cursor_y(t) > 0; - term_free(t); + wsap_vtcore_free(t); return ok; } @@ -888,7 +888,7 @@ static void test_unimplemented_da_features(void) static void test_device_attributes(void) { - struct term *t = tt_new_opts(80, 24, &reply_cb); + struct wsap_vtcore *t = tt_new_opts(80, 24, &reply_cb); write_seq(t, "\033[c"); assert(!strcmp(response, "\033[?62;22c")); @@ -903,10 +903,10 @@ static void test_device_attributes(void) write_seq(t, "\033[=c"); assert(response_len == 0); - term_free(t); + wsap_vtcore_free(t); } -static void expect_flags(struct term *t, const char *commands, const char *reply) +static void expect_flags(struct wsap_vtcore *t, const char *commands, const char *reply) { write_seq(t, commands); write_seq(t, "\033[?u"); @@ -914,12 +914,12 @@ static void expect_flags(struct term *t, const char *commands, const char *reply } static void test_keyboard_negotiation(void) { - struct term *t = tt_new_opts(80, 24, &reply_cb); - assert(!term_modes(t).app_cursor); + struct wsap_vtcore *t = tt_new_opts(80, 24, &reply_cb); + assert(!wsap_vtcore_modes(t).app_cursor); write_seq(t, "\033[?1h"); - assert(term_modes(t).app_cursor); + assert(wsap_vtcore_modes(t).app_cursor); write_seq(t, "\033[?1l"); - assert(!term_modes(t).app_cursor); + assert(!wsap_vtcore_modes(t).app_cursor); expect_flags(t, "", "\033[?0u"); expect_flags(t, "\033[=1u", "\033[?1u"); expect_flags(t, "\033[>3u\033[>31u", "\033[?31u"); @@ -943,10 +943,10 @@ static void test_keyboard_negotiation(void) expect_flags(t, "\033[<2147483647u", "\033[?0u"); write_seq(t, "hello"); assert(row_is(t, 0, "hello")); - term_free(t); + wsap_vtcore_free(t); } -static void expect_selection(struct term *t, int x1, int y1, int x2, int y2, const char *want) +static void expect_selection(struct wsap_vtcore *t, int x1, int y1, int x2, int y2, const char *want) { tt_select(t, x1, y1, x2, y2); char *text = tt_selection_text(t); @@ -958,7 +958,7 @@ static void expect_selection(struct term *t, int x1, int y1, int x2, int y2, con static void test_wide_characters(void) { - struct term *t = tt_new(8, 4); + struct wsap_vtcore *t = tt_new(8, 4); write_seq(t, "A😀界B"); assert(tt_cursor_x(t) == 6); assert(tt_cell(t, 1, 0)->text == 0x1f600 && tt_cell(t, 3, 0)->text == 0x754c); @@ -974,7 +974,7 @@ static void test_wide_characters(void) write_seq(t, "\033[4;1H😀\r \033[4;1H😀\033[4;2H\033[38;2;1;2;3mX"); assert(row_is(t, 3, " X")); - term_free(t); + wsap_vtcore_free(t); t = tt_new(5, 8); write_seq(t, "abcd😀Z"); @@ -991,7 +991,7 @@ static void test_wide_characters(void) tt_resize(t, 12, 8); expect_selection(t, 0, 0, 11, 0, "abcd😀Z"); assert(tt_cursor_x(t) == 7); - term_free(t); + wsap_vtcore_free(t); t = tt_new(4, 3); write_seq(t, "abc©️)"); @@ -1002,16 +1002,16 @@ static void test_wide_characters(void) expect_selection(t, 0, 0, 3, 0, "😀︎x"); write_seq(t, "\033[2J\033[H\033[?7labc😀"); assert(tt_cursor_y(t) == 0 && tt_cursor_x(t) == 3); - term_free(t); + wsap_vtcore_free(t); t = tt_new(4, 2); write_seq(t, "😀😀界界AB"); - term_scroll(t, 1); + wsap_vtcore_scroll(t, 1); expect_selection(t, 0, 0, 3, 1, "😀😀界界"); - term_scroll_to(t, 0); + wsap_vtcore_scroll_to(t, 0); tt_resize(t, 10, 2); expect_selection(t, 0, 0, 9, 0, "😀😀界界AB"); - term_free(t); + wsap_vtcore_free(t); } static void test_wide_runs(void) @@ -1029,15 +1029,15 @@ static void test_wide_runs(void) for (size_t k = 0; k < sizeof(runs) / sizeof(*runs); k++) { char text[512]; snprintf(text, sizeof(text), "\033[999;1H%s", runs[k]); - struct term *bulk = tt_new(120, 6); - struct term *split = tt_new(120, 6); + struct wsap_vtcore *bulk = tt_new(120, 6); + struct wsap_vtcore *split = tt_new(120, 6); tt_write(bulk, text, strlen(text)); write_seq(split, text); assert_same_screen(bulk, split); expect_selection(bulk, 0, 5, 119, 5, runs[k]); - term_free(bulk); - term_free(split); + wsap_vtcore_free(bulk); + wsap_vtcore_free(split); } } @@ -1055,8 +1055,8 @@ static void test_invalid_utf8_runs(void) } memcpy(input + n, "END", 3); n += 3; - struct term *bulk = tt_new(120, 4); - struct term *split = tt_new(120, 4); + struct wsap_vtcore *bulk = tt_new(120, 4); + struct wsap_vtcore *split = tt_new(120, 4); write_seq(bulk, "\033[4;1H\n"); write_seq(split, "\033[4;1H\n"); tt_write(bulk, input, n); @@ -1067,15 +1067,15 @@ static void test_invalid_utf8_runs(void) for (int c = 0; c < 3; c++) assert(tt_cell_cp(bulk, tt_cell(bulk, 96 + c, 3)) == (uint32_t)"END"[c]); assert_same_screen(bulk, split); - term_free(bulk); - term_free(split); + wsap_vtcore_free(bulk); + wsap_vtcore_free(split); } } static void test_recycled_scrollback_blanks(void) { for (int mode = 0; mode < 3; mode++) { - struct term *t = tt_new(32, 3); + struct wsap_vtcore *t = tt_new(32, 3); write_seq(t, "\033[3;1H"); const char *line = mode == 2 ? "abcdefghijklmnopqrstuvwxyz\r\033[S" : "abcdefghijklmnopqrstuvwxyz\r\n"; @@ -1085,7 +1085,7 @@ static void test_recycled_scrollback_blanks(void) } write_seq(t, "\tfile/"); assert(row_is(t, 2, " file/")); - term_free(t); + wsap_vtcore_free(t); } } @@ -1093,26 +1093,26 @@ static void test_recycled_scrollback_blanks(void) * scroll that cannot move leaves the frame alone. */ static void test_scroll_view_clamps_extreme_deltas(void) { - struct term *t = tt_new(20, 3); + struct wsap_vtcore *t = tt_new(20, 3); for (int i = 0; i < 10; i++) write_seq(t, "line\r\n"); int max = tt_history(t); assert(max > 1); - struct term_snapshot *snap = term_snapshot_new(); - term_scroll(t, 1); - term_scroll(t, INT_MAX); + struct wsap_vtcore_snapshot *snap = wsap_vtcore_snapshot_new(); + wsap_vtcore_scroll(t, 1); + wsap_vtcore_scroll(t, INT_MAX); assert(tt_view_offset(t) == max); uint64_t version = view_version(snap, t); - term_scroll(t, 1); + wsap_vtcore_scroll(t, 1); assert(view_version(snap, t) == version); - term_scroll(t, -1); - term_scroll(t, INT_MIN); + wsap_vtcore_scroll(t, -1); + wsap_vtcore_scroll(t, INT_MIN); assert(tt_view_offset(t) == 0); version = view_version(snap, t); - term_scroll(t, -1); + wsap_vtcore_scroll(t, -1); assert(view_version(snap, t) == version); - term_snapshot_free(snap); - term_free(t); + wsap_vtcore_snapshot_free(snap); + wsap_vtcore_free(t); } static void test_batched_recycled_lines(void) @@ -1125,8 +1125,8 @@ static void test_batched_recycled_lines(void) "short\r\nx\r\nyz\r\npartial\r", }; for (size_t k = 0; k < sizeof(endings) / sizeof(endings[0]); k++) { - struct term *bulk = tt_new(32, 3); - struct term *bytes = tt_new(32, 3); + struct wsap_vtcore *bulk = tt_new(32, 3); + struct wsap_vtcore *bytes = tt_new(32, 3); const char *old = "\033[31;44mabcdefghijklmnopqrst界界界\r\n"; for (int i = 0; i < TEST_SCROLLBACK + 10; i++) { tt_write(bulk, old, strlen(old)); @@ -1139,12 +1139,12 @@ static void test_batched_recycled_lines(void) assert_same_screen(bulk, bytes); for (int i = 0; i < tt_history(bulk); i += 3) { - term_scroll(bulk, 3); - term_scroll(bytes, 3); + wsap_vtcore_scroll(bulk, 3); + wsap_vtcore_scroll(bytes, 3); assert_same_screen(bulk, bytes); } - term_free(bulk); - term_free(bytes); + wsap_vtcore_free(bulk); + wsap_vtcore_free(bytes); } } @@ -1158,20 +1158,20 @@ static void test_full_width_line_endings(void) "aa\r\nbb\r\ncc\r\nd中d\r\nef", }; for (size_t k = 0; k < sizeof(feeds) / sizeof(feeds[0]); k++) { - struct term *bulk = tt_new(4, 3); - struct term *bytes = tt_new(4, 3); + struct wsap_vtcore *bulk = tt_new(4, 3); + struct wsap_vtcore *bytes = tt_new(4, 3); tt_write(bulk, feeds[k], strlen(feeds[k])); write_seq(bytes, feeds[k]); assert_same_screen(bulk, bytes); - term_free(bulk); - term_free(bytes); + wsap_vtcore_free(bulk); + wsap_vtcore_free(bytes); } - struct term *t = tt_new(4, 3); + struct wsap_vtcore *t = tt_new(4, 3); tt_write(t, feeds[0], strlen(feeds[0])); assert(tt_history(t) == 3); assert(row_is(t, 0, "dddd") && row_is(t, 1, "eeee") && row_is(t, 2, "ffff")); - term_free(t); + wsap_vtcore_free(t); } /* CRLFs at every mask boundary, followed by complete or interrupted lines. */ @@ -1189,18 +1189,18 @@ static void test_batched_line_masks(void) memcpy(input + offset, tails[k], strlen(tails[k])); memset(input + n, 'z', 128); n += 128; - struct term *bulk = tt_new(80, 3), *bytes = tt_new(80, 3); + struct wsap_vtcore *bulk = tt_new(80, 3), *bytes = tt_new(80, 3); /* A nondefault pen exercises the queued bulk path, not streaming. */ write_both(bulk, bytes, "\033[3;1H\033[31m"); tt_write(bulk, input, n); for (size_t i = 0; i < n; i++) tt_write(bytes, input + i, 1); write_both(bulk, bytes, "\033[b"); assert_same_screen(bulk, bytes); - term_scroll_to(bulk, INT_MAX); - term_scroll_to(bytes, INT_MAX); + wsap_vtcore_scroll_to(bulk, INT_MAX); + wsap_vtcore_scroll_to(bytes, INT_MAX); assert_same_screen(bulk, bytes); - term_free(bulk); - term_free(bytes); + wsap_vtcore_free(bulk); + wsap_vtcore_free(bytes); } } } @@ -1217,7 +1217,7 @@ static void test_batched_line_masks(void) */ static void test_bulk_line_flood(void) { - static const struct term_vector2i geoms[] = { + static const struct wsap_vtcore_vector2i geoms[] = { {.x = 80, .y = 24}, {.x = 27, .y = 8}, {.x = 10, .y = 5}, {.x = 120, .y = 80}, }; for (size_t g = 0; g < 2 * sizeof(geoms) / sizeof(geoms[0]); g++) { @@ -1246,28 +1246,28 @@ static void test_bulk_line_flood(void) buf[n++] = pick == 26 ? '\n' : (char)('a' + pick); } - struct term *bulk = tt_new(cols, rows); - struct term *stream = tt_new(cols, rows); - struct term *bytes = tt_new(cols, rows); - unsigned flags = g % 2 != 0 ? TERM_FEED_ONLCR : 0; + struct wsap_vtcore *bulk = tt_new(cols, rows); + struct wsap_vtcore *stream = tt_new(cols, rows); + struct wsap_vtcore *bytes = tt_new(cols, rows); + unsigned flags = g % 2 != 0 ? WSAP_VTCORE_FEED_ONLCR : 0; for (size_t i = 0; i < n; i += 65536) - term_feed(bulk, buf + i, n - i < 65536 ? n - i : 65536, flags); + wsap_vtcore_feed(bulk, buf + i, n - i < 65536 ? n - i : 65536, flags); /* One large write has enough newlines to discard old output. */ - term_feed(stream, buf, n, flags); - for (size_t i = 0; i < n; i++) term_feed(bytes, buf + i, 1, flags); + wsap_vtcore_feed(stream, buf, n, flags); + for (size_t i = 0; i < n; i++) wsap_vtcore_feed(bytes, buf + i, 1, flags); assert_same_screen(bulk, bytes); assert_same_screen(stream, bytes); for (int i = 0; i < tt_history(bulk); i += 7) { - term_scroll(bulk, 7); - term_scroll(stream, 7); - term_scroll(bytes, 7); + wsap_vtcore_scroll(bulk, 7); + wsap_vtcore_scroll(stream, 7); + wsap_vtcore_scroll(bytes, 7); assert_same_screen(bulk, bytes); assert_same_screen(stream, bytes); } - term_free(bulk); - term_free(stream); - term_free(bytes); + wsap_vtcore_free(bulk); + wsap_vtcore_free(stream); + wsap_vtcore_free(bytes); free(buf); } } @@ -1289,29 +1289,29 @@ static void test_ascii_flood_edits(void) "\033[?1049hALT\033[?1049l\033[6;1Htail\n"; for (size_t w = 0; w < sizeof(widths) / sizeof(widths[0]); w++) { for (size_t chunk = 4096; chunk <= sizeof(input); chunk *= 16) { - struct term *bulk = tt_new(widths[w], 6); - struct term *bytes = tt_new(widths[w], 6); + struct wsap_vtcore *bulk = tt_new(widths[w], 6); + struct wsap_vtcore *bytes = tt_new(widths[w], 6); for (size_t i = 0; i < sizeof(input); i += chunk) - term_feed(bulk, input + i, chunk, TERM_FEED_ONLCR); + wsap_vtcore_feed(bulk, input + i, chunk, WSAP_VTCORE_FEED_ONLCR); for (size_t i = 0; i < sizeof(input); i++) - term_feed(bytes, input + i, 1, TERM_FEED_ONLCR); + wsap_vtcore_feed(bytes, input + i, 1, WSAP_VTCORE_FEED_ONLCR); assert_same_screen(bulk, bytes); - term_feed(bulk, edit, sizeof(edit) - 1, TERM_FEED_ONLCR); + wsap_vtcore_feed(bulk, edit, sizeof(edit) - 1, WSAP_VTCORE_FEED_ONLCR); for (size_t i = 0; i < sizeof(edit) - 1; i++) - term_feed(bytes, edit + i, 1, TERM_FEED_ONLCR); + wsap_vtcore_feed(bytes, edit + i, 1, WSAP_VTCORE_FEED_ONLCR); assert_same_screen(bulk, bytes); for (int i = 0; i < tt_history(bulk); i += 6) { - term_scroll(bulk, 6); - term_scroll(bytes, 6); + wsap_vtcore_scroll(bulk, 6); + wsap_vtcore_scroll(bytes, 6); assert_same_screen(bulk, bytes); } - term_scroll_to(bulk, 0); - term_scroll_to(bytes, 0); + wsap_vtcore_scroll_to(bulk, 0); + wsap_vtcore_scroll_to(bytes, 0); assert(tt_resize(bulk, widths[w] + 3, 7)); assert(tt_resize(bytes, widths[w] + 3, 7)); assert_same_screen(bulk, bytes); - term_free(bulk); - term_free(bytes); + wsap_vtcore_free(bulk); + wsap_vtcore_free(bytes); } } } @@ -1327,8 +1327,8 @@ static void test_margin_linefeed_bursts(void) }; for (size_t k = 0; k < sizeof(bursts) / sizeof(bursts[0]); k++) { for (int mode = 0; mode < 3; mode++) { - struct term *bulk = tt_new(8, 8); - struct term *bytes = tt_new(8, 8); + struct wsap_vtcore *bulk = tt_new(8, 8); + struct wsap_vtcore *bytes = tt_new(8, 8); const char *setup = "\033[1;1Htop\033[2;1Ha\033[3;1Hb\033[4;1Hc" "\033[5;1Hd\033[6;1He\033[7;1Hf\033[8;1Hfoot" "\033[2;7r\033[7;3H"; @@ -1338,22 +1338,22 @@ static void test_margin_linefeed_bursts(void) write_seq(bulk, "\033[20h"); write_seq(bytes, "\033[20h"); } - unsigned flags = mode == 2 ? TERM_FEED_ONLCR : 0; - term_feed(bulk, bursts[k], strlen(bursts[k]), flags); + unsigned flags = mode == 2 ? WSAP_VTCORE_FEED_ONLCR : 0; + wsap_vtcore_feed(bulk, bursts[k], strlen(bursts[k]), flags); feed_seq(bytes, bursts[k], flags); assert_same_screen(bulk, bytes); assert(row_is(bulk, 0, "top")); assert(row_is(bulk, 7, "foot")); - term_free(bulk); - term_free(bytes); + wsap_vtcore_free(bulk); + wsap_vtcore_free(bytes); } } } static void test_alt_linefeed_burst_after_resize(void) { - struct term *bulk = tt_new(8, 5); - struct term *bytes = tt_new(8, 5); + struct wsap_vtcore *bulk = tt_new(8, 5); + struct wsap_vtcore *bytes = tt_new(8, 5); const char *setup = "\033[?1049h\033[5;1H\n\n\n\n"; tt_write(bulk, setup, strlen(setup)); write_seq(bytes, setup); @@ -1366,8 +1366,8 @@ static void test_alt_linefeed_burst_after_resize(void) tt_resize(bulk, 12, 4); tt_resize(bytes, 12, 4); assert_same_screen(bulk, bytes); - term_free(bulk); - term_free(bytes); + wsap_vtcore_free(bulk); + wsap_vtcore_free(bytes); } /* @@ -1380,24 +1380,24 @@ static void test_alt_resize_keeps_row_order(void) const char *setup = "\033[?1049h\033[5;1H\n\n\n" "\033[1;1HA\033[2;1HB\033[3;1HC\033[4;1HD\033[5;1HE"; - struct term *grow = tt_new(20, 5); + struct wsap_vtcore *grow = tt_new(20, 5); write_seq(grow, setup); tt_resize(grow, 20, 8); assert(row_is(grow, 0, "A") && row_is(grow, 4, "E")); assert(row_is(grow, 5, "") && row_is(grow, 7, "")); - term_free(grow); + wsap_vtcore_free(grow); /* The cursor is on the last row, so shrinking scrolls A and B off. */ - struct term *shrink = tt_new(20, 5); + struct wsap_vtcore *shrink = tt_new(20, 5); write_seq(shrink, setup); tt_resize(shrink, 20, 3); assert(row_is(shrink, 0, "C") && row_is(shrink, 2, "E")); - term_free(shrink); + wsap_vtcore_free(shrink); } static void test_alt_shrink_then_flood(void) { - struct term *t = tt_new(80, 40); + struct wsap_vtcore *t = tt_new(80, 40); tt_write(t, "\033[?1049h\033[40;1H", 16); for (int i = 0; i < 35; i++) tt_write(t, "x\n", 2); @@ -1409,36 +1409,36 @@ static void test_alt_shrink_then_flood(void) tt_write(t, line, (size_t)len); } assert(row_is(t, 8, "line 5999") && row_is(t, 0, "line 5991")); - term_free(t); + wsap_vtcore_free(t); } /* Regression: ED 3 on the alternate screen kept the history count, so the * normal screen came back with blank history rows. */ static void test_alt_erase_scrollback(void) { - struct term *t = tt_new(20, 5); + struct wsap_vtcore *t = tt_new(20, 5); for (int i = 0; i < 30; i++) tt_write(t, "line\r\n", 6); assert(tt_history(t) > 0); write_seq(t, "\033[?1049h\033[3J\033[?1049l"); assert(tt_history(t) == 0); - term_free(t); + wsap_vtcore_free(t); } /* Regression: a snapshot knew its terminal by address. A new terminal that * reused a freed one's memory then showed the old terminal's rows. */ static void test_snapshot_follows_new_terminal(void) { - struct term_snapshot *s = term_snapshot_new(); + struct wsap_vtcore_snapshot *s = wsap_vtcore_snapshot_new(); for (int i = 0; i < 8; i++) { - struct term *t = tt_new(10, 2); + struct wsap_vtcore *t = tt_new(10, 2); char text[2] = { (char)('a' + i), 0 }; tt_puts(t, text); - assert(term_snapshot_update(s, t)); - assert(term_snapshot_row(s, 0)[0].text == (uint32_t)text[0]); - term_free(t); + assert(wsap_vtcore_snapshot_update(s, t)); + assert(wsap_vtcore_snapshot_row(s, 0)[0].text == (uint32_t)text[0]); + wsap_vtcore_free(t); } - term_snapshot_free(s); + wsap_vtcore_snapshot_free(s); } /* The getters take a NULL snapshot and an out-of-range row like a NULL @@ -1446,48 +1446,48 @@ static void test_snapshot_follows_new_terminal(void) static void test_snapshot_null_and_range(void) { uint32_t cps[4] = { 0xAAAA, 0xAAAA, 0xAAAA, 0xAAAA }; - assert(term_snapshot_view(NULL) == NULL); - assert(term_snapshot_row(NULL, 0) == NULL); - assert(term_snapshot_row_key(NULL, 0) == 0); - struct term_span none = term_snapshot_row_selection(NULL, 0); + assert(wsap_vtcore_snapshot_view(NULL) == NULL); + assert(wsap_vtcore_snapshot_row(NULL, 0) == NULL); + assert(wsap_vtcore_snapshot_row_key(NULL, 0) == 0); + struct wsap_vtcore_span none = wsap_vtcore_snapshot_row_selection(NULL, 0); assert(none.begin == 0 && none.end == 0); - assert(term_snapshot_cluster(NULL, 'a', cps, 4) == 0); - assert(term_snapshot_cluster(NULL, TERM_TEXT_CLUSTER, cps, 4) == 0); + assert(wsap_vtcore_snapshot_cluster(NULL, 'a', cps, 4) == 0); + assert(wsap_vtcore_snapshot_cluster(NULL, WSAP_VTCORE_TEXT_CLUSTER, cps, 4) == 0); assert(cps[0] == 0xAAAA); - struct term *t = tt_new(4, 2); + struct wsap_vtcore *t = tt_new(4, 2); tt_write(t, "e\xcc\x81", 3); - struct term_snapshot *s = term_snapshot_new(); - assert(term_snapshot_update(s, t)); + struct wsap_vtcore_snapshot *s = wsap_vtcore_snapshot_new(); + assert(wsap_vtcore_snapshot_update(s, t)); - const struct term_view *view = term_snapshot_view(s); + const struct wsap_vtcore_view *view = wsap_vtcore_snapshot_view(s); const uint32_t *palette = view->palette; - assert(term_snapshot_update(s, t)); - assert(term_snapshot_view(s) == view && view->palette == palette); - - assert(term_snapshot_row(s, -1) == NULL); - assert(term_snapshot_row(s, 2) == NULL); - assert(term_snapshot_row_key(s, -1) == 0); - assert(term_snapshot_row_key(s, 2) == 0); - struct term_span off = term_snapshot_row_selection(s, 2); + assert(wsap_vtcore_snapshot_update(s, t)); + assert(wsap_vtcore_snapshot_view(s) == view && view->palette == palette); + + assert(wsap_vtcore_snapshot_row(s, -1) == NULL); + assert(wsap_vtcore_snapshot_row(s, 2) == NULL); + assert(wsap_vtcore_snapshot_row_key(s, -1) == 0); + assert(wsap_vtcore_snapshot_row_key(s, 2) == 0); + struct wsap_vtcore_span off = wsap_vtcore_snapshot_row_selection(s, 2); assert(off.begin == 0 && off.end == 0); /* A cluster cell gives its count with no buffer, and with cap 0 it * writes nothing. */ - uint32_t text = term_snapshot_row(s, 0)[0].text; - assert(text & TERM_TEXT_CLUSTER); - assert(term_snapshot_cluster(s, text, NULL, 0) == 2); - assert(term_snapshot_cluster(s, text, cps, 0) == 2); + uint32_t text = wsap_vtcore_snapshot_row(s, 0)[0].text; + assert(text & WSAP_VTCORE_TEXT_CLUSTER); + assert(wsap_vtcore_snapshot_cluster(s, text, NULL, 0) == 2); + assert(wsap_vtcore_snapshot_cluster(s, text, cps, 0) == 2); assert(cps[0] == 0xAAAA); - assert(term_snapshot_cluster(s, text, NULL, 4) == 2); + assert(wsap_vtcore_snapshot_cluster(s, text, NULL, 4) == 2); /* A plain code point is one code point, and cap 0 writes nothing. */ - assert(term_snapshot_cluster(s, 'a', NULL, 0) == 1); - assert(term_snapshot_cluster(s, 'a', cps, 0) == 1); + assert(wsap_vtcore_snapshot_cluster(s, 'a', NULL, 0) == 1); + assert(wsap_vtcore_snapshot_cluster(s, 'a', cps, 0) == 1); assert(cps[0] == 0xAAAA); - assert(term_snapshot_cluster(s, 'a', cps, 4) == 1 && cps[0] == 'a'); + assert(wsap_vtcore_snapshot_cluster(s, 'a', cps, 4) == 1 && cps[0] == 'a'); - term_snapshot_free(s); - term_free(t); + wsap_vtcore_snapshot_free(s); + wsap_vtcore_free(t); } static void test_string_payloads(void) @@ -1508,7 +1508,7 @@ static void test_string_payloads(void) for (size_t c = 0; c < 3; c++) { title[0] = 0; response_len = 0; - struct term *t = tt_new_opts(80, 4, &title_cb); + struct wsap_vtcore *t = tt_new_opts(80, 4, &title_cb); for (size_t i = 0; i < n;) { size_t take = n - i < chunks[c] ? n - i : chunks[c]; tt_write(t, input + i, take); @@ -1528,14 +1528,14 @@ static void test_string_payloads(void) assert(title[0] == 0); } } - term_free(t); + wsap_vtcore_free(t); } } } } } -/* term_new() refuses a name that a DCS reply could echo unsafely. */ +/* wsap_vtcore_new() refuses a name that a DCS reply could echo unsafely. */ static void test_host_name_rejected(void) { static const char *const bad[] = { @@ -1549,40 +1549,40 @@ static void test_host_name_rejected(void) fits[63] = 0; for (size_t i = 0; i < sizeof(bad) / sizeof(bad[0]); i++) { - struct term_options opt = { .size = { .x = 10, .y = 3 }, .name = bad[i] }; - assert(!term_new(&opt)); + struct wsap_vtcore_options opt = { .size = { .x = 10, .y = 3 }, .name = bad[i] }; + assert(!wsap_vtcore_new(&opt)); } - struct term_options opt = { .size = { .x = 10, .y = 3 }, .name = longest }; - assert(!term_new(&opt)); + struct wsap_vtcore_options opt = { .size = { .x = 10, .y = 3 }, .name = longest }; + assert(!wsap_vtcore_new(&opt)); opt.name = fits; - struct term *t = term_new(&opt); + struct wsap_vtcore *t = wsap_vtcore_new(&opt); assert(t); - term_free(t); + wsap_vtcore_free(t); } static void test_newline_policy_survives_reset(void) { static const char *const resets[] = { "\033c", "\033[!p", "\033[20l" }; for (size_t i = 0; i < sizeof(resets) / sizeof(resets[0]); i++) { - struct term *t = tt_new(20, 6); - term_feed(t, "a\n", 2, TERM_FEED_ONLCR); + struct wsap_vtcore *t = tt_new(20, 6); + wsap_vtcore_feed(t, "a\n", 2, WSAP_VTCORE_FEED_ONLCR); assert(tt_cursor_x(t) == 0); write_seq(t, resets[i]); - term_feed(t, "b\nc", 3, TERM_FEED_ONLCR); + wsap_vtcore_feed(t, "b\nc", 3, WSAP_VTCORE_FEED_ONLCR); assert(tt_cursor_x(t) == 1); assert(row_is(t, tt_cursor_y(t), "c")); - term_free(t); + wsap_vtcore_free(t); } } static void test_lnm_mode_alone_is_not_sticky(void) { - struct term *t = tt_new(20, 6); + struct wsap_vtcore *t = tt_new(20, 6); write_seq(t, "\033[20h\033c"); tt_write(t, "b\nc", 3); assert(tt_cursor_x(t) == 2); - term_free(t); + wsap_vtcore_free(t); } /* A C0 control ends an unfinished UTF-8 sequence, which prints U+FFFD. A @@ -1591,13 +1591,13 @@ static void test_c0_ends_utf8_sequence(void) { static const char input[] = "\xc3\n\xa9z"; for (size_t split = 0; split < sizeof(input) - 1; split++) { - struct term *t = tt_new(20, 4); + struct wsap_vtcore *t = tt_new(20, 4); tt_write(t, input, split); tt_write(t, input + split, sizeof(input) - 1 - split); assert(tt_cell_cp(t, tt_cell(t, 0, 0)) == 0xFFFD); assert(tt_cell_cp(t, tt_cell(t, 1, 1)) == 0xFFFD); assert(tt_cell_cp(t, tt_cell(t, 2, 1)) == 'z'); - term_free(t); + wsap_vtcore_free(t); } } @@ -1611,8 +1611,8 @@ static void test_bulk_rows_survive_edits(void) for (size_t i = 0; i < sizeof(flood); i++) flood[i] = (char)('a' + (i * 7 + i / COLS) % 26); - struct term *bulk = tt_new(COLS, ROWS); - struct term *bytes = tt_new(COLS, ROWS); + struct wsap_vtcore *bulk = tt_new(COLS, ROWS); + struct wsap_vtcore *bytes = tt_new(COLS, ROWS); write_seq(bulk, "\033[1;4;38;2;9;8;7;48;2;1;2;3m"); write_seq(bytes, "\033[1;4;38;2;9;8;7;48;2;1;2;3m"); tt_write(bulk, flood, sizeof(flood)); @@ -1637,24 +1637,24 @@ static void test_bulk_rows_survive_edits(void) write_seq(bytes, "\033[?1049hALT\033[?1049l"); assert_same_screen(bulk, bytes); for (int i = 0; i < 3; i++) { - term_scroll(bulk, 100); - term_scroll(bytes, 100); + wsap_vtcore_scroll(bulk, 100); + wsap_vtcore_scroll(bytes, 100); assert_same_screen(bulk, bytes); } - term_scroll_to(bulk, 0); - term_scroll_to(bytes, 0); + wsap_vtcore_scroll_to(bulk, 0); + wsap_vtcore_scroll_to(bytes, 0); /* Selection text reads rows straight from history. */ - term_scroll(bulk, 50); - term_scroll(bytes, 50); + wsap_vtcore_scroll(bulk, 50); + wsap_vtcore_scroll(bytes, 50); tt_select(bulk, 0, 0, COLS - 1, 2); tt_select(bytes, 0, 0, COLS - 1, 2); char *a = tt_selection_text(bulk), *b = tt_selection_text(bytes); assert(a && b && !strcmp(a, b) && strlen(a) >= COLS); free(a); free(b); - term_scroll_to(bulk, 0); - term_scroll_to(bytes, 0); + wsap_vtcore_scroll_to(bulk, 0); + wsap_vtcore_scroll_to(bytes, 0); /* Reflow narrower and wider keeps history identical. */ tt_resize(bulk, 29, ROWS); @@ -1663,27 +1663,27 @@ static void test_bulk_rows_survive_edits(void) tt_resize(bulk, 61, ROWS + 2); tt_resize(bytes, 61, ROWS + 2); assert_same_screen(bulk, bytes); - term_scroll(bulk, 20); - term_scroll(bytes, 20); + wsap_vtcore_scroll(bulk, 20); + wsap_vtcore_scroll(bytes, 20); assert_same_screen(bulk, bytes); - term_free(bulk); - term_free(bytes); + wsap_vtcore_free(bulk); + wsap_vtcore_free(bytes); } static void test_erase_keeps_used_rows(void) { for (int row = 0; row < 40; row++) { - struct term *t = tt_new(20, 40); + struct wsap_vtcore *t = tt_new(20, 40); char seq[64]; int len = snprintf(seq, sizeof(seq), "\033[%d;1Hsaved\033[2J", row + 1); tt_write(t, seq, (size_t)len); assert(tt_history(t) == row + 1); for (int y = 0; y < 40; y++) assert(row_eq(t, y, "")); - term_scroll(t, 1); + wsap_vtcore_scroll(t, 1); assert(row_eq(t, 0, "saved")); - term_free(t); + wsap_vtcore_free(t); } } @@ -1691,20 +1691,20 @@ static void test_blank_rows(void) { /* ED 2 pushes used rows to scrollback; the erased screen reads as * default-color blanks through every accessor. */ - struct term *t = tt_new(10, 4); + struct wsap_vtcore *t = tt_new(10, 4); write_seq(t, "one\r\ntwo\r\nthree"); write_seq(t, "\033[2J"); assert(tt_history(t) == 3); for (int y = 0; y < 4; y++) for (int x = 0; x < 10; x++) { - const struct term_cell *c = tt_view_cell(t, x, y); - assert(c->text == ' ' && c->fg == TERM_COLOR_FG && - c->bg == TERM_COLOR_BG); + const struct wsap_vtcore_cell *c = tt_view_cell(t, x, y); + assert(c->text == ' ' && c->fg == WSAP_VTCORE_COLOR_FG && + c->bg == WSAP_VTCORE_COLOR_BG); assert(tt_cell(t, x, y)->text == ' '); } - term_scroll(t, 3); + wsap_vtcore_scroll(t, 3); assert(row_is(t, 0, "one") && row_is(t, 1, "two") && row_is(t, 2, "three")); - term_scroll_to(t, 0); + wsap_vtcore_scroll_to(t, 0); /* A scrolled-in blank row reads as blanks, then accepts new text. */ write_seq(t, "\033[4;1Hlast\r\n\r\n\r\n"); @@ -1712,7 +1712,7 @@ static void test_blank_rows(void) assert(tt_view_cell(t, x, 3)->text == ' '); write_seq(t, "\033[4;6Hhi"); assert(row_is(t, 3, " hi")); - term_free(t); + wsap_vtcore_free(t); /* A spaces-only row does not extend ED 2 history. */ t = tt_new(10, 6); @@ -1720,23 +1720,23 @@ static void test_blank_rows(void) assert(tt_history(t) == 0); write_seq(t, "\033[2J"); assert(tt_history(t) == 1); - term_scroll(t, 1); + wsap_vtcore_scroll(t, 1); assert(row_is(t, 0, "top")); - term_scroll_to(t, 0); + wsap_vtcore_scroll_to(t, 0); /* Blank rows survive a resize and still read as blanks. */ tt_resize(t, 20, 6); for (int x = 0; x < 20; x++) assert(tt_cell(t, x, 5)->text == ' ' && - tt_cell(t, x, 5)->bg == TERM_COLOR_BG); - term_free(t); + tt_cell(t, x, 5)->bg == WSAP_VTCORE_COLOR_BG); + wsap_vtcore_free(t); /* Erasing a blank row with a color still produces a colored row. */ t = tt_new(10, 4); write_seq(t, "\033[2J\033[41m\033[2K"); - assert(tt_cell(t, 0, 0)->bg != TERM_COLOR_BG); + assert(tt_cell(t, 0, 0)->bg != WSAP_VTCORE_COLOR_BG); assert(tt_cell(t, 9, 0)->bg == tt_cell(t, 0, 0)->bg); - term_free(t); + wsap_vtcore_free(t); } static void test_csi_text_chunks(void) @@ -1757,26 +1757,26 @@ static void test_csi_text_chunks(void) for (size_t c = 0; c < sizeof(cases) / sizeof(cases[0]); c++) { const char *seq = cases[c]; size_t len = strlen(seq); - struct term *expected = tt_new(20, 40); + struct wsap_vtcore *expected = tt_new(20, 40); write_seq(expected, seq); for (size_t split = 0; split <= len; split++) { - struct term *actual = tt_new(20, 40); + struct wsap_vtcore *actual = tt_new(20, 40); tt_write(actual, seq, split); tt_write(actual, seq + split, len - split); assert(tt_cursor_x(actual) == tt_cursor_x(expected)); assert(tt_cursor_y(actual) == tt_cursor_y(expected)); assert(tt_history(actual) == tt_history(expected)); int history = tt_history(expected); - term_scroll(actual, history); - term_scroll(expected, history); + wsap_vtcore_scroll(actual, history); + wsap_vtcore_scroll(expected, history); for (int page = 0; page <= history; page++) { assert_same_rows(actual, expected, 40); - term_scroll(actual, -1); - term_scroll(expected, -1); + wsap_vtcore_scroll(actual, -1); + wsap_vtcore_scroll(expected, -1); } - term_free(actual); + wsap_vtcore_free(actual); } - term_free(expected); + wsap_vtcore_free(expected); } } @@ -1785,7 +1785,7 @@ static void test_csi_text_chunks(void) * keep their text. */ static void test_grow_past_reservation(void) { - struct term *t = tt_new(40, 10); + struct wsap_vtcore *t = tt_new(40, 10); for (int i = 0; i < 30; i++) { char line[32]; int len = snprintf(line, sizeof(line), "hist %02d\r\n", i); @@ -1821,20 +1821,20 @@ static void test_grow_past_reservation(void) tt_write(t, "\033[?1049l", 8); bool found = false; - term_scroll(t, tt_history(t)); + wsap_vtcore_scroll(t, tt_history(t)); for (int y = 0; y < tt_rows(t) && !found; y++) found = row_eq(t, y, "hist 00"); assert(found); - term_scroll(t, -tt_history(t)); + wsap_vtcore_scroll(t, -tt_history(t)); bool last = false; for (int y = 0; y < tt_rows(t) && !last; y++) last = row_eq(t, y, "fill 0999"); assert(last); - term_free(t); + wsap_vtcore_free(t); } struct concurrent_worker_args { - struct term *t; + struct wsap_vtcore *t; _Atomic bool done; }; @@ -1853,7 +1853,7 @@ static void *concurrent_feed_worker(void *arg) size_t len = strlen(concurrent_stream); for (int i = 0; i < 2000; i++) { - term_feed(w->t, concurrent_stream, len, 0); + wsap_vtcore_feed(w->t, concurrent_stream, len, 0); } atomic_store(&w->done, true); return NULL; @@ -1861,11 +1861,11 @@ static void *concurrent_feed_worker(void *arg) static void test_concurrent_feed_and_snapshot(void) { - struct term_options opt = { + struct wsap_vtcore_options opt = { .size = { .x = 80, .y = 24 }, .scrollback = 1000, }; - struct term *t = term_new(&opt); + struct wsap_vtcore *t = wsap_vtcore_new(&opt); assert(t != NULL); struct concurrent_worker_args w = { .t = t, .done = false }; @@ -1873,43 +1873,43 @@ static void test_concurrent_feed_and_snapshot(void) int err = pthread_create(&th, NULL, concurrent_feed_worker, &w); assert(err == 0); - struct term_snapshot *snap = term_snapshot_new(); + struct wsap_vtcore_snapshot *snap = wsap_vtcore_snapshot_new(); assert(snap != NULL); while (!atomic_load(&w.done)) { - bool ok = term_snapshot_update(snap, t); + bool ok = wsap_vtcore_snapshot_update(snap, t); assert(ok); - struct term_vector2i sz = term_size(t); + struct wsap_vtcore_vector2i sz = wsap_vtcore_size(t); assert(sz.x > 0 && sz.y > 0); - term_scroll(t, 2); - term_scroll_to(t, 0); - struct term_modes m = term_modes(t); + wsap_vtcore_scroll(t, 2); + wsap_vtcore_scroll_to(t, 0); + struct wsap_vtcore_modes m = wsap_vtcore_modes(t); (void)m; - struct term_cursor c = term_cursor(t); + struct wsap_vtcore_cursor c = wsap_vtcore_cursor(t); (void)c; /* Every reader is safe while another thread feeds. */ - term_select_start(t, (struct term_vector2i){ .x = 0, .y = 0 }, false, TERM_SELECT_WORD); - term_select_extend(t, (struct term_vector2i){ .x = 40, .y = 10 }, false); - (void)term_has_selection(t); - term_text_free(term_selection_text(t)); - term_text_free(term_link_at(t, (struct term_vector2i){ .x = 1, .y = 1 })); - term_text_free(term_cwd(t)); - term_text_free(term_pointer_shape(t)); - (void)term_history_rows(t); - term_text_free(term_history_text(t, 5)); - struct term_scrollback sb = term_scrollback(t); + wsap_vtcore_select_start(t, (struct wsap_vtcore_vector2i){ .x = 0, .y = 0 }, false, WSAP_VTCORE_SELECT_WORD); + wsap_vtcore_select_extend(t, (struct wsap_vtcore_vector2i){ .x = 40, .y = 10 }, false); + (void)wsap_vtcore_has_selection(t); + wsap_vtcore_text_free(wsap_vtcore_selection_text(t)); + wsap_vtcore_text_free(wsap_vtcore_link_at(t, (struct wsap_vtcore_vector2i){ .x = 1, .y = 1 })); + wsap_vtcore_text_free(wsap_vtcore_cwd(t)); + wsap_vtcore_text_free(wsap_vtcore_pointer_shape(t)); + (void)wsap_vtcore_history_rows(t); + wsap_vtcore_text_free(wsap_vtcore_history_text(t, 5)); + struct wsap_vtcore_scrollback sb = wsap_vtcore_scrollback(t); assert(sb.offset >= 0 && sb.total >= 0); } pthread_join(th, NULL); - bool ok = term_snapshot_update(snap, t); + bool ok = wsap_vtcore_snapshot_update(snap, t); assert(ok); /* The reader changed only the view and the selection. The screen and * the history must match a terminal that got the same bytes on one * thread. */ - struct term *ref = term_new(&opt); + struct wsap_vtcore *ref = wsap_vtcore_new(&opt); assert(ref != NULL); for (int i = 0; i < 2000; i++) tt_write(ref, concurrent_stream, strlen(concurrent_stream)); @@ -1926,65 +1926,65 @@ static void test_concurrent_feed_and_snapshot(void) } free(got); free(want); - char *text = term_history_text(t, 1000); - char *text_ref = term_history_text(ref, 1000); + char *text = wsap_vtcore_history_text(t, 1000); + char *text_ref = wsap_vtcore_history_text(ref, 1000); assert(text && text_ref && !strcmp(text, text_ref)); - term_text_free(text); - term_text_free(text_ref); + wsap_vtcore_text_free(text); + wsap_vtcore_text_free(text_ref); - term_free(ref); - term_snapshot_free(snap); - term_free(t); + wsap_vtcore_free(ref); + wsap_vtcore_snapshot_free(snap); + wsap_vtcore_free(t); } static void test_reserved_options_must_be_zero(void) { - struct term_options opt = { .size = { .x = 10, .y = 2 } }; - struct term *t = term_new(&opt); + struct wsap_vtcore_options opt = { .size = { .x = 10, .y = 2 } }; + struct wsap_vtcore *t = wsap_vtcore_new(&opt); assert(t != NULL); - term_free(t); + wsap_vtcore_free(t); size_t words = sizeof(opt.reserved) / sizeof(opt.reserved[0]); for (size_t i = 0; i < words; i++) { opt.reserved[i] = 1; - assert(term_new(&opt) == NULL); + assert(wsap_vtcore_new(&opt) == NULL); opt.reserved[i] = 0; } opt.reserved[words - 1] = 0x80000000u; - assert(term_new(&opt) == NULL); + assert(wsap_vtcore_new(&opt) == NULL); opt.reserved[words - 1] = 0; - t = term_new(&opt); + t = wsap_vtcore_new(&opt); assert(t != NULL); - term_free(t); + wsap_vtcore_free(t); } struct lock_probe { - struct term *t; + struct wsap_vtcore *t; _Atomic bool entered; }; static void *lock_probe_worker(void *arg) { struct lock_probe *p = arg; - term_lock(p->t); + wsap_vtcore_lock(p->t); atomic_store(&p->entered, true); - term_unlock(p->t); + wsap_vtcore_unlock(p->t); return NULL; } -/* term_lock() nests on the owning thread. Another thread waits until the - * last term_unlock(). */ +/* wsap_vtcore_lock() nests on the owning thread. Another thread waits until the + * last wsap_vtcore_unlock(). */ static void test_lock_reentrant_across_threads(void) { - struct term *t = term_new(&(struct term_options){ + struct wsap_vtcore *t = wsap_vtcore_new(&(struct wsap_vtcore_options){ .size = { .x = 80, .y = 24 }, }); assert(t != NULL); - term_lock(t); - term_lock(t); + wsap_vtcore_lock(t); + wsap_vtcore_lock(t); assert(tt_cols(t) == 80); - term_unlock(t); + wsap_vtcore_unlock(t); struct lock_probe p = { .t = t, .entered = false }; pthread_t th; @@ -1992,11 +1992,11 @@ static void test_lock_reentrant_across_threads(void) for (int i = 0; i < 1000; i++) sched_yield(); assert(!atomic_load(&p.entered)); - term_unlock(t); + wsap_vtcore_unlock(t); assert(pthread_join(th, NULL) == 0); assert(atomic_load(&p.entered)); - term_free(t); + wsap_vtcore_free(t); } int main(void) @@ -2032,21 +2032,21 @@ int main(void) test_bulk_rows_survive_edits(); test_host_name_rejected(); - assert(!strcmp(TERM_UNICODE_DATA_VERSION, "18.0.0")); - assert(!strcmp(term_unicode_version(), TERM_UNICODE_DATA_VERSION)); - assert(term_unicode_width('A') == 1); - assert(term_unicode_width(0x0301) == 0); - assert(term_unicode_width(0x754C) == 2); - assert(term_unicode_width(0x1FAE0) == 2); - assert(term_unicode_emoji_presentation(0x1FAE0)); - assert(term_unicode_width(0x1FAEB) == 2); - assert(term_unicode_emoji_presentation(0x1FAEB)); + assert(!strcmp(WSAP_VTCORE_UNICODE_DATA_VERSION, "18.0.0")); + assert(!strcmp(wsap_vtcore_unicode_version(), WSAP_VTCORE_UNICODE_DATA_VERSION)); + assert(wsap_vtcore_unicode_width('A') == 1); + assert(wsap_vtcore_unicode_width(0x0301) == 0); + assert(wsap_vtcore_unicode_width(0x754C) == 2); + assert(wsap_vtcore_unicode_width(0x1FAE0) == 2); + assert(wsap_vtcore_unicode_emoji_presentation(0x1FAE0)); + assert(wsap_vtcore_unicode_width(0x1FAEB) == 2); + assert(wsap_vtcore_unicode_emoji_presentation(0x1FAEB)); { /* A Jamo Extended-B vowel draws inside its leading consonant. */ - struct term *t = term_new(&(struct term_options){ .size = { .x = 10, .y = 2 } }); - term_feed(t, "\xe1\x84\x80\xed\x9e\xb0", 6, 0); - assert(term_cursor(t).pos.x == 2); - term_free(t); + struct wsap_vtcore *t = wsap_vtcore_new(&(struct wsap_vtcore_options){ .size = { .x = 10, .y = 2 } }); + wsap_vtcore_feed(t, "\xe1\x84\x80\xed\x9e\xb0", 6, 0); + assert(wsap_vtcore_cursor(t).pos.x == 2); + wsap_vtcore_free(t); } test_wide_characters(); @@ -2069,7 +2069,7 @@ int main(void) test_parameter_limits(); test_unterminated_control_strings_do_not_swallow_text(); test_c0_controls_after_esc_are_executed(); - struct term *t = tt_new_opts(10, 4, &reply_cb); + struct wsap_vtcore *t = tt_new_opts(10, 4, &reply_cb); write_seq(t, "\033(Babc\r\nD"); assert(tt_cell(t, 0, 0)->text == 'a'); assert(tt_cell(t, 0, 1)->text == 'D'); @@ -2133,7 +2133,7 @@ int main(void) write_seq(t, "\033[?6;69l"); write_seq(t, "\033[?1;5;1004;2026h\033[!p"); - struct term_modes modes = term_modes(t); + struct wsap_vtcore_modes modes = wsap_vtcore_modes(t); assert(!modes.app_cursor && !modes.focus_events); assert(!modes.synchronized && !modes.reverse_video); write_seq(t, "kept\033c"); @@ -2147,28 +2147,28 @@ int main(void) assert(tt_cell(t, 0, 0)->text == 'A'); write_seq(t, "\033[2;4H\033[2J"); assert(tt_cursor_x(t) == 3 && tt_cursor_y(t) == 1); - assert(term_modes(t).mouse == TERM_MOUSE_OFF); + assert(wsap_vtcore_modes(t).mouse == WSAP_VTCORE_MOUSE_OFF); write_seq(t, "\033[?1000;1006h"); - assert(term_modes(t).mouse == TERM_MOUSE_NORMAL); - assert(term_modes(t).mouse_encoding == TERM_MOUSE_ENC_SGR); + assert(wsap_vtcore_modes(t).mouse == WSAP_VTCORE_MOUSE_NORMAL); + assert(wsap_vtcore_modes(t).mouse_encoding == WSAP_VTCORE_MOUSE_ENC_SGR); write_seq(t, "\033[?1002h"); - assert(term_modes(t).mouse == TERM_MOUSE_BUTTON); - assert(term_modes(t).mouse_encoding == TERM_MOUSE_ENC_SGR); + assert(wsap_vtcore_modes(t).mouse == WSAP_VTCORE_MOUSE_BUTTON); + assert(wsap_vtcore_modes(t).mouse_encoding == WSAP_VTCORE_MOUSE_ENC_SGR); write_seq(t, "\033[?1003h"); - assert(term_modes(t).mouse == TERM_MOUSE_ANY); + assert(wsap_vtcore_modes(t).mouse == WSAP_VTCORE_MOUSE_ANY); write_seq(t, "\033[?1006l"); - assert(term_modes(t).mouse_encoding == TERM_MOUSE_ENC_X10); + assert(wsap_vtcore_modes(t).mouse_encoding == WSAP_VTCORE_MOUSE_ENC_X10); write_seq(t, "\033[?1015h"); - assert(term_modes(t).mouse_encoding == TERM_MOUSE_ENC_URXVT); + assert(wsap_vtcore_modes(t).mouse_encoding == WSAP_VTCORE_MOUSE_ENC_URXVT); write_seq(t, "\033[?1016h"); - assert(term_modes(t).mouse_encoding == TERM_MOUSE_ENC_SGR_PIXELS); + assert(wsap_vtcore_modes(t).mouse_encoding == WSAP_VTCORE_MOUSE_ENC_SGR_PIXELS); write_seq(t, "\033[?1004h"); - term_focus(t, false); + wsap_vtcore_focus(t, false); assert(!strcmp(response, "\033[O")); - term_focus(t, true); + wsap_vtcore_focus(t, true); assert(!strcmp(response, "\033[I")); write_seq(t, "\033[?1003l"); - assert(term_modes(t).mouse == TERM_MOUSE_OFF); + assert(wsap_vtcore_modes(t).mouse == WSAP_VTCORE_MOUSE_OFF); response_len = 0; write_seq(t, "\033]10;?\007"); assert(!strcmp(response, "\033]10;rgb:ffff/ffff/ffff\033\\")); @@ -2176,7 +2176,7 @@ int main(void) assert(!strcmp(response, "\033P0+r696e646e\033\\")); write_seq(t, "\033P+q6b696e64\033\\"); assert(!strcmp(response, "\033P1+r6b696e64=1b5b313b3242\033\\")); - term_free(t); + wsap_vtcore_free(t); t = tt_new(40, 4); write_seq(t, "hello 世界 \r\nsecond line\r\nhttps://example.com/path."); tt_select(t, 9, 0, 0, 0); @@ -2194,13 +2194,13 @@ int main(void) free(text); assert(!tt_link_at(t, 10, 1)); write_seq(t, "\033[?2004h"); - assert(term_modes(t).bracketed_paste); + assert(wsap_vtcore_modes(t).bracketed_paste); text = tt_selection_text(t); assert(text && !strcmp(text, "hello 世界\nsecond")); free(text); write_seq(t, "\033[?2004l\r\nlast\r\n"); - assert(!term_modes(t).bracketed_paste); - term_scroll(t, 1); + assert(!wsap_vtcore_modes(t).bracketed_paste); + wsap_vtcore_scroll(t, 1); tt_select(t, 0, 0, 9, 0); text = tt_selection_text(t); assert(text && !strcmp(text, "hello 世界")); @@ -2209,7 +2209,7 @@ int main(void) text = tt_selection_text(t); assert(text && !strcmp(text, "hello 世界")); free(text); - term_free(t); + wsap_vtcore_free(t); t = tt_new(40, 4); write_seq(t, "\033[31;44mA\033[>4;0mB\033[>4;1m\033[31mC"); assert(tt_cell(t, 0, 0)->fg == tt_cell(t, 1, 0)->fg); @@ -2218,49 +2218,49 @@ int main(void) assert(tt_cell(t, 0, 0)->bg == tt_cell(t, 2, 0)->bg); assert(tt_cursor_x(t) == 3 && tt_cursor_y(t) == 0); write_seq(t, "\033[0mD"); - assert(tt_cell(t, 3, 0)->fg == TERM_COLOR_FG); - assert(tt_cell(t, 3, 0)->bg == TERM_COLOR_BG); - term_free(t); + assert(tt_cell(t, 3, 0)->fg == WSAP_VTCORE_COLOR_FG); + assert(tt_cell(t, 3, 0)->bg == WSAP_VTCORE_COLOR_BG); + wsap_vtcore_free(t); t = tt_new(10, 4); write_seq(t, "ABCDEFGHIJ\r\n\r\n\r\n\r\n"); - term_scroll(t, 1); + wsap_vtcore_scroll(t, 1); assert(tt_view_cell(t, 0, 0)->text == 'A'); assert(tt_view_cell(t, 9, 0)->text == 'J'); - term_scroll_to(t, 0); + wsap_vtcore_scroll_to(t, 0); for (int i = 0; i < TEST_SCROLLBACK; i++) write_seq(t, "xy\r\n"); - term_scroll(t, 1); + wsap_vtcore_scroll(t, 1); assert(tt_view_cell(t, 0, 0)->text == 'x'); for (int c = 2; c < 10; c++) { assert(tt_view_cell(t, c, 0)->text == ' '); - assert(tt_view_cell(t, c, 0)->bg == TERM_COLOR_BG); + assert(tt_view_cell(t, c, 0)->bg == WSAP_VTCORE_COLOR_BG); } - term_free(t); + wsap_vtcore_free(t); t = tt_new(10, 4); write_seq(t, "\033[41m\033[2K"); - term_color erased_bg = tt_cell(t, 0, 0)->bg; - assert(erased_bg != TERM_COLOR_BG); + wsap_vtcore_color erased_bg = tt_cell(t, 0, 0)->bg; + assert(erased_bg != WSAP_VTCORE_COLOR_BG); assert(tt_cell(t, 9, 0)->bg == erased_bg); write_seq(t, "\033[m\n\n\n\n"); - term_scroll(t, 1); + wsap_vtcore_scroll(t, 1); assert(tt_view_cell(t, 9, 0)->bg == erased_bg); - assert(tt_view_cell(t, 10, 0)->bg == TERM_COLOR_BG); - term_free(t); + assert(tt_view_cell(t, 10, 0)->bg == WSAP_VTCORE_COLOR_BG); + wsap_vtcore_free(t); t = tt_new(10, 4); write_seq(t, "\033[Hnormal"); write_seq(t, "\033[?1049h"); for (int c = 0; c < 10; c++) { assert(tt_cell(t, c, 0)->text == ' '); - assert(tt_cell(t, c, 0)->bg == TERM_COLOR_BG); + assert(tt_cell(t, c, 0)->bg == WSAP_VTCORE_COLOR_BG); } write_seq(t, "\033[Halt\n\033[2J"); write_seq(t, "\033[?1049l"); assert(tt_cell(t, 0, 0)->text == 'n' && tt_cell(t, 5, 0)->text == 'l'); - term_free(t); + wsap_vtcore_free(t); t = tt_new(20, 8); write_seq(t, "one\r\ntwo\r\nthree\r\nfour\r\nfive\r\n$ "); @@ -2268,9 +2268,9 @@ int main(void) tt_resize(t, 20, 3); assert(tt_cursor_y(t) == 2 && tt_history(t) == 3); assert(row_is(t, 0, "four") && row_is(t, 1, "five") && row_is(t, 2, "$")); - term_scroll(t, 3); + wsap_vtcore_scroll(t, 3); assert(row_is(t, 0, "one") && row_is(t, 1, "two") && row_is(t, 2, "three")); - term_scroll_to(t, 0); + wsap_vtcore_scroll_to(t, 0); tt_resize(t, 20, 8); assert(tt_cursor_y(t) == 5 && tt_history(t) == 0); assert(row_is(t, 0, "one") && row_is(t, 2, "three") && row_is(t, 5, "$")); @@ -2279,7 +2279,7 @@ int main(void) tt_resize(t, 20, 6); assert(tt_cursor_y(t) == 5 && tt_history(t) == 0); assert(row_is(t, 0, "one") && row_is(t, 5, "$")); - term_free(t); + wsap_vtcore_free(t); t = tt_new(20, 6); write_seq(t, "a\r\nb\r\nc\r\nd\r\ne\r\n"); @@ -2291,7 +2291,7 @@ int main(void) assert(tt_history(t) == before); write_seq(t, "\033[?1049l"); assert(row_is(t, 0, "a") && row_is(t, 4, "e")); - term_free(t); + wsap_vtcore_free(t); t = tt_new(40, 6); write_seq(t, "\033[?1049h\033[1;38Hxy"); @@ -2300,7 +2300,7 @@ int main(void) assert(tt_cursor_x(t) < tt_cols(t)); write_seq(t, "Q"); assert(tt_cell(t, tt_cursor_x(t) - 1, tt_cursor_y(t))->text == 'Q'); - term_free(t); + wsap_vtcore_free(t); t = tt_new(8, 4); write_seq(t, "abcdefghijkl"); @@ -2313,7 +2313,7 @@ int main(void) text = tt_selection_text(t); assert(text && !strcmp(text, "abcd\nefgh")); free(text); - term_free(t); + wsap_vtcore_free(t); t = tt_new(10, 4); write_seq(t, "abcdef"); @@ -2326,7 +2326,7 @@ int main(void) write_seq(t, "\033[10P"); assert(row_is(t, 0, "ab")); assert(tt_cursor_x(t) == 2 && tt_cursor_y(t) == 0); - term_free(t); + wsap_vtcore_free(t); t = tt_new(8, 4); write_seq(t, "abcdef"); @@ -2335,87 +2335,87 @@ int main(void) assert(tt_cursor_x(t) == 2 && tt_cursor_y(t) == 0); write_seq(t, "\033[2@"); assert(row_is(t, 0, "ab cde")); - term_free(t); + wsap_vtcore_free(t); t = tt_new(10, 4); - assert(term_cursor(t).style == TERM_CURSOR_BLOCK); - assert(term_cursor(t).blink == true); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_BLOCK); + assert(wsap_vtcore_cursor(t).blink == true); write_seq(t, "\033[2 q"); - assert(term_cursor(t).style == TERM_CURSOR_BLOCK); - assert(term_cursor(t).blink == false); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_BLOCK); + assert(wsap_vtcore_cursor(t).blink == false); write_seq(t, "\033[3 q"); - assert(term_cursor(t).style == TERM_CURSOR_UNDERLINE); - assert(term_cursor(t).blink == true); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_UNDERLINE); + assert(wsap_vtcore_cursor(t).blink == true); write_seq(t, "\033[4 q"); - assert(term_cursor(t).style == TERM_CURSOR_UNDERLINE); - assert(term_cursor(t).blink == false); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_UNDERLINE); + assert(wsap_vtcore_cursor(t).blink == false); write_seq(t, "\033[5 q"); - assert(term_cursor(t).style == TERM_CURSOR_BAR); - assert(term_cursor(t).blink == true); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_BAR); + assert(wsap_vtcore_cursor(t).blink == true); write_seq(t, "\033[6 q"); - assert(term_cursor(t).style == TERM_CURSOR_BAR); - assert(term_cursor(t).blink == false); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_BAR); + assert(wsap_vtcore_cursor(t).blink == false); write_seq(t, "\033[0 q"); - assert(term_cursor(t).style == TERM_CURSOR_BLOCK); - assert(term_cursor(t).blink == true); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_BLOCK); + assert(wsap_vtcore_cursor(t).blink == true); write_seq(t, "\033[5 q"); write_seq(t, "\033[ q"); - assert(term_cursor(t).style == TERM_CURSOR_BLOCK); - assert(term_cursor(t).blink == true); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_BLOCK); + assert(wsap_vtcore_cursor(t).blink == true); write_seq(t, "\033[6 q"); - assert(term_cursor(t).style == TERM_CURSOR_BAR && !term_cursor(t).blink); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_BAR && !wsap_vtcore_cursor(t).blink); write_seq(t, "\033[?1049h"); write_seq(t, "\033[3 q"); - assert(term_cursor(t).style == TERM_CURSOR_UNDERLINE && term_cursor(t).blink); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_UNDERLINE && wsap_vtcore_cursor(t).blink); write_seq(t, "\033[?1049l"); - assert(term_cursor(t).style == TERM_CURSOR_BAR && !term_cursor(t).blink); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_BAR && !wsap_vtcore_cursor(t).blink); - term_set_cursor_default(t, TERM_CURSOR_UNDERLINE, true); + wsap_vtcore_set_cursor_default(t, WSAP_VTCORE_CURSOR_UNDERLINE, true); write_seq(t, "\033[5 q"); - assert(term_cursor(t).style == TERM_CURSOR_BAR && term_cursor(t).blink); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_BAR && wsap_vtcore_cursor(t).blink); write_seq(t, "\033[0 q"); - assert(term_cursor(t).style == TERM_CURSOR_UNDERLINE && !term_cursor(t).blink); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_UNDERLINE && !wsap_vtcore_cursor(t).blink); write_seq(t, "\033[2 q"); - assert(term_cursor(t).style == TERM_CURSOR_BLOCK && !term_cursor(t).blink); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_BLOCK && !wsap_vtcore_cursor(t).blink); write_seq(t, "\033[ q"); - assert(term_cursor(t).style == TERM_CURSOR_UNDERLINE && !term_cursor(t).blink); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_UNDERLINE && !wsap_vtcore_cursor(t).blink); write_seq(t, "\033[1 q"); - assert(term_cursor(t).style == TERM_CURSOR_BLOCK && term_cursor(t).blink); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_BLOCK && wsap_vtcore_cursor(t).blink); write_seq(t, "\033[!p"); - assert(term_cursor(t).style == TERM_CURSOR_UNDERLINE && !term_cursor(t).blink); - term_free(t); + assert(wsap_vtcore_cursor(t).style == WSAP_VTCORE_CURSOR_UNDERLINE && !wsap_vtcore_cursor(t).blink); + wsap_vtcore_free(t); t = tt_new(20, 4); write_seq(t, "\033[1;2;3;4;9;53mA\033[21mB\033[4:2mC\033[22;24mD\033[0mE"); - const uint16_t styles = TERM_ATTR_BOLD | TERM_ATTR_FAINT | TERM_ATTR_ITALIC | - TERM_ATTR_STRIKE | TERM_ATTR_OVERLINE; + const uint16_t styles = WSAP_VTCORE_ATTR_BOLD | WSAP_VTCORE_ATTR_FAINT | WSAP_VTCORE_ATTR_ITALIC | + WSAP_VTCORE_ATTR_STRIKE | WSAP_VTCORE_ATTR_OVERLINE; assert((tt_cell(t, 0, 0)->attrs & styles) == styles); - assert(term_attr_underline(tt_cell(t, 0, 0)->attrs) == TERM_UNDERLINE_SINGLE); - assert(term_attr_underline(tt_cell(t, 1, 0)->attrs) == TERM_UNDERLINE_DOUBLE); - assert(term_attr_underline(tt_cell(t, 2, 0)->attrs) == TERM_UNDERLINE_DOUBLE); - assert(!(tt_cell(t, 3, 0)->attrs & (TERM_ATTR_BOLD | TERM_ATTR_FAINT))); - assert(term_attr_underline(tt_cell(t, 3, 0)->attrs) == TERM_UNDERLINE_NONE); + assert(wsap_vtcore_attr_underline(tt_cell(t, 0, 0)->attrs) == WSAP_VTCORE_UNDERLINE_SINGLE); + assert(wsap_vtcore_attr_underline(tt_cell(t, 1, 0)->attrs) == WSAP_VTCORE_UNDERLINE_DOUBLE); + assert(wsap_vtcore_attr_underline(tt_cell(t, 2, 0)->attrs) == WSAP_VTCORE_UNDERLINE_DOUBLE); + assert(!(tt_cell(t, 3, 0)->attrs & (WSAP_VTCORE_ATTR_BOLD | WSAP_VTCORE_ATTR_FAINT))); + assert(wsap_vtcore_attr_underline(tt_cell(t, 3, 0)->attrs) == WSAP_VTCORE_UNDERLINE_NONE); assert(tt_cell(t, 4, 0)->attrs == 0); - term_free(t); + wsap_vtcore_free(t); t = tt_new(20, 4); write_seq(t, "\033[30mA\033[0;1;30mB\033[0;90mC"); assert(tt_cell(t, 0, 0)->fg == tt_cell(t, 1, 0)->fg); assert(tt_cell(t, 1, 0)->fg != tt_cell(t, 2, 0)->fg); - assert(!(tt_cell(t, 0, 0)->attrs & TERM_ATTR_BOLD)); - assert(tt_cell(t, 1, 0)->attrs & TERM_ATTR_BOLD); - term_free(t); + assert(!(tt_cell(t, 0, 0)->attrs & WSAP_VTCORE_ATTR_BOLD)); + assert(tt_cell(t, 1, 0)->attrs & WSAP_VTCORE_ATTR_BOLD); + wsap_vtcore_free(t); const char *colon_rgb = "\033[48;2;145;2;34m\033[38;2;12;34;56mA" "\033[38:2::12:34:56mB\033[;mC"; @@ -2428,16 +2428,16 @@ int main(void) assert(tt_cell(t, x, 0)->fg == 0xFF0C2238); assert(tt_cell(t, x, 0)->bg == 0xFF910222); } - assert(tt_cell(t, 2, 0)->fg == TERM_COLOR_FG); - assert(tt_cell(t, 2, 0)->bg == TERM_COLOR_BG); - term_free(t); + assert(tt_cell(t, 2, 0)->fg == WSAP_VTCORE_COLOR_FG); + assert(tt_cell(t, 2, 0)->bg == WSAP_VTCORE_COLOR_BG); + wsap_vtcore_free(t); } t = tt_new(20, 4); write_seq(t, "\033[38;2;246;226;183;49mX"); assert(tt_cell(t, 0, 0)->fg == 0xFFF6E2B7); - assert(tt_cell(t, 0, 0)->bg == TERM_COLOR_BG); - term_free(t); + assert(tt_cell(t, 0, 0)->bg == WSAP_VTCORE_COLOR_BG); + wsap_vtcore_free(t); t = tt_new(20, 4); const char *clusters = "(\xc2\xa9\xef\xb8\x8f)\xe2\x98\xba\xef\xb8\x8e" @@ -2445,17 +2445,17 @@ int main(void) write_seq(t, clusters); assert(tt_cursor_x(t) == 7); - assert((tt_cell(t, 1, 0)->attrs & TERM_ATTR_EMOJI) && tt_cell(t, 1, 0)->width == 2); + assert((tt_cell(t, 1, 0)->attrs & WSAP_VTCORE_ATTR_EMOJI) && tt_cell(t, 1, 0)->width == 2); assert(tt_cell(t, 2, 0)->width == 0); - assert((tt_cell(t, 4, 0)->attrs & TERM_ATTR_TEXT) && tt_cell(t, 4, 0)->width == 1); - assert((tt_cell(t, 5, 0)->attrs & TERM_ATTR_EMOJI) && tt_cell(t, 5, 0)->width == 2); + assert((tt_cell(t, 4, 0)->attrs & WSAP_VTCORE_ATTR_TEXT) && tt_cell(t, 4, 0)->width == 1); + assert((tt_cell(t, 5, 0)->attrs & WSAP_VTCORE_ATTR_EMOJI) && tt_cell(t, 5, 0)->width == 2); assert(tt_cell(t, 6, 0)->width == 0); tt_select(t, 0, 0, 6, 0); text = tt_selection_text(t); assert(text && !strcmp(text, clusters)); free(text); - term_free(t); + wsap_vtcore_free(t); /* BS with a pending wrap clears the wrap and moves left from the last * column, as in xterm and the VT100. */ @@ -2471,11 +2471,11 @@ int main(void) write_seq(t, "\b \b"); assert(row_is(t, 0, "123 5")); assert(tt_cursor_x(t) == 3 && tt_cursor_y(t) == 0); - term_free(t); + wsap_vtcore_free(t); /* A renderer sees each cursor move within the row. */ t = tt_new(10, 2); - struct term_snapshot *snap = term_snapshot_new(); + struct wsap_vtcore_snapshot *snap = wsap_vtcore_snapshot_new(); write_seq(t, "abc"); uint64_t version = view_version(snap, t); write_seq(t, "\b"); @@ -2486,14 +2486,14 @@ int main(void) version = view_version(snap, t); write_seq(t, "\t"); assert(tt_cursor_x(t) == 8 && view_version(snap, t) != version); - term_snapshot_free(snap); - term_free(t); + wsap_vtcore_snapshot_free(snap); + wsap_vtcore_free(t); t = tt_new(20, 2); tt_write(t, "hello world", 11); assert(row_is(t, 0, "hello world")); assert(tt_cursor_x(t) == 11 && tt_cursor_y(t) == 0); - term_free(t); + wsap_vtcore_free(t); title[0] = 0; t = tt_new_opts(10, 4, &title_cb); @@ -2503,18 +2503,18 @@ int main(void) assert(!strcmp(title, "Second Title")); write_seq(t, "\033]1;Icon Name\007"); assert(!strcmp(title, "Icon Name")); - term_free(t); + wsap_vtcore_free(t); t = tt_new(20, 4); write_seq(t, "$ /mnt/work"); const char *round_trip = "\033[?1049h\033[?1049l"; tt_write(t, round_trip, strlen(round_trip)); assert(row_is(t, 0, "$ /mnt/work")); - term_free(t); + wsap_vtcore_free(t); /* A renderer sees both switches between the screens. */ t = tt_new(20, 4); - snap = term_snapshot_new(); + snap = wsap_vtcore_snapshot_new(); write_seq(t, "$ /mnt/work"); version = view_version(snap, t); write_seq(t, "\033[?1049h"); @@ -2523,22 +2523,22 @@ int main(void) write_seq(t, "\033[?1049l"); assert(view_version(snap, t) != version); assert(row_is(t, 0, "$ /mnt/work")); - term_snapshot_free(snap); - term_free(t); + wsap_vtcore_snapshot_free(snap); + wsap_vtcore_free(t); t = tt_new(20, 4); write_seq(t, "output"); write_seq(t, "\r\033[K../"); assert(row_is(t, 0, "../")); - term_free(t); + wsap_vtcore_free(t); t = tt_new(80, 24); - assert(!term_modes(t).alternate); + assert(!wsap_vtcore_modes(t).alternate); write_seq(t, "\033[?1049h"); - assert(term_modes(t).alternate); + assert(wsap_vtcore_modes(t).alternate); write_seq(t, "\033[?1049l"); - assert(!term_modes(t).alternate); - term_free(t); + assert(!wsap_vtcore_modes(t).alternate); + wsap_vtcore_free(t); const char *color_runs[] = { "\033[1;1H\033[48;2;10;20;30m\033[38;2;200;210;220ma" @@ -2560,9 +2560,9 @@ int main(void) assert(tt_cell(t, 1, 0)->fg == 0xffe6f0fa); assert(tt_cell(t, 1, 0)->bg == 0xff646e78); for (int col = 2; col < 100; col++) - assert(tt_cell(t, col, 0)->bg == TERM_COLOR_BG); + assert(tt_cell(t, col, 0)->bg == WSAP_VTCORE_COLOR_BG); assert(row_is(t, 1, "")); - term_free(t); + wsap_vtcore_free(t); } } |
