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 /src | |
| parent | ba75c8b0a1bba03ad92c53375432f122ddb4cb98 (diff) | |
| parent | dcebf9c7f954a55350b68d0ead1935612c4e2e05 (diff) | |
Merge branch 'wt/rename' into api-hardening
# Conflicts:
# README.md
Diffstat (limited to 'src')
| -rw-r--r-- | src/cell.h | 36 | ||||
| -rw-r--r-- | src/compat.h | 150 | ||||
| -rw-r--r-- | src/core.c | 282 | ||||
| -rw-r--r-- | src/core.h | 132 | ||||
| -rw-r--r-- | src/escape.c | 218 | ||||
| -rw-r--r-- | src/escape.h | 12 | ||||
| -rw-r--r-- | src/fastcsi.c | 68 | ||||
| -rw-r--r-- | src/gstore.c | 56 | ||||
| -rw-r--r-- | src/gstore.h | 20 | ||||
| -rw-r--r-- | src/hist.c | 352 | ||||
| -rw-r--r-- | src/hist.h | 70 | ||||
| -rw-r--r-- | src/hist_view.c | 86 | ||||
| -rw-r--r-- | src/hist_view.h | 26 | ||||
| -rw-r--r-- | src/input.c | 598 | ||||
| -rw-r--r-- | src/internal.h | 94 | ||||
| -rw-r--r-- | src/isa.c | 40 | ||||
| -rw-r--r-- | src/kernels.h | 186 | ||||
| -rw-r--r-- | src/meson.build | 10 | ||||
| -rw-r--r-- | src/osc/clipboard.c | 2 | ||||
| -rw-r--r-- | src/osc/dispatch.c | 56 | ||||
| -rw-r--r-- | src/osc/link.c | 44 | ||||
| -rw-r--r-- | src/osc/meson.build | 2 | ||||
| -rw-r--r-- | src/osc/misc.c | 14 | ||||
| -rw-r--r-- | src/osc/osc.h | 28 | ||||
| -rw-r--r-- | src/palette.c | 50 | ||||
| -rw-r--r-- | src/palette.h | 22 | ||||
| -rw-r--r-- | src/pen.h | 40 | ||||
| -rw-r--r-- | src/scan.c | 8 | ||||
| -rw-r--r-- | src/screen.c | 308 | ||||
| -rw-r--r-- | src/screen.h | 106 | ||||
| -rw-r--r-- | src/selection.c | 188 | ||||
| -rw-r--r-- | src/simd.h | 76 | ||||
| -rw-r--r-- | src/snapshot.c | 106 | ||||
| -rw-r--r-- | src/term.c | 96 | ||||
| -rw-r--r-- | src/text.c | 184 | ||||
| -rw-r--r-- | src/text.h | 10 | ||||
| -rw-r--r-- | src/text_run.c | 180 | ||||
| -rw-r--r-- | src/text_run.h | 42 |
38 files changed, 1999 insertions, 1999 deletions
@@ -1,33 +1,33 @@ -#ifndef TERM_CELL_H -#define TERM_CELL_H +#ifndef WSAP_VTCORE_CELL_H +#define WSAP_VTCORE_CELL_H /* * The cell layout that the terminal stores. Only src/term uses it. A - * snapshot converts these cells to the public struct term_cell. + * snapshot converts these cells to the public struct wsap_vtcore_cell. */ -#include "term.h" +#include "wsap_vtcore.h" enum cell_flags { - CELL_BOLD = TERM_ATTR_BOLD, - CELL_ITALIC = TERM_ATTR_ITALIC, - CELL_UNDERLINE = TERM_ATTR_UNDERLINE, - CELL_STRIKE = TERM_ATTR_STRIKE, - CELL_OVERLINE = TERM_ATTR_OVERLINE, - CELL_EMOJI = TERM_ATTR_EMOJI, - CELL_TEXT = TERM_ATTR_TEXT, + CELL_BOLD = WSAP_VTCORE_ATTR_BOLD, + CELL_ITALIC = WSAP_VTCORE_ATTR_ITALIC, + CELL_UNDERLINE = WSAP_VTCORE_ATTR_UNDERLINE, + CELL_STRIKE = WSAP_VTCORE_ATTR_STRIKE, + CELL_OVERLINE = WSAP_VTCORE_ATTR_OVERLINE, + CELL_EMOJI = WSAP_VTCORE_ATTR_EMOJI, + CELL_TEXT = WSAP_VTCORE_ATTR_TEXT, CELL_WIDE = 1 << 7, CELL_TRAIL = 1 << 8, CELL_WRAP_PAD = 1 << 9, - CELL_FAINT = TERM_ATTR_FAINT, - CELL_DOUBLE_UNDERLINE = TERM_ATTR_DOUBLE_UNDERLINE, - CELL_CURLY_UNDERLINE = TERM_ATTR_CURLY_UNDERLINE, - CELL_DOTTED_UNDERLINE = TERM_ATTR_DOTTED_UNDERLINE, - CELL_DASHED_UNDERLINE = TERM_ATTR_DASHED_UNDERLINE, - CELL_LINK = TERM_ATTR_LINK, + CELL_FAINT = WSAP_VTCORE_ATTR_FAINT, + CELL_DOUBLE_UNDERLINE = WSAP_VTCORE_ATTR_DOUBLE_UNDERLINE, + CELL_CURLY_UNDERLINE = WSAP_VTCORE_ATTR_CURLY_UNDERLINE, + CELL_DOTTED_UNDERLINE = WSAP_VTCORE_ATTR_DOTTED_UNDERLINE, + CELL_DASHED_UNDERLINE = WSAP_VTCORE_ATTR_DASHED_UNDERLINE, + CELL_LINK = WSAP_VTCORE_ATTR_LINK, }; -#define CELL_ANY_UNDERLINE TERM_ATTR_UNDERLINE_MASK +#define CELL_ANY_UNDERLINE WSAP_VTCORE_ATTR_UNDERLINE_MASK /* c is a code point or a grapheme handle. pad holds the OSC 8 link id. */ struct cell { diff --git a/src/compat.h b/src/compat.h index 6c3302f..0b4559e 100644 --- a/src/compat.h +++ b/src/compat.h @@ -1,10 +1,10 @@ -#ifndef TERM_COMPAT_H -#define TERM_COMPAT_H +#ifndef WSAP_VTCORE_COMPAT_H +#define WSAP_VTCORE_COMPAT_H /* * Compiler and libc differences, kept in one place. GCC and Clang use their * builtins. MSVC uses its intrinsics. Any other compiler, and any build with - * TERM_NO_COMPILER_BUILTINS, uses plain C. Plain C gives the same results, + * WSAP_VTCORE_NO_COMPILER_BUILTINS, uses plain C. Plain C gives the same results, * only slower. */ @@ -28,68 +28,68 @@ #endif #if defined(__GNUC__) || defined(__clang__) -#define TERM_COMPILER_GNU 1 +#define WSAP_VTCORE_COMPILER_GNU 1 #elif defined(_MSC_VER) -#define TERM_COMPILER_MSVC 1 +#define WSAP_VTCORE_COMPILER_MSVC 1 #include <intrin.h> #endif -#if !defined(TERM_NO_COMPILER_BUILTINS) && defined(TERM_COMPILER_GNU) -#define TERM_HAVE_BUILTINS 1 -#elif !defined(TERM_NO_COMPILER_BUILTINS) && defined(TERM_COMPILER_MSVC) -#define TERM_HAVE_MSVC_BITOPS 1 +#if !defined(WSAP_VTCORE_NO_COMPILER_BUILTINS) && defined(WSAP_VTCORE_COMPILER_GNU) +#define WSAP_VTCORE_HAVE_BUILTINS 1 +#elif !defined(WSAP_VTCORE_NO_COMPILER_BUILTINS) && defined(WSAP_VTCORE_COMPILER_MSVC) +#define WSAP_VTCORE_HAVE_MSVC_BITOPS 1 #endif -#if defined(TERM_COMPILER_GNU) -#define TERM_HOT __attribute__((hot)) -#define TERM_NOINLINE __attribute__((noinline)) -#define TERM_ALWAYS_INLINE __attribute__((always_inline)) -#define TERM_MAYBE_UNUSED __attribute__((unused)) -#elif defined(TERM_COMPILER_MSVC) -#define TERM_HOT -#define TERM_NOINLINE __declspec(noinline) -#define TERM_ALWAYS_INLINE __forceinline -#define TERM_MAYBE_UNUSED +#if defined(WSAP_VTCORE_COMPILER_GNU) +#define WSAP_VTCORE_HOT __attribute__((hot)) +#define WSAP_VTCORE_NOINLINE __attribute__((noinline)) +#define WSAP_VTCORE_ALWAYS_INLINE __attribute__((always_inline)) +#define WSAP_VTCORE_MAYBE_UNUSED __attribute__((unused)) +#elif defined(WSAP_VTCORE_COMPILER_MSVC) +#define WSAP_VTCORE_HOT +#define WSAP_VTCORE_NOINLINE __declspec(noinline) +#define WSAP_VTCORE_ALWAYS_INLINE __forceinline +#define WSAP_VTCORE_MAYBE_UNUSED #else -#define TERM_HOT -#define TERM_NOINLINE -#define TERM_ALWAYS_INLINE -#define TERM_MAYBE_UNUSED +#define WSAP_VTCORE_HOT +#define WSAP_VTCORE_NOINLINE +#define WSAP_VTCORE_ALWAYS_INLINE +#define WSAP_VTCORE_MAYBE_UNUSED #endif -#if defined(TERM_HAVE_BUILTINS) -#define TERM_EXPECT(x, v) __builtin_expect((x), (v)) +#if defined(WSAP_VTCORE_HAVE_BUILTINS) +#define WSAP_VTCORE_EXPECT(x, v) __builtin_expect((x), (v)) #else -#define TERM_EXPECT(x, v) (x) +#define WSAP_VTCORE_EXPECT(x, v) (x) #endif -/* term_ctz32(0) is 32, term_clz32(0) is 32, term_ctz64(0) is 64, and - * term_clz64(0) is 64 on every path. */ -#if defined(TERM_HAVE_BUILTINS) +/* wsap_vtcore_ctz32(0) is 32, wsap_vtcore_clz32(0) is 32, wsap_vtcore_ctz64(0) is 64, and + * wsap_vtcore_clz64(0) is 64 on every path. */ +#if defined(WSAP_VTCORE_HAVE_BUILTINS) -static inline int term_ctz32(uint32_t x) { return x ? __builtin_ctz(x) : 32; } -static inline int term_clz32(uint32_t x) { return x ? __builtin_clz(x) : 32; } -static inline int term_popcount32(uint32_t x) { return __builtin_popcount(x); } -static inline int term_ctz64(uint64_t x) { return x ? __builtin_ctzll(x) : 64; } -static inline int term_clz64(uint64_t x) { return x ? __builtin_clzll(x) : 64; } -static inline int term_popcount64(uint64_t x) { return __builtin_popcountll(x); } +static inline int wsap_vtcore_ctz32(uint32_t x) { return x ? __builtin_ctz(x) : 32; } +static inline int wsap_vtcore_clz32(uint32_t x) { return x ? __builtin_clz(x) : 32; } +static inline int wsap_vtcore_popcount32(uint32_t x) { return __builtin_popcount(x); } +static inline int wsap_vtcore_ctz64(uint64_t x) { return x ? __builtin_ctzll(x) : 64; } +static inline int wsap_vtcore_clz64(uint64_t x) { return x ? __builtin_clzll(x) : 64; } +static inline int wsap_vtcore_popcount64(uint64_t x) { return __builtin_popcountll(x); } #else -#if defined(TERM_HAVE_MSVC_BITOPS) -static inline int term_ctz32(uint32_t x) +#if defined(WSAP_VTCORE_HAVE_MSVC_BITOPS) +static inline int wsap_vtcore_ctz32(uint32_t x) { unsigned long i; return _BitScanForward(&i, x) ? (int)i : 32; } -static inline int term_clz32(uint32_t x) +static inline int wsap_vtcore_clz32(uint32_t x) { unsigned long i; return _BitScanReverse(&i, x) ? 31 - (int)i : 32; } -static inline int term_popcount32(uint32_t x) { return (int)__popcnt(x); } +static inline int wsap_vtcore_popcount32(uint32_t x) { return (int)__popcnt(x); } #else -static inline int term_ctz32(uint32_t x) +static inline int wsap_vtcore_ctz32(uint32_t x) { if (!x) return 32; @@ -99,7 +99,7 @@ static inline int term_ctz32(uint32_t x) }; return (int)de_bruijn[((uint32_t)((x & -x) * 0x077CB531U)) >> 27]; } -static inline int term_clz32(uint32_t x) +static inline int wsap_vtcore_clz32(uint32_t x) { if (!x) return 32; @@ -111,7 +111,7 @@ static inline int term_clz32(uint32_t x) if (!(x & 0x80000000u)) { n += 1; } return n; } -static inline int term_popcount32(uint32_t x) +static inline int wsap_vtcore_popcount32(uint32_t x) { x = x - ((x >> 1) & 0x55555555u); x = (x & 0x33333333u) + ((x >> 2) & 0x33333333u); @@ -120,75 +120,75 @@ static inline int term_popcount32(uint32_t x) #endif /* Without builtins, the 64-bit forms are built from the 32-bit ones. */ -static inline int term_ctz64(uint64_t x) +static inline int wsap_vtcore_ctz64(uint64_t x) { uint32_t lo = (uint32_t)x; - return lo ? term_ctz32(lo) : 32 + term_ctz32((uint32_t)(x >> 32)); + return lo ? wsap_vtcore_ctz32(lo) : 32 + wsap_vtcore_ctz32((uint32_t)(x >> 32)); } -static inline int term_clz64(uint64_t x) +static inline int wsap_vtcore_clz64(uint64_t x) { uint32_t hi = (uint32_t)(x >> 32); - return hi ? term_clz32(hi) : 32 + term_clz32((uint32_t)x); + return hi ? wsap_vtcore_clz32(hi) : 32 + wsap_vtcore_clz32((uint32_t)x); } -static inline int term_popcount64(uint64_t x) +static inline int wsap_vtcore_popcount64(uint64_t x) { - return term_popcount32((uint32_t)x) + term_popcount32((uint32_t)(x >> 32)); + return wsap_vtcore_popcount32((uint32_t)x) + wsap_vtcore_popcount32((uint32_t)(x >> 32)); } #endif /* Smallest power of two >= x, branchlessly via CLZ. Returns UINT32_MAX on overflow. */ -static inline uint32_t term_next_pow2_32(uint32_t x) +static inline uint32_t wsap_vtcore_next_pow2_32(uint32_t x) { uint32_t v = x <= 1 ? 1 : x - 1; - int lz = term_clz32(v); + int lz = wsap_vtcore_clz32(v); uint32_t res = UINT32_C(1) << ((32 - lz) & 31); return (x <= 1) ? 1 : (lz == 0 ? UINT32_MAX : res); } /* Smallest power of two >= x, branchlessly via CLZ. Returns UINT64_MAX on overflow. */ -static inline uint64_t term_next_pow2_64(uint64_t x) +static inline uint64_t wsap_vtcore_next_pow2_64(uint64_t x) { uint64_t v = x <= 1 ? 1 : x - 1; - int lz = term_clz64(v); + int lz = wsap_vtcore_clz64(v); uint64_t res = UINT64_C(1) << ((64 - lz) & 63); return (x <= 1) ? 1 : (lz == 0 ? UINT64_MAX : res); } /* Grows cap by doubling until >= need, branchlessly. * If cap >= need, returns cap. Otherwise returns next power of two >= need. */ -static inline uint32_t term_grow_cap32(uint32_t cap, uint32_t need) +static inline uint32_t wsap_vtcore_grow_cap32(uint32_t cap, uint32_t need) { - return cap >= need ? cap : term_next_pow2_32(need); + return cap >= need ? cap : wsap_vtcore_next_pow2_32(need); } -static inline uint64_t term_grow_cap64(uint64_t cap, uint64_t need) +static inline uint64_t wsap_vtcore_grow_cap64(uint64_t cap, uint64_t need) { - return cap >= need ? cap : term_next_pow2_64(need); + return cap >= need ? cap : wsap_vtcore_next_pow2_64(need); } -static inline size_t term_grow_cap(size_t cap, size_t need) +static inline size_t wsap_vtcore_grow_cap(size_t cap, size_t need) { #if SIZE_MAX > UINT32_MAX - return (size_t)term_grow_cap64(cap, need); + return (size_t)wsap_vtcore_grow_cap64(cap, need); #else - return (size_t)term_grow_cap32((uint32_t)cap, (uint32_t)need); + return (size_t)wsap_vtcore_grow_cap32((uint32_t)cap, (uint32_t)need); #endif } /* A spin-wait hint. Compilers without one get a no-op. */ -static inline void term_cpu_relax(void) +static inline void wsap_vtcore_cpu_relax(void) { -#if defined(TERM_COMPILER_GNU) -#if defined(TERM_HAVE_BUILTINS) && defined(__x86_64__) +#if defined(WSAP_VTCORE_COMPILER_GNU) +#if defined(WSAP_VTCORE_HAVE_BUILTINS) && defined(__x86_64__) __builtin_ia32_pause(); #elif defined(__aarch64__) __asm__ __volatile__("yield"); #endif -#elif defined(TERM_COMPILER_MSVC) +#elif defined(WSAP_VTCORE_COMPILER_MSVC) #if defined(_M_X64) || defined(_M_IX86) _mm_pause(); #elif defined(_M_ARM64) @@ -199,11 +199,11 @@ static inline void term_cpu_relax(void) /* The writer lock. POSIX uses a mutex with priority inheritance where the * platform has it, so a waiter lifts the thread that holds the lock. Windows - * uses an SRWLOCK. Neither nests, so term_write_begin() counts re-entry. */ + * uses an SRWLOCK. Neither nests, so wsap_vtcore_write_begin() counts re-entry. */ #if defined(_WIN32) -typedef SRWLOCK term_mutex; +typedef SRWLOCK wsap_vtcore_mutex; #else -typedef pthread_mutex_t term_mutex; +typedef pthread_mutex_t wsap_vtcore_mutex; /* Strict C11 can hide PTHREAD_PRIO_INHERIT in pthread.h, as zig's aarch64 * glibc headers do. Every POSIX system that has the option uses 1 for it. */ #if !defined(PTHREAD_PRIO_INHERIT) @@ -212,7 +212,7 @@ typedef pthread_mutex_t term_mutex; #endif /* Returns false when the lock cannot be made. */ -static inline bool term_mutex_init(term_mutex *m) +static inline bool wsap_vtcore_mutex_init(wsap_vtcore_mutex *m) { #if defined(_WIN32) InitializeSRWLock(m); @@ -231,7 +231,7 @@ static inline bool term_mutex_init(term_mutex *m) } /* A normal mutex fails only when it is broken, so the result is ignored. */ -static inline void term_mutex_lock(term_mutex *m) +static inline void wsap_vtcore_mutex_lock(wsap_vtcore_mutex *m) { #if defined(_WIN32) AcquireSRWLockExclusive(m); @@ -240,7 +240,7 @@ static inline void term_mutex_lock(term_mutex *m) #endif } -static inline void term_mutex_unlock(term_mutex *m) +static inline void wsap_vtcore_mutex_unlock(wsap_vtcore_mutex *m) { #if defined(_WIN32) ReleaseSRWLockExclusive(m); @@ -250,7 +250,7 @@ static inline void term_mutex_unlock(term_mutex *m) } /* An SRWLOCK has no destroy. */ -static inline void term_mutex_destroy(term_mutex *m) +static inline void wsap_vtcore_mutex_destroy(wsap_vtcore_mutex *m) { #if defined(_WIN32) (void)m; @@ -260,7 +260,7 @@ static inline void term_mutex_destroy(term_mutex *m) } /* strdup is POSIX, so the core copies strings itself. */ -static inline char *term_strdup(const char *s) +static inline char *wsap_vtcore_strdup(const char *s) { size_t n = strlen(s) + 1; char *copy = malloc(n); @@ -270,7 +270,7 @@ static inline char *term_strdup(const char *s) } /* ASCII-only prefix test, as strncasecmp() does in the C locale. */ -static inline bool term_has_prefix_ci(const char *s, const char *prefix) +static inline bool wsap_vtcore_has_prefix_ci(const char *s, const char *prefix) { for (; *prefix; prefix++, s++) { unsigned char a = (unsigned char)*s; @@ -285,9 +285,9 @@ static inline bool term_has_prefix_ci(const char *s, const char *prefix) /* Allocates size bytes that start on an align-byte boundary. align must be a * power of two. The raw pointer is stored just before the block, so - * term_aligned_free() can release it. C11 aligned_alloc() and POSIX + * wsap_vtcore_aligned_free() can release it. C11 aligned_alloc() and POSIX * posix_memalign() are not on every toolchain. */ -static inline void *term_aligned_alloc(size_t align, size_t size) +static inline void *wsap_vtcore_aligned_alloc(size_t align, size_t size) { if (size > SIZE_MAX - align - sizeof(void *)) return NULL; @@ -299,7 +299,7 @@ static inline void *term_aligned_alloc(size_t align, size_t size) return (void *)p; } -static inline void term_aligned_free(void *p) +static inline void wsap_vtcore_aligned_free(void *p) { if (p) free(((void **)p)[-1]); @@ -16,13 +16,13 @@ static uint16_t cluster_presentation(const uint32_t *cps, int len) { if (len <= 1) return 0; - bool pictographic = term_unicode_extended_pictographic(cps[0]); + bool pictographic = wsap_vtcore_unicode_extended_pictographic(cps[0]); if (len == 2) { uint32_t c1 = cps[1]; if (c1 == 0xFE0F) return CELL_EMOJI; if (c1 == 0xFE0E) return CELL_TEXT; - if (c1 == 0x20E3 || term_grapheme_regional_indicator(c1) || - (pictographic && (c1 == 0x200D || term_grapheme_emoji_modifier(c1) || + if (c1 == 0x20E3 || wsap_vtcore_grapheme_regional_indicator(c1) || + (pictographic && (c1 == 0x200D || wsap_vtcore_grapheme_emoji_modifier(c1) || (c1 >= 0xE0020 && c1 <= 0xE007F)))) return CELL_EMOJI; return 0; @@ -33,40 +33,40 @@ static uint16_t cluster_presentation(const uint32_t *cps, int len) return CELL_EMOJI; if (cps[i] == 0xFE0E) return CELL_TEXT; - if (cps[i] == 0x20E3 || term_grapheme_regional_indicator(cps[i]) || - (pictographic && (cps[i] == 0x200D || term_grapheme_emoji_modifier(cps[i]) || + if (cps[i] == 0x20E3 || wsap_vtcore_grapheme_regional_indicator(cps[i]) || + (pictographic && (cps[i] == 0x200D || wsap_vtcore_grapheme_emoji_modifier(cps[i]) || (cps[i] >= 0xE0020 && cps[i] <= 0xE007F)))) emoji = true; } return emoji ? CELL_EMOJI : 0; } -void term_sc_print_glyph(struct term *t, uint32_t cp, int width, uint16_t flags) +void wsap_vtcore_sc_print_glyph(struct wsap_vtcore *t, uint32_t cp, int width, uint16_t flags) { uint32_t base = cp; - if (TERM_EXPECT(term_grapheme_is_handle(cp), 0)) { - uint32_t cps[TERM_GRAPHEME_MAX_LEN]; - int len = term_gstore_expand(t->gstore, cp, cps, TERM_GRAPHEME_MAX_LEN); + if (WSAP_VTCORE_EXPECT(wsap_vtcore_grapheme_is_handle(cp), 0)) { + uint32_t cps[WSAP_VTCORE_GRAPHEME_MAX_LEN]; + int len = wsap_vtcore_gstore_expand(t->gstore, cp, cps, WSAP_VTCORE_GRAPHEME_MAX_LEN); base = cps[0]; flags = (flags & ~(CELL_EMOJI | CELL_TEXT)) | cluster_presentation(cps, len); } - if (TERM_EXPECT(width <= 0, 0)) - width = term_text_class(base); + if (WSAP_VTCORE_EXPECT(width <= 0, 0)) + width = wsap_vtcore_text_class(base); if (width == 2 || (flags & CELL_EMOJI)) width = 2; else width = 1; - if (TERM_EXPECT(flags & CELL_TEXT, 0)) + if (WSAP_VTCORE_EXPECT(flags & CELL_TEXT, 0)) width = 1; - if (TERM_EXPECT(width == 1 && !t->pending_wrap && !t->insert_mode && + if (WSAP_VTCORE_EXPECT(width == 1 && !t->pending_wrap && !t->insert_mode && !t->lr_margin_mode && t->cursor_x < t->cols, 1)) { - struct srow *srow = term_row(t, t->cursor_y); + struct srow *srow = wsap_vtcore_row(t, t->cursor_y); int cx = t->cursor_x; int len = srow->len; - if (TERM_EXPECT(srow->kind == ROW_CELLS && cx <= len, 1)) { + if (WSAP_VTCORE_EXPECT(srow->kind == ROW_CELLS && cx <= len, 1)) { struct cell *row = srow->cells; - if (TERM_EXPECT(!((cx < len && (row[cx].flags & CELL_TRAIL)) || + if (WSAP_VTCORE_EXPECT(!((cx < len && (row[cx].flags & CELL_TRAIL)) || (cx + 1 < len && (row[cx + 1].flags & CELL_TRAIL))), 1)) { row[cx] = (struct cell){cp, t->inverse ? t->cur_bg : t->cur_fg, @@ -88,8 +88,8 @@ void term_sc_print_glyph(struct term *t, uint32_t cp, int width, uint16_t flags) } } - if (TERM_EXPECT(t->pending_wrap, 0)) { - row_set_wrapped(term_row(t, t->cursor_y), true); + if (WSAP_VTCORE_EXPECT(t->pending_wrap, 0)) { + row_set_wrapped(wsap_vtcore_row(t, t->cursor_y), true); t->cursor_x = t->lr_margin_mode ? t->left_margin : 0; sc_linefeed(t, 1); t->pending_wrap = false; @@ -102,10 +102,10 @@ void term_sc_print_glyph(struct term *t, uint32_t cp, int width, uint16_t flags) int cols = t->cols; int right = t->lr_margin_mode ? t->right_margin : cols - 1; - if (TERM_EXPECT(width == 2 && cols > 1 && cx == right && t->autowrap, 0)) { - term_row_fill_gap(srow, cx); + if (WSAP_VTCORE_EXPECT(width == 2 && cols > 1 && cx == right && t->autowrap, 0)) { + wsap_vtcore_row_fill_gap(srow, cx); clear_wide_edges(row, cx, right + 1, srow->len); - row[cx] = (struct cell){ ' ', TERM_COLOR_FG, TERM_COLOR_BG, CELL_WRAP_PAD, 0 }; + row[cx] = (struct cell){ ' ', WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG, CELL_WRAP_PAD, 0 }; srow->len = (uint16_t)cols; srow->version++; row_set_wrapped(srow, true); @@ -125,10 +125,10 @@ void term_sc_print_glyph(struct term *t, uint32_t cp, int width, uint16_t flags) } else { flags &= ~CELL_WIDE; } - term_row_fill_gap(srow, cx); - if (TERM_EXPECT(t->insert_mode, 0)) { + wsap_vtcore_row_fill_gap(srow, cx); + if (WSAP_VTCORE_EXPECT(t->insert_mode, 0)) { if (cx == srow->len) - row[cx] = (struct cell){ ' ', TERM_COLOR_FG, TERM_COLOR_BG, 0, 0 }; + row[cx] = (struct cell){ ' ', WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG, 0, 0 }; int move = right + 1 - cx - span; if (move > 0) memmove(&row[cx + span], &row[cx], (size_t)move * sizeof(struct cell)); @@ -155,7 +155,7 @@ void term_sc_print_glyph(struct term *t, uint32_t cp, int width, uint16_t flags) } } -static inline struct cell *last_written_cell(struct term *t) +static inline struct cell *last_written_cell(struct wsap_vtcore *t) { int right = (t->lr_margin_mode && t->cursor_x <= t->right_margin) ? t->right_margin : t->cols - 1; @@ -163,7 +163,7 @@ static inline struct cell *last_written_cell(struct term *t) if (t->lr_margin_mode && x < t->left_margin) return NULL; - struct srow *srow = term_row(t, t->cursor_y); + struct srow *srow = wsap_vtcore_row(t, t->cursor_y); if (x < 0 || x >= srow->len) return NULL; int p = phys_row(t, t->cursor_y); @@ -173,19 +173,19 @@ static inline struct cell *last_written_cell(struct term *t) return &row[x]; } -bool term_sc_extend_cluster(struct term *t, uint32_t cp, int klass) +bool wsap_vtcore_sc_extend_cluster(struct wsap_vtcore *t, uint32_t cp, int klass) { if (!can_extend_cluster(t->last_char, cp, klass)) return false; struct cell *prev = last_written_cell(t); - uint32_t cps[TERM_GRAPHEME_MAX_LEN]; - int len = prev && prev->c > ' ' ? term_gstore_expand(t->gstore, prev->c, cps, TERM_GRAPHEME_MAX_LEN) : 0; + uint32_t cps[WSAP_VTCORE_GRAPHEME_MAX_LEN]; + int len = prev && prev->c > ' ' ? wsap_vtcore_gstore_expand(t->gstore, prev->c, cps, WSAP_VTCORE_GRAPHEME_MAX_LEN) : 0; if (!len) return joins_cluster(cp, klass); if (!cluster_joins(cps, len, cp, klass)) return false; - if (len >= TERM_GRAPHEME_MAX_LEN) + if (len >= WSAP_VTCORE_GRAPHEME_MAX_LEN) return true; cps[len++] = cp; @@ -196,15 +196,15 @@ bool term_sc_extend_cluster(struct term *t, uint32_t cp, int klass) int span = (cell.flags & CELL_WIDE) && x + 1 < t->cols ? 2 : 1; struct srow *srow = &t->scr.slot[p]; if (srow->len == x + span) { - fill_cells(prev, span, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(prev, span, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); srow->len = (uint16_t)x; } else { fill_cells(prev, span, cell.fg, cell.bg); } t->cursor_x = x; t->pending_wrap = false; - t->last_char = term_gstore_intern(t->gstore, cps, len); - term_sc_print_glyph(t, t->last_char, -1, + t->last_char = wsap_vtcore_gstore_intern(t->gstore, cps, len); + wsap_vtcore_sc_print_glyph(t, t->last_char, -1, cell.flags & ~(CELL_WIDE | CELL_EMOJI | CELL_TEXT)); prev = last_written_cell(t); @@ -221,22 +221,22 @@ bool term_sc_extend_cluster(struct term *t, uint32_t cp, int klass) } /* n blank default rows scroll off the top, after the screen rows. */ -static void push_blank_lines(struct term *t, size_t n) +static void push_blank_lines(struct wsap_vtcore *t, size_t n) { if (screen_has_history(t)) { - term_hist_push_blank(&t->hist, n); + wsap_vtcore_hist_push_blank(&t->hist, n); } else { t->scr.top_id += n; t->scr.top_seg = 0; } } -static void scroll_up_bce(struct term *t, size_t count) +static void scroll_up_bce(struct wsap_vtcore *t, size_t count) { size_t rows = (size_t)t->rows; if (t->alternate || count <= rows) { for (size_t i = count < rows ? count : rows; i > 0; i--) - term_screen_scroll_up(t); + wsap_vtcore_screen_scroll_up(t); return; } size_t rem = count - rows; @@ -244,7 +244,7 @@ static void scroll_up_bce(struct term *t, size_t count) /* Rows past the history limit would leave again at once. */ size_t keep = screen_has_history(t) ? t->hist.line_limit : 0; for (size_t i = rows + (rem < keep ? rem : keep); i > 0; i--) - term_screen_scroll_up(t); + wsap_vtcore_screen_scroll_up(t); return; } bool skip = screen_has_history(t) && rem >= t->hist.line_limit; @@ -260,7 +260,7 @@ static void scroll_up_bce(struct term *t, size_t count) push_blank_lines(t, count); } else { for (size_t i = 0; i < rows; i++) - term_screen_scroll_up(t); + wsap_vtcore_screen_scroll_up(t); push_blank_lines(t, rem); } if (t->prompt_y > 0) @@ -269,12 +269,12 @@ static void scroll_up_bce(struct term *t, size_t count) t->full_gen++; } -void term_sc_linefeed_slow(struct term *t, size_t n) +void wsap_vtcore_sc_linefeed_slow(struct wsap_vtcore *t, size_t n) { if (n == 0) return; t->pending_wrap = false; - term_row(t, t->cursor_y)->version++; + wsap_vtcore_row(t, t->cursor_y)->version++; if (t->cursor_y > t->scroll_bottom) { if (t->cursor_y + (int)n < t->rows) @@ -292,23 +292,23 @@ void term_sc_linefeed_slow(struct term *t, size_t n) size_t scroll = (size_t)(t->cursor_y + (int)n - t->scroll_bottom); t->cursor_y = t->scroll_bottom; - if (TERM_EXPECT(t->scroll_top == 0 && t->scroll_bottom == t->rows - 1, 1)) { - if (TERM_EXPECT(scroll == 1, 1)) - term_screen_scroll_up(t); + if (WSAP_VTCORE_EXPECT(t->scroll_top == 0 && t->scroll_bottom == t->rows - 1, 1)) { + if (WSAP_VTCORE_EXPECT(scroll == 1, 1)) + wsap_vtcore_screen_scroll_up(t); else scroll_up_bce(t, scroll); } else if (t->scroll_top > 0 || t->alternate) { int height = t->scroll_bottom - t->scroll_top + 1; if (height <= 0) height = 1; int count = scroll > (size_t)height ? height : (int)scroll; - term_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, count, false, false); + wsap_vtcore_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, count, false, false); } else { int height = t->scroll_bottom - t->scroll_top + 1; if (height <= 0) height = 1; if (scroll <= (size_t)height) { - term_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, (int)scroll, false, true); + wsap_vtcore_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, (int)scroll, false, true); } else { - term_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, height, false, true); + wsap_vtcore_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, height, false, true); size_t rem = scroll - (size_t)height; if (using_default_colors(t)) { push_blank_lines(t, rem); @@ -319,7 +319,7 @@ void term_sc_linefeed_slow(struct term *t, size_t n) rem = cap; while (rem > 0) { int chunk = rem > (size_t)height ? height : (int)rem; - term_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, chunk, false, true); + wsap_vtcore_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, chunk, false, true); rem -= (size_t)chunk; } } @@ -327,7 +327,7 @@ void term_sc_linefeed_slow(struct term *t, size_t n) } } -void term_sc_tab(struct term *t, int n) +void wsap_vtcore_sc_tab(struct wsap_vtcore *t, int n) { int dir = n >= 0 ? 1 : -1; int count = n >= 0 ? n : -n; @@ -341,7 +341,7 @@ void term_sc_tab(struct term *t, int n) t->cursor_x = prev > 0 ? prev : 0; } t->pending_wrap = false; - struct srow *cur = term_row(t, t->cursor_y); + struct srow *cur = wsap_vtcore_row(t, t->cursor_y); if (cur) cur->version++; return; } @@ -352,7 +352,7 @@ void term_sc_tab(struct term *t, int n) t->cursor_x = x < 0 ? 0 : x >= t->cols ? t->cols - 1 : x; } t->pending_wrap = false; - struct srow *cur = term_row(t, t->cursor_y); + struct srow *cur = wsap_vtcore_row(t, t->cursor_y); if (cur) cur->version++; } @@ -361,8 +361,8 @@ void term_sc_tab(struct term *t, int n) static inline void sgr_cell_reset(struct cell *cell) { - cell->fg = TERM_COLOR_FG; - cell->bg = TERM_COLOR_BG; + cell->fg = WSAP_VTCORE_COLOR_FG; + cell->bg = WSAP_VTCORE_COLOR_BG; cell->flags &= (uint16_t)~CELL_SGR_FLAGS; } @@ -370,7 +370,7 @@ static inline void sgr_cell_underline(struct cell *cell, int style) { if (style < 0 || style > 5) style = 1; cell->flags = (uint16_t)((cell->flags & ~CELL_ANY_UNDERLINE) | - term_ul_flags[style]); + wsap_vtcore_ul_flags[style]); } static void apply_sgr_to_cell(struct cell *cell, const struct csi *csi, int first) @@ -406,42 +406,42 @@ static void apply_sgr_to_cell(struct cell *cell, const struct csi *csi, int firs i += sgr_extended_color(csi->params, csi->nparams, csi->subparams, i, &color, &ok); if (ok) cell->fg = color; break; - case 39: cell->fg = TERM_COLOR_FG; break; + case 39: cell->fg = WSAP_VTCORE_COLOR_FG; break; case 48: i += sgr_extended_color(csi->params, csi->nparams, csi->subparams, i, &color, &ok); if (ok) cell->bg = color; break; - case 49: cell->bg = TERM_COLOR_BG; break; + case 49: cell->bg = WSAP_VTCORE_COLOR_BG; break; case 53: cell->flags |= CELL_OVERLINE; break; case 55: cell->flags &= (uint16_t)~CELL_OVERLINE; break; case 58: i += sgr_extended_color(csi->params, csi->nparams, csi->subparams, i, &color, &ok); break; default: - if ((unsigned)(v - 30) < 8) cell->fg = term_color_index(v - 30); - else if ((unsigned)(v - 40) < 8) cell->bg = term_color_index(v - 40); - else if ((unsigned)(v - 90) < 8) cell->fg = term_color_index(v - 90 + 8); - else if ((unsigned)(v - 100) < 8) cell->bg = term_color_index(v - 100 + 8); + if ((unsigned)(v - 30) < 8) cell->fg = wsap_vtcore_color_index(v - 30); + else if ((unsigned)(v - 40) < 8) cell->bg = wsap_vtcore_color_index(v - 40); + else if ((unsigned)(v - 90) < 8) cell->fg = wsap_vtcore_color_index(v - 90 + 8); + else if ((unsigned)(v - 100) < 8) cell->bg = wsap_vtcore_color_index(v - 100 + 8); break; } } } -static void deccara_row(struct term *t, int y, int x0, int x1, const struct csi *csi) +static void deccara_row(struct wsap_vtcore *t, int y, int x0, int x1, const struct csi *csi) { int p = phys_row(t, y); struct cell *row = row_cells(t, p); - struct srow *srow = term_row(t, y); + struct srow *srow = wsap_vtcore_row(t, y); int len = srow->len; if (x0 > 0 && x0 < len && (row[x0].flags & CELL_TRAIL)) x0--; if (x1 + 1 < t->cols && x1 < len && (row[x1].flags & CELL_WIDE)) x1++; - term_row_fill_gap(srow, x1 + 1); + wsap_vtcore_row_fill_gap(srow, x1 + 1); for (int x = x0; x <= x1; x++) apply_sgr_to_cell(&row[x], csi, 4); srow->version++; } -void term_sc_deccara(struct term *t, const struct csi *csi) +void wsap_vtcore_sc_deccara(struct wsap_vtcore *t, const struct csi *csi) { int top = csi->params[0] > 0 ? csi->params[0] - 1 : 0; int left = csi->nparams > 1 && csi->params[1] > 0 ? csi->params[1] - 1 : 0; @@ -462,9 +462,9 @@ void term_sc_deccara(struct term *t, const struct csi *csi) } } -void term_sc_decaln(struct term *t) +void wsap_vtcore_sc_decaln(struct wsap_vtcore *t) { - struct cell fill = { .c = 'E', .fg = TERM_COLOR_FG, .bg = TERM_COLOR_BG }; + struct cell fill = { .c = 'E', .fg = WSAP_VTCORE_COLOR_FG, .bg = WSAP_VTCORE_COLOR_BG }; struct cell *row0 = NULL; for (int y = 0; y < t->rows; y++) { int p = phys_row(t, y); @@ -484,45 +484,45 @@ void term_sc_decaln(struct term *t) sc_move(t, 0, 0); } -void term_sc_reset(struct term *t) +void wsap_vtcore_sc_reset(struct wsap_vtcore *t) { t->cursor_x = t->cursor_y = 0; - t->saved = term_saved_cursor_initial(); + t->saved = wsap_vtcore_saved_cursor_initial(); t->prompt_y = -1; t->has_prompt = false; t->graphics = t->pending_wrap = false; t->last_char = 0; t->charsets[0] = t->charsets[1] = 'B'; t->charset_active = 0; - term_tabs_clear(t); - term_tabs_default(t); - term_screen_erase_all(t); + wsap_vtcore_tabs_clear(t); + wsap_vtcore_tabs_default(t); + wsap_vtcore_screen_erase_all(t); t->full_gen++; } -void term_sc_set_cursor_style(struct term *t, int ps) +void wsap_vtcore_sc_set_cursor_style(struct wsap_vtcore *t, int ps) { if (ps == 0) { t->cursor_style = t->default_cursor_style; t->cursor_blink = t->default_cursor_blink; } else if (ps >= 1 && ps <= 6) { - t->cursor_style = ps < 3 ? TERM_CURSOR_BLOCK - : ps < 5 ? TERM_CURSOR_UNDERLINE : TERM_CURSOR_BAR; + t->cursor_style = ps < 3 ? WSAP_VTCORE_CURSOR_BLOCK + : ps < 5 ? WSAP_VTCORE_CURSOR_UNDERLINE : WSAP_VTCORE_CURSOR_BAR; t->cursor_blink = (ps & 1); } - term_row(t, t->cursor_y)->version++; + wsap_vtcore_row(t, t->cursor_y)->version++; } static inline bool next_byte_wraps(const char *buf, size_t len, size_t pos, uint32_t last) { if (pos >= len) return false; uint32_t cp; - if (!term_utf8_decode_one(buf + pos, len - pos, &cp)) return false; - int w = term_text_class(cp); + if (!wsap_vtcore_utf8_decode_one(buf + pos, len - pos, &cp)) return false; + int w = wsap_vtcore_text_class(cp); return w > 0 && !can_extend_cluster(last, cp, w); } -static void flush_orig_rows(struct term *t, struct screen *s, +static void flush_orig_rows(struct wsap_vtcore *t, struct screen *s, int *orig_y, int *orig_rem, int count) { int y = *orig_y; @@ -556,8 +556,8 @@ static void flush_orig_rows(struct term *t, struct screen *s, } } if (lines) { - term_hist_push_ascii_lf(&t->hist, (const char *)base, ends, lines); - if (t->view.anchor.active) term_hist_view_note_push(&t->view, &t->hist, t->cols); + wsap_vtcore_hist_push_ascii_lf(&t->hist, (const char *)base, ends, lines); + if (t->view.anchor.active) wsap_vtcore_hist_view_note_push(&t->view, &t->hist, t->cols); y = closed; continue; } @@ -578,15 +578,15 @@ static void flush_orig_rows(struct term *t, struct screen *s, }; } if (n) { - term_hist_push_ascii_lines(&t->hist, q, n, NULL); - if (t->view.anchor.active) term_hist_view_note_push(&t->view, &t->hist, t->cols); + wsap_vtcore_hist_push_ascii_lines(&t->hist, q, n, NULL); + if (t->view.anchor.active) wsap_vtcore_hist_view_note_push(&t->view, &t->hist, t->cols); y += n; - } else term_screen_push_row(t, screen_get_row(s, y++)); + } else wsap_vtcore_screen_push_row(t, screen_get_row(s, y++)); } } struct stream_emit_ctx { - struct term *term; + struct wsap_vtcore *term; struct screen *screen; struct hist_ascii_line *q; const struct pen_attr *attr; @@ -603,7 +603,7 @@ static void flush_stream_queue(struct stream_emit_ctx *ctx) if (ctx->orig_rem > 0) flush_orig_rows(ctx->term, ctx->screen, &ctx->orig_y, &ctx->orig_rem, ctx->orig_rem); int flush_n = ctx->q_count - ctx->q_cap; - term_hist_push_ascii_lines(&ctx->term->hist, ctx->q, flush_n, ctx->attr); + wsap_vtcore_hist_push_ascii_lines(&ctx->term->hist, ctx->q, flush_n, ctx->attr); if (ctx->q_cap > 0) { if (flush_n >= ctx->q_cap) memcpy(ctx->q, ctx->q + flush_n, (size_t)ctx->q_cap * sizeof(ctx->q[0])); @@ -617,14 +617,14 @@ static void flush_stream_queue(struct stream_emit_ctx *ctx) static inline void emit_stream_bulk_wrapped(struct stream_emit_ctx *ctx, const char *src, int bulk_lines) { - struct term *t = ctx->term; + struct wsap_vtcore *t = ctx->term; struct screen *s = ctx->screen; int cols = ctx->cols; - if (TERM_EXPECT(t->pending_wrap, 0)) { + if (WSAP_VTCORE_EXPECT(t->pending_wrap, 0)) { row_set_wrapped(screen_get_row(s, s->rows - 1), true); t->pending_wrap = false; t->cursor_x = 0; - term_screen_scroll_up(t); + wsap_vtcore_screen_scroll_up(t); } if (bulk_lines < ctx->q_cap) { const char *p = src; @@ -640,13 +640,13 @@ static inline void emit_stream_bulk_wrapped(struct stream_emit_ctx *ctx, if (ctx->orig_rem > 0) flush_orig_rows(t, s, &ctx->orig_y, &ctx->orig_rem, ctx->orig_rem); if (ctx->q_count > 0) { - term_hist_push_ascii_lines(&t->hist, ctx->q, ctx->q_count, ctx->attr); + wsap_vtcore_hist_push_ascii_lines(&t->hist, ctx->q, ctx->q_count, ctx->attr); ctx->flushed_scrolled += (size_t)ctx->q_count; ctx->q_count = 0; } int hist_rows = bulk_lines - ctx->q_cap; if (hist_rows > 0) { - term_hist_push_ascii(&t->hist, src, hist_rows * cols, ctx->attr, true); + wsap_vtcore_hist_push_ascii(&t->hist, src, hist_rows * cols, ctx->attr, true); ctx->flushed_scrolled += (size_t)hist_rows; } const char *sp = src + (size_t)hist_rows * (size_t)cols; @@ -655,31 +655,31 @@ static inline void emit_stream_bulk_wrapped(struct stream_emit_ctx *ctx, ctx->q_count = ctx->q_cap; } -static inline TERM_ALWAYS_INLINE void emit_stream_row_fast(struct stream_emit_ctx *ctx, +static inline WSAP_VTCORE_ALWAYS_INLINE void emit_stream_row_fast(struct stream_emit_ctx *ctx, const char *row_ptr, int row_len, bool row_wrapped) { - if (TERM_EXPECT(ctx->q_count == 256, 0)) + if (WSAP_VTCORE_EXPECT(ctx->q_count == 256, 0)) flush_stream_queue(ctx); ctx->q[ctx->q_count++] = (struct hist_ascii_line){ row_ptr, (uint16_t)row_len, (uint8_t)row_wrapped }; } -static inline TERM_ALWAYS_INLINE void emit_stream_row(struct stream_emit_ctx *ctx, +static inline WSAP_VTCORE_ALWAYS_INLINE void emit_stream_row(struct stream_emit_ctx *ctx, const char *row_ptr, int row_len, bool row_wrapped) { - if (TERM_EXPECT(ctx->term->pending_wrap, 0)) { + if (WSAP_VTCORE_EXPECT(ctx->term->pending_wrap, 0)) { row_set_wrapped(screen_get_row(ctx->screen, ctx->screen->rows - 1), true); ctx->term->pending_wrap = false; ctx->term->cursor_x = 0; - term_screen_scroll_up(ctx->term); + wsap_vtcore_screen_scroll_up(ctx->term); } emit_stream_row_fast(ctx, row_ptr, row_len, row_wrapped); } -static TERM_NOINLINE size_t stream_ascii_wrapped(struct term *t, const char *buf, size_t len) +static WSAP_VTCORE_NOINLINE size_t stream_ascii_wrapped(struct wsap_vtcore *t, const char *buf, size_t len) { int limit = len > INT32_MAX ? INT32_MAX : (int)len; int run = scan_ascii_run(buf, limit); @@ -700,7 +700,7 @@ static TERM_NOINLINE size_t stream_ascii_wrapped(struct term *t, const char *buf int orig_y = 0, orig_rem = old_rows; flush_orig_rows(t, s, &orig_y, &orig_rem, old_count); int extra = count - (keep - orig_rem); - if (extra) term_hist_push_ascii(&t->hist, buf, extra * cols, NULL, true); + if (extra) wsap_vtcore_hist_push_ascii(&t->hist, buf, extra * cols, NULL, true); s->top = (s->top + scrolls % rows) % rows; const char *src = buf + extra * cols; uint8_t *copy_dst = NULL; @@ -740,10 +740,10 @@ static TERM_NOINLINE size_t stream_ascii_wrapped(struct term *t, const char *buf return (size_t)count * cols; } -#if defined(TERM_KERNEL_AVX512) +#if defined(WSAP_VTCORE_KERNEL_AVX512) /* Cut *count at the first line longer than half a history page. Check * whole blocks of 32 lines. Return the line where the check stopped. */ -TERM_TARGET_AVX512 +WSAP_VTCORE_TARGET_AVX512 static int long_lines_avx512(const uint16_t *ends, int *count) { int j = 0; @@ -753,7 +753,7 @@ static int long_lines_avx512(const uint16_t *ends, int *count) uint32_t bad = _mm512_cmpgt_epu16_mask(_mm512_sub_epi16(end, start), _mm512_set1_epi16(HIST_PAGE_USABLE / 2)); if (bad) { - *count = j + term_ctz32(bad); + *count = j + wsap_vtcore_ctz32(bad); break; } } @@ -761,7 +761,7 @@ static int long_lines_avx512(const uint16_t *ends, int *count) } #endif -static TERM_NOINLINE size_t stream_ascii_lf(struct term *t, const char *buf, size_t len) +static WSAP_VTCORE_NOINLINE size_t stream_ascii_lf(struct wsap_vtcore *t, const char *buf, size_t len) { int limit = len < UINT16_MAX ? (int)len : UINT16_MAX; size_t need = ((size_t)limit + 65) * sizeof(uint16_t); @@ -774,8 +774,8 @@ static TERM_NOINLINE size_t stream_ascii_lf(struct term *t, const char *buf, siz uint16_t *ends = t->ascii_ends.data; int count = scan_ascii_lf(buf, limit, ends); int j = 0; -#if defined(TERM_KERNEL_AVX512) - if (term_use_avx512()) +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (wsap_vtcore_use_avx512()) j = long_lines_avx512(ends, &count); #endif for (; j < count; j++) { @@ -809,9 +809,9 @@ static TERM_NOINLINE size_t stream_ascii_lf(struct term *t, const char *buf, siz t->ascii_tail.cap = tail_bytes; } memcpy(tail_data, buf + source_start, tail_bytes); - term_hist_push_ascii_lf(&t->hist, buf, ends, first); + wsap_vtcore_hist_push_ascii_lf(&t->hist, buf, ends, first); if (skip) - term_hist_push_ascii(&t->hist, buf + ends[first], skip, NULL, true); + wsap_vtcore_hist_push_ascii(&t->hist, buf + ends[first], skip, NULL, true); uint32_t last = t->last_char; for (int j = count; j > 0; j--) { if (ends[j] - ends[j - 1] > 1) { @@ -851,8 +851,8 @@ static TERM_NOINLINE size_t stream_ascii_lf(struct term *t, const char *buf, siz /* Bit i of the result is set when buf[i] is not printable ASCII. *nl gets * the line feeds. Both cover 64 bytes. */ -#if defined(TERM_KERNEL_AVX512) -TERM_TARGET_AVX512 +#if defined(WSAP_VTCORE_KERNEL_AVX512) +WSAP_VTCORE_TARGET_AVX512 static inline uint64_t line_masks_avx512(const char *buf, uint64_t *nl) { __m512i v = _mm512_loadu_si512((const void *)buf); @@ -862,8 +862,8 @@ static inline uint64_t line_masks_avx512(const char *buf, uint64_t *nl) } #endif -#if defined(TERM_KERNEL_AVX2) -TERM_TARGET_AVX2 +#if defined(WSAP_VTCORE_KERNEL_AVX2) +WSAP_VTCORE_TARGET_AVX2 static inline uint64_t line_masks_avx2(const char *buf, uint64_t *nl) { uint64_t lf = 0, controls = 0; @@ -883,16 +883,16 @@ static inline uint64_t line_masks_avx2(const char *buf, uint64_t *nl) static inline uint64_t line_masks(const char *buf, uint64_t *nl) { -#if defined(TERM_KERNEL_AVX2) - if (term_use_avx2()) +#if defined(WSAP_VTCORE_KERNEL_AVX2) + if (wsap_vtcore_use_avx2()) return line_masks_avx2(buf, nl); #endif uint64_t lf = 0, controls = 0; #if defined(__aarch64__) for (int b = 0; b < 64; b += 16) { uint8x16_t v = vld1q_u8((const uint8_t *)buf + b); - lf |= (uint64_t)term_lane_bits(vceqq_u8(v, vdupq_n_u8('\n'))) << b; - controls |= (uint64_t)term_lane_bits(vcgeq_u8( + lf |= (uint64_t)wsap_vtcore_lane_bits(vceqq_u8(v, vdupq_n_u8('\n'))) << b; + controls |= (uint64_t)wsap_vtcore_lane_bits(vcgeq_u8( vsubq_u8(v, vdupq_n_u8(0x20)), vdupq_n_u8(0x7f - 0x20))) << b; } #else @@ -916,7 +916,7 @@ static void stream_queue_finish(struct stream_emit_ctx *ctx) if (loop_scrolled == 0) return; - struct term *t = ctx->term; + struct wsap_vtcore *t = ctx->term; struct screen *s = ctx->screen; int rows = s->rows; @@ -936,7 +936,7 @@ static void stream_queue_finish(struct stream_emit_ctx *ctx) int flush_n = k; if (flush_n > 0) { - term_hist_push_ascii_lines(&t->hist, ctx->q, flush_n, ctx->attr); + wsap_vtcore_hist_push_ascii_lines(&t->hist, ctx->q, flush_n, ctx->attr); } int skip_rows = tail_rows - needed; @@ -944,7 +944,7 @@ static void stream_queue_finish(struct stream_emit_ctx *ctx) struct hist_ascii_line pr = ctx->q[k]; int skip_bytes = skip_rows * cols; if (skip_bytes > (int)pr.len) skip_bytes = (int)pr.len; - term_hist_push_ascii(&t->hist, pr.ptr, skip_bytes, ctx->attr, true); + wsap_vtcore_hist_push_ascii(&t->hist, pr.ptr, skip_bytes, ctx->attr, true); } if (ctx->orig_rem == 0) { @@ -1042,20 +1042,20 @@ static void stream_queue_finish(struct stream_emit_ctx *ctx) /* One body for every level. isa is a constant in each copy below, so each * copy keeps only its own kernels. */ -static inline TERM_ALWAYS_INLINE size_t bulk_ascii_lines_body(struct term *t, const char *buf, +static inline WSAP_VTCORE_ALWAYS_INLINE size_t bulk_ascii_lines_body(struct wsap_vtcore *t, const char *buf, size_t len, int isa) { (void)isa; struct screen *s = &t->scr; int rows = s->rows; - if (TERM_EXPECT(rows > 256, 0)) + if (WSAP_VTCORE_EXPECT(rows > 256, 0)) return 0; size_t i = 0; int cols = t->cols; - uint32_t flags = term_flags_pad(t); + uint32_t flags = wsap_vtcore_flags_pad(t); bool autowrap = t->autowrap; - bool lnm = term_lnm(t); + bool lnm = wsap_vtcore_lnm(t); int last_char = (int)t->last_char; struct pen_attr attr = { @@ -1088,8 +1088,8 @@ static inline TERM_ALWAYS_INLINE size_t bulk_ascii_lines_body(struct term *t, co size_t scan = i; while (scan + 64 <= len) { uint64_t nl, controls; -#if defined(TERM_KERNEL_AVX512) - if (isa == TERM_ISA_AVX512) +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (isa == WSAP_VTCORE_ISA_AVX512) controls = line_masks_avx512(buf + scan, &nl); else #endif @@ -1097,7 +1097,7 @@ static inline TERM_ALWAYS_INLINE size_t bulk_ascii_lines_body(struct term *t, co if (controls != nl) break; while (nl) { - size_t end = scan + (size_t)term_ctz64(nl); + size_t end = scan + (size_t)wsap_vtcore_ctz64(nl); if (!autowrap && end - i > (size_t)cols) goto narrow_done; if (end > i) @@ -1116,8 +1116,8 @@ static inline TERM_ALWAYS_INLINE size_t bulk_ascii_lines_body(struct term *t, co narrow_done: if (i >= len) break; -#if defined(TERM_KERNEL_AVX512) - if (isa == TERM_ISA_AVX512 && TERM_EXPECT(!lnm && !t->pending_wrap, 1)) { +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (isa == WSAP_VTCORE_ISA_AVX512 && WSAP_VTCORE_EXPECT(!lnm && !t->pending_wrap, 1)) { while (i + 64 <= len) { uint64_t nl; uint64_t mask = line_masks_avx512(buf + i, &nl); @@ -1165,7 +1165,7 @@ narrow_done: for (int line = 0; line < 3 && consumed < 64; line++) { uint64_t rest = mask >> consumed; if (!rest) break; - int run = term_ctz64(rest); + int run = wsap_vtcore_ctz64(rest); if (run > cols) break; int pos = consumed + run; int eol = buf[i + pos] == '\n' && lnm ? 1 : @@ -1189,13 +1189,13 @@ narrow_done: int limit = len - i > (size_t)cols ? cols : (int)(len - i); int run = scan_ascii_run(buf + i, limit); int eol = 0; - if (TERM_EXPECT(i + run + 1 < len && buf[i + run] == '\r' && buf[i + run + 1] == '\n', 1)) { + if (WSAP_VTCORE_EXPECT(i + run + 1 < len && buf[i + run] == '\r' && buf[i + run + 1] == '\n', 1)) { eol = 2; } else if (i + run < len && buf[i + run] == '\n' && lnm) { eol = 1; } - if (TERM_EXPECT(eol > 0, 1)) { + if (WSAP_VTCORE_EXPECT(eol > 0, 1)) { if (run > 0) last_char = (unsigned char)buf[i + run - 1]; emit_stream_row(&ctx, buf + i, run, false); @@ -1228,7 +1228,7 @@ narrow_done: emit_stream_row(&ctx, buf + i, run, true); i += (size_t)run; } -#if defined(TERM_KERNEL_AVX512) +#if defined(WSAP_VTCORE_KERNEL_AVX512) done: #endif if (i == 0) @@ -1244,30 +1244,30 @@ done: return i; } -#if defined(TERM_KERNEL_AVX512) -TERM_TARGET_AVX512 -static TERM_NOINLINE size_t bulk_ascii_lines_avx512(struct term *t, const char *buf, size_t len) +#if defined(WSAP_VTCORE_KERNEL_AVX512) +WSAP_VTCORE_TARGET_AVX512 +static WSAP_VTCORE_NOINLINE size_t bulk_ascii_lines_avx512(struct wsap_vtcore *t, const char *buf, size_t len) { - return bulk_ascii_lines_body(t, buf, len, TERM_ISA_AVX512); + return bulk_ascii_lines_body(t, buf, len, WSAP_VTCORE_ISA_AVX512); } #endif -static TERM_NOINLINE size_t bulk_ascii_lines_base(struct term *t, const char *buf, size_t len) +static WSAP_VTCORE_NOINLINE size_t bulk_ascii_lines_base(struct wsap_vtcore *t, const char *buf, size_t len) { - return bulk_ascii_lines_body(t, buf, len, TERM_ISA_BASE); + return bulk_ascii_lines_body(t, buf, len, WSAP_VTCORE_ISA_BASE); } -size_t term_sc_bulk_ascii_lines(struct term *t, const char *buf, size_t len) +size_t wsap_vtcore_sc_bulk_ascii_lines(struct wsap_vtcore *t, const char *buf, size_t len) { - if (TERM_EXPECT(t->scr.rows > 256, 0)) return 0; - if (len >= 1024 && t->autowrap && using_default_colors(t) && !term_flags_pad(t)) { + if (WSAP_VTCORE_EXPECT(t->scr.rows > 256, 0)) return 0; + if (len >= 1024 && t->autowrap && using_default_colors(t) && !wsap_vtcore_flags_pad(t)) { size_t done = 0; - if (!term_lnm(t)) done = stream_ascii_wrapped(t, buf, len); + if (!wsap_vtcore_lnm(t)) done = stream_ascii_wrapped(t, buf, len); else if (!t->pending_wrap) done = stream_ascii_lf(t, buf, len); if (done) return done; } -#if defined(TERM_KERNEL_AVX512) - if (term_use_avx512()) +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (wsap_vtcore_use_avx512()) return bulk_ascii_lines_avx512(t, buf, len); #endif return bulk_ascii_lines_base(t, buf, len); @@ -18,28 +18,28 @@ struct span { }; /* Begin writing a span of cells. Settle cursor row, repair left edge. */ -static inline struct span sc_span_begin(struct term *t, int want); +static inline struct span sc_span_begin(struct wsap_vtcore *t, int want); /* Finish writing a span of cells. Repair right edge, raise len, bump gen. */ -static inline void sc_span_end(struct term *t, struct span *s, int cols, +static inline void sc_span_end(struct wsap_vtcore *t, struct span *s, int cols, uint8_t row_flags, uint32_t last); /* Print ASCII characters through span and SIMD chunking. */ -static inline void sc_print_ascii(struct term *t, const char *s, int n); +static inline void sc_print_ascii(struct wsap_vtcore *t, const char *s, int n); /* Print one glyph (single codepoint or cluster handle). */ -void term_sc_print_glyph(struct term *t, uint32_t cp, int width, uint16_t flags); +void wsap_vtcore_sc_print_glyph(struct wsap_vtcore *t, uint32_t cp, int width, uint16_t flags); -static inline void sc_print_cell(struct term *t, uint32_t cp, int width, uint16_t flags) +static inline void sc_print_cell(struct wsap_vtcore *t, uint32_t cp, int width, uint16_t flags) { - if (TERM_EXPECT(width == 1 && !t->pending_wrap && !t->insert_mode && + if (WSAP_VTCORE_EXPECT(width == 1 && !t->pending_wrap && !t->insert_mode && !t->lr_margin_mode && t->cursor_x < t->cols, 1)) { - struct srow *srow = term_row(t, t->cursor_y); + struct srow *srow = wsap_vtcore_row(t, t->cursor_y); int cx = t->cursor_x; int len = srow->len; - if (TERM_EXPECT(srow->kind == ROW_CELLS && cx <= len, 1)) { + if (WSAP_VTCORE_EXPECT(srow->kind == ROW_CELLS && cx <= len, 1)) { struct cell *row = srow->cells; - if (TERM_EXPECT(!((cx < len && (row[cx].flags & CELL_TRAIL)) || + if (WSAP_VTCORE_EXPECT(!((cx < len && (row[cx].flags & CELL_TRAIL)) || (cx + 1 < len && (row[cx + 1].flags & CELL_TRAIL))), 1)) { row[cx] = (struct cell){cp, t->inverse ? t->cur_bg : t->cur_fg, @@ -60,43 +60,43 @@ static inline void sc_print_cell(struct term *t, uint32_t cp, int width, uint16_ } } } - term_sc_print_glyph(t, cp, width, flags); + wsap_vtcore_sc_print_glyph(t, cp, width, flags); } /* Extend the last printed glyph into a grapheme cluster. */ -bool term_sc_extend_cluster(struct term *t, uint32_t cp, int klass); +bool wsap_vtcore_sc_extend_cluster(struct wsap_vtcore *t, uint32_t cp, int klass); /* Multi-line or region-constrained line feed helper. */ -void term_sc_linefeed_slow(struct term *t, size_t n); +void wsap_vtcore_sc_linefeed_slow(struct wsap_vtcore *t, size_t n); /* Line feed: move down or scroll with BCE. */ -static inline void sc_linefeed(struct term *t, size_t n) +static inline void sc_linefeed(struct wsap_vtcore *t, size_t n) { - if (TERM_EXPECT(n == 1 && t->scroll_top == 0 && + if (WSAP_VTCORE_EXPECT(n == 1 && t->scroll_top == 0 && t->scroll_bottom == t->rows - 1, 1)) { t->pending_wrap = false; - term_row(t, t->cursor_y)->version++; - if (TERM_EXPECT(t->cursor_y == t->rows - 1, 1)) - term_screen_scroll_up(t); + wsap_vtcore_row(t, t->cursor_y)->version++; + if (WSAP_VTCORE_EXPECT(t->cursor_y == t->rows - 1, 1)) + wsap_vtcore_screen_scroll_up(t); else t->cursor_y++; return; } - term_sc_linefeed_slow(t, n); + wsap_vtcore_sc_linefeed_slow(t, n); } /* Carriage return: move cursor to left margin. */ -static inline void sc_cr(struct term *t) +static inline void sc_cr(struct wsap_vtcore *t) { t->pending_wrap = false; if (t->cursor_x != 0) { t->cursor_x = 0; - term_row(t, t->cursor_y)->version++; + wsap_vtcore_row(t, t->cursor_y)->version++; } } /* Move cursor to (x, y), margin-aware. */ -static inline void sc_move(struct term *t, int x, int y) +static inline void sc_move(struct wsap_vtcore *t, int x, int y) { t->pending_wrap = false; if (x < 0) x = 0; @@ -109,16 +109,16 @@ static inline void sc_move(struct term *t, int x, int y) return; t->cursor_x = x; t->cursor_y = y; - term_row(t, old_y)->version++; + wsap_vtcore_row(t, old_y)->version++; if (y != old_y) - term_row(t, y)->version++; + wsap_vtcore_row(t, y)->version++; } /* Advance cursor by n tab stops. */ -void term_sc_tab(struct term *t, int n); +void wsap_vtcore_sc_tab(struct wsap_vtcore *t, int n); /* Erase cells in span [from, to) on physical row y. */ -static inline void sc_erase_span(struct term *t, int y, int from, int to) +static inline void sc_erase_span(struct wsap_vtcore *t, int y, int from, int to) { t->pending_wrap = false; if (to > t->cols) to = t->cols; @@ -128,50 +128,50 @@ static inline void sc_erase_span(struct term *t, int y, int from, int to) } /* Restore saved cursor state and position. */ -static inline void sc_restore_cursor(struct term *t, const struct term_saved_cursor *s) +static inline void sc_restore_cursor(struct wsap_vtcore *t, const struct wsap_vtcore_saved_cursor *s) { - term_cursor_apply(t, s); + wsap_vtcore_cursor_apply(t, s); sc_move(t, s->x, s->y); t->pending_wrap = s->pending_wrap; } /* Change attributes in a rectangular or stream area (DECCARA). */ -void term_sc_deccara(struct term *t, const struct csi *csi); +void wsap_vtcore_sc_deccara(struct wsap_vtcore *t, const struct csi *csi); /* Screen alignment pattern (DECALN). */ -void term_sc_decaln(struct term *t); +void wsap_vtcore_sc_decaln(struct wsap_vtcore *t); /* Reset screen and cursor state for full reset (RIS). */ -void term_sc_reset(struct term *t); +void wsap_vtcore_sc_reset(struct wsap_vtcore *t); /* Set cursor style (DECSCUSR). */ -void term_sc_set_cursor_style(struct term *t, int ps); +void wsap_vtcore_sc_set_cursor_style(struct wsap_vtcore *t, int ps); /* Bulk streaming of ASCII lines with raw rows and skip-ahead. */ -size_t term_sc_bulk_ascii_lines(struct term *t, const char *buf, size_t len); +size_t wsap_vtcore_sc_bulk_ascii_lines(struct wsap_vtcore *t, const char *buf, size_t len); /* Fast CSI parser. */ -int term_try_fast_csi(struct term *t, const char *buf, size_t rem); +int wsap_vtcore_try_fast_csi(struct wsap_vtcore *t, const char *buf, size_t rem); -static inline struct span sc_span_begin(struct term *t, int want) +static inline struct span sc_span_begin(struct wsap_vtcore *t, int want) { (void)want; - if (TERM_EXPECT(t->pending_wrap, 0)) { - row_set_wrapped(term_row(t, t->cursor_y), true); + if (WSAP_VTCORE_EXPECT(t->pending_wrap, 0)) { + row_set_wrapped(wsap_vtcore_row(t, t->cursor_y), true); t->cursor_x = t->lr_margin_mode ? t->left_margin : 0; sc_linefeed(t, 1); t->pending_wrap = false; } - struct srow *row = term_row(t, t->cursor_y); - if (TERM_EXPECT(row->kind != ROW_CELLS, 0)) + struct srow *row = wsap_vtcore_row(t, t->cursor_y); + if (WSAP_VTCORE_EXPECT(row->kind != ROW_CELLS, 0)) srow_settle(row, t->cols); int cx = t->cursor_x; - term_row_fill_gap(row, cx); + wsap_vtcore_row_fill_gap(row, cx); int len = row->len; - if (TERM_EXPECT(cx < len && (row->cells[cx].flags & CELL_TRAIL), 0)) + if (WSAP_VTCORE_EXPECT(cx < len && (row->cells[cx].flags & CELL_TRAIL), 0)) fill_cells(row->cells + cx - 1, 1, row->cells[cx - 1].fg, row->cells[cx - 1].bg); - int right = TERM_EXPECT(t->lr_margin_mode, 0) ? t->right_margin : t->cols - 1; + int right = WSAP_VTCORE_EXPECT(t->lr_margin_mode, 0) ? t->right_margin : t->cols - 1; int avail = right + 1 > cx ? right + 1 - cx : 0; return (struct span){ .row = row, @@ -182,21 +182,21 @@ static inline struct span sc_span_begin(struct term *t, int want) }; } -static inline void sc_span_end(struct term *t, struct span *s, int cols, +static inline void sc_span_end(struct wsap_vtcore *t, struct span *s, int cols, uint8_t row_flags, uint32_t last) { struct srow *row = s->row; int end_x = s->x + cols; - if (TERM_EXPECT(end_x < s->old_len && (row->cells[end_x].flags & CELL_TRAIL), 0)) + if (WSAP_VTCORE_EXPECT(end_x < s->old_len && (row->cells[end_x].flags & CELL_TRAIL), 0)) fill_cells(row->cells + end_x, 1, row->cells[end_x].fg, row->cells[end_x].bg); if (end_x > s->old_len) row->len = (uint16_t)end_x; - if (TERM_EXPECT(row_flags != 0, 0)) + if (WSAP_VTCORE_EXPECT(row_flags != 0, 0)) row->flags |= row_flags; row->version++; t->last_char = last; - if (TERM_EXPECT(cols < s->avail, 1)) { + if (WSAP_VTCORE_EXPECT(cols < s->avail, 1)) { t->cursor_x = end_x; t->pending_wrap = false; } else { @@ -206,7 +206,7 @@ static inline void sc_span_end(struct term *t, struct span *s, int cols, } /* Move the cursor after cols columns written at x, of avail. */ -static inline void sc_text_advance(struct term *t, int x, int cols, int avail) +static inline void sc_text_advance(struct wsap_vtcore *t, int x, int cols, int avail) { if (cols < avail) { t->cursor_x = x + cols; @@ -219,12 +219,12 @@ static inline void sc_text_advance(struct term *t, int x, int cols, int avail) /* Append ASCII at the cursor, with the pen, * when the cursor row takes text. Return the bytes taken. */ -static inline int sc_text_ascii(struct term *t, const char *s, int n, struct text_pen pen) +static inline int sc_text_ascii(struct wsap_vtcore *t, const char *s, int n, struct text_pen pen) { - if (TERM_EXPECT(t->insert_mode || t->lr_margin_mode, 0)) + if (WSAP_VTCORE_EXPECT(t->insert_mode || t->lr_margin_mode, 0)) return 0; if (t->pending_wrap) { - row_set_wrapped(term_row(t, t->cursor_y), true); + row_set_wrapped(wsap_vtcore_row(t, t->cursor_y), true); t->cursor_x = 0; sc_linefeed(t, 1); t->pending_wrap = false; @@ -242,16 +242,16 @@ static inline int sc_text_ascii(struct term *t, const char *s, int n, struct tex return take; } -static inline void sc_print_ascii(struct term *t, const char *s, int n) +static inline void sc_print_ascii(struct wsap_vtcore *t, const char *s, int n) { - struct text_pen pen = term_text_pen(t); + struct text_pen pen = wsap_vtcore_text_pen(t); for (int k; n > 0 && (k = sc_text_ascii(t, s, n, pen)) > 0; s += k, n -= k) {} while (n > 0) { struct span span = sc_span_begin(t, n); int take = n < span.avail ? n : span.avail; - if (TERM_EXPECT(take <= 0, 0)) { + if (WSAP_VTCORE_EXPECT(take <= 0, 0)) { t->pending_wrap = t->autowrap; if (!t->autowrap) break; @@ -262,33 +262,33 @@ static inline void sc_print_ascii(struct term *t, const char *s, int n) } put_ascii_chunk(span.cells, s, take, pen.fg, pen.bg, pen.sl); sc_span_end(t, &span, take, 0, (unsigned char)s[take - 1]); - if (TERM_EXPECT(n <= take, 1)) break; + if (WSAP_VTCORE_EXPECT(n <= take, 1)) break; s += take; n -= take; } } /* Write a short ASCII span without settling an already writable row. */ -static inline bool sc_ascii_fast(struct term *t, const char *s, int n, +static inline bool sc_ascii_fast(struct wsap_vtcore *t, const char *s, int n, struct text_pen pen) { int cx = t->cursor_x; - if (TERM_EXPECT(t->pending_wrap || t->insert_mode || + if (WSAP_VTCORE_EXPECT(t->pending_wrap || t->insert_mode || t->lr_margin_mode || t->inverse || n <= 0 || n > t->cols - cx, 0)) return false; - struct srow *row = term_row(t, t->cursor_y); + struct srow *row = wsap_vtcore_row(t, t->cursor_y); if (row->kind == ROW_TEXT || (row->len == 0 && cx == 0)) { if (sc_text_ascii(t, s, n, pen) == n) return true; if (row->kind == ROW_TEXT) return false; } - if (TERM_EXPECT(row->kind != ROW_CELLS || cx > row->len, 0)) + if (WSAP_VTCORE_EXPECT(row->kind != ROW_CELLS || cx > row->len, 0)) return false; int len = row->len; struct cell *cells = row->cells; - if (TERM_EXPECT((cx < len && (cells[cx].flags & CELL_TRAIL)) || + if (WSAP_VTCORE_EXPECT((cx < len && (cells[cx].flags & CELL_TRAIL)) || (cx + n < len && (cells[cx + n].flags & CELL_TRAIL)), 0)) return false; put_ascii_chunk(cells + cx, s, n, pen.fg, pen.bg, pen.sl); @@ -308,18 +308,18 @@ static inline bool sc_ascii_fast(struct term *t, const char *s, int n, } /* Fast inline check for 1-character write (fg-char fast path). */ -static inline bool sc_put1_fast(struct term *t, char ch, struct text_pen pen) +static inline bool sc_put1_fast(struct wsap_vtcore *t, char ch, struct text_pen pen) { int cx = t->cursor_x; int cols = t->cols; - if (TERM_EXPECT(t->pending_wrap | t->insert_mode | t->lr_margin_mode | t->inverse, 0)) + if (WSAP_VTCORE_EXPECT(t->pending_wrap | t->insert_mode | t->lr_margin_mode | t->inverse, 0)) return false; - if (TERM_EXPECT(cx >= cols, 0)) + if (WSAP_VTCORE_EXPECT(cx >= cols, 0)) return false; - struct srow *row = term_row(t, t->cursor_y); + struct srow *row = wsap_vtcore_row(t, t->cursor_y); if (row->kind == ROW_TEXT) { struct text_row *tr = &row->text; - if (TERM_EXPECT(cx != tr->cells || !tr->cells || cx + 1 == cols, 0)) + if (WSAP_VTCORE_EXPECT(cx != tr->cells || !tr->cells || cx + 1 == cols, 0)) return sc_text_ascii(t, &ch, 1, pen) == 1; /* One character in the middle of a text row. */ tr->text[tr->text_len++] = (uint8_t)ch; @@ -339,10 +339,10 @@ static inline bool sc_put1_fast(struct term *t, char ch, struct text_pen pen) return true; } int len = row->len; - if (TERM_EXPECT(cx > len, 0)) + if (WSAP_VTCORE_EXPECT(cx > len, 0)) return false; struct cell *cells = row->cells; - if (TERM_EXPECT((cx < len && (cells[cx].flags & CELL_TRAIL)) || + if (WSAP_VTCORE_EXPECT((cx < len && (cells[cx].flags & CELL_TRAIL)) || (cx + 1 < len && (cells[cx + 1].flags & CELL_TRAIL)), 0)) return false; @@ -353,7 +353,7 @@ static inline bool sc_put1_fast(struct term *t, char ch, struct text_pen pen) if (cx > len) row->len = (uint16_t)cx; row->version++; - if (TERM_EXPECT(cx < cols, 1)) { + if (WSAP_VTCORE_EXPECT(cx < cols, 1)) { t->cursor_x = cx; } else { t->cursor_x = cols - 1; diff --git a/src/escape.c b/src/escape.c index dceb7a6..d5f61eb 100644 --- a/src/escape.c +++ b/src/escape.c @@ -11,27 +11,27 @@ #include <string.h> #include <stdio.h> -static int sgr_color_param(const struct term *t, char *buf, size_t sz, int base, uint32_t c) +static int sgr_color_param(const struct wsap_vtcore *t, char *buf, size_t sz, int base, uint32_t c) { - if (term_color_is_slot(c) && (c & 0x1FFu) < 256) { + if (wsap_vtcore_color_is_slot(c) && (c & 0x1FFu) < 256) { int i = (int)(c & 0xFFu); /* The underline color has no short form. */ if (i < 16 && base != 50) return snprintf(buf, sz, ";%d", i < 8 ? base + i : base + 60 + i - 8); return snprintf(buf, sz, ";%d:5:%d", base + 8, i); } - if (term_color_is_slot(c)) - c = t->palette.colors[c & TERM_COLOR_SLOT_INDEX]; + if (wsap_vtcore_color_is_slot(c)) + c = t->palette.colors[c & WSAP_VTCORE_COLOR_SLOT_INDEX]; return snprintf(buf, sz, ";%d:2:%d:%d:%d", base + 8, (int)((c >> 16) & 0xff), (int)((c >> 8) & 0xff), (int)(c & 0xff)); } -static int sgr_serialize(const struct term *t, char *buf, size_t sz) +static int sgr_serialize(const struct wsap_vtcore *t, char *buf, size_t sz) { int n = 0; if (!(t->bold || t->faint || t->italic || t->underline || t->strike || - t->overline || t->inverse || t->cur_fg != TERM_COLOR_FG || - t->cur_bg != TERM_COLOR_BG || t->cur_ul)) + t->overline || t->inverse || t->cur_fg != WSAP_VTCORE_COLOR_FG || + t->cur_bg != WSAP_VTCORE_COLOR_BG || t->cur_ul)) return 0; #define SGR_ADD(expr) \ do { \ @@ -47,8 +47,8 @@ static int sgr_serialize(const struct term *t, char *buf, size_t sz) if (t->inverse) SGR_ADD(snprintf(buf + n, sz - (size_t)n, ";7")); if (t->strike) SGR_ADD(snprintf(buf + n, sz - (size_t)n, ";9")); if (t->overline) SGR_ADD(snprintf(buf + n, sz - (size_t)n, ";53")); - if (t->cur_fg != TERM_COLOR_FG) SGR_ADD(sgr_color_param(t, buf + n, sz - (size_t)n, 30, t->cur_fg)); - if (t->cur_bg != TERM_COLOR_BG) SGR_ADD(sgr_color_param(t, buf + n, sz - (size_t)n, 40, t->cur_bg)); + if (t->cur_fg != WSAP_VTCORE_COLOR_FG) SGR_ADD(sgr_color_param(t, buf + n, sz - (size_t)n, 30, t->cur_fg)); + if (t->cur_bg != WSAP_VTCORE_COLOR_BG) SGR_ADD(sgr_color_param(t, buf + n, sz - (size_t)n, 40, t->cur_bg)); if (t->cur_ul) SGR_ADD(sgr_color_param(t, buf + n, sz - (size_t)n, 50, t->cur_ul)); #undef SGR_ADD return n; @@ -105,7 +105,7 @@ static int tcap_cmp(const void *k, const void *e) return strcmp(key, elem->name); } -static const char *term_tcap(const struct term *t, const char *name) +static const char *wsap_vtcore_tcap(const struct wsap_vtcore *t, const char *name) { static const struct tcap_entry caps[] = { { "Co", "16777216" }, { "RGB", "8/8/8" }, @@ -193,7 +193,7 @@ static void resp_put(struct resp_buf *r, const char *s, size_t n) if (r->failed) return; if (r->len + n + 1 > r->cap) { - size_t cap = term_grow_cap(r->cap ? r->cap : 256, r->len + n + 1); + size_t cap = wsap_vtcore_grow_cap(r->cap ? r->cap : 256, r->len + n + 1); char *p = realloc(r->s, cap); if (!p) { r->failed = true; @@ -207,7 +207,7 @@ static void resp_put(struct resp_buf *r, const char *s, size_t n) r->s[r->len] = '\0'; } -static void dcs_xtgettcap(struct term *t, const char *buf, int len) +static void dcs_xtgettcap(struct wsap_vtcore *t, const char *buf, int len) { static const char hex[] = "0123456789abcdef"; struct resp_buf r = {0}; @@ -226,7 +226,7 @@ static void dcs_xtgettcap(struct term *t, const char *buf, int len) if (n < 0) break; name[n] = 0; - const char *cap = term_tcap(t, name); + const char *cap = wsap_vtcore_tcap(t, name); if (first && r.s) { r.s[2] = cap ? '1' : '0'; first = false; } resp_put(&r, buf + i, (size_t)span); if (!cap) break; @@ -266,7 +266,7 @@ static int dcs_param_chr(const char **p, const char *end) return v; } -static void restore_deccir(struct term *t, const char *p, const char *end) +static void restore_deccir(struct wsap_vtcore *t, const char *p, const char *end) { int row = dcs_param_int(&p, end); if (row <= 0 || row > t->rows) return; @@ -300,9 +300,9 @@ static void restore_deccir(struct term *t, const char *p, const char *end) t->graphics = t->charsets[t->charset_active] == '0'; } -static void restore_dectabsr(struct term *t, const char *p, const char *end) +static void restore_dectabsr(struct wsap_vtcore *t, const char *p, const char *end) { - term_tabs_clear(t); + wsap_vtcore_tabs_clear(t); t->custom_tabs = true; int stop = 0, any = 0; for (; p < end; p++) { @@ -319,18 +319,18 @@ static void restore_dectabsr(struct term *t, const char *p, const char *end) if (any && --stop >= 0 && stop < t->tabs_cap) t->tabs[stop] = 1; } -/* Grows the DCS string to hold extra more bytes, up to TERM_OSC_MAX. +/* Grows the DCS string to hold extra more bytes, up to WSAP_VTCORE_OSC_MAX. * False when nothing more fits. */ -static bool dcs_reserve(struct term *t, size_t extra) +static bool dcs_reserve(struct wsap_vtcore *t, size_t extra) { size_t need = (size_t)t->dcs_len + extra; if (need <= t->dcs_cap) return true; - if (t->dcs_cap >= TERM_OSC_MAX) + if (t->dcs_cap >= WSAP_VTCORE_OSC_MAX) return false; - size_t cap = term_grow_cap(t->dcs_cap ? t->dcs_cap : 256, need); - if (cap > TERM_OSC_MAX) - cap = TERM_OSC_MAX; + size_t cap = wsap_vtcore_grow_cap(t->dcs_cap ? t->dcs_cap : 256, need); + if (cap > WSAP_VTCORE_OSC_MAX) + cap = WSAP_VTCORE_OSC_MAX; char *p = realloc(t->dcs_buf, cap); if (!p) return false; @@ -339,9 +339,9 @@ static bool dcs_reserve(struct term *t, size_t extra) return need <= cap; } -static void dcs_dispatch(struct term *t) +static void dcs_dispatch(struct wsap_vtcore *t) { - if (term_str_was_truncated(t)) + if (wsap_vtcore_str_was_truncated(t)) return; const char *buf = t->dcs_buf; int len = t->dcs_len; @@ -370,8 +370,8 @@ static void dcs_dispatch(struct term *t) const char *spec = buf + 2; int slen = len - 2, p; if (slen == 2 && spec[0] == ' ' && spec[1] == 'q') { - int shape = t->cursor_style == TERM_CURSOR_BLOCK ? (t->cursor_blink ? 1 : 2) - : t->cursor_style == TERM_CURSOR_UNDERLINE ? (t->cursor_blink ? 3 : 4) + int shape = t->cursor_style == WSAP_VTCORE_CURSOR_BLOCK ? (t->cursor_blink ? 1 : 2) + : t->cursor_style == WSAP_VTCORE_CURSOR_UNDERLINE ? (t->cursor_blink ? 3 : 4) : (t->cursor_blink ? 5 : 6); p = snprintf(resp, sizeof(resp), "\033P1$r%d q\033\\", shape); } else if (slen == 1 && spec[0] == 'm') { @@ -421,7 +421,7 @@ static void dcs_dispatch(struct term *t) } } -static void soft_reset(struct term *t) +static void soft_reset(struct wsap_vtcore *t) { t->application_cursor = t->application_keypad = t->backarrow_sends_bs = false; t->insert_mode = t->origin_mode = t->reverse_video = t->lnm = false; @@ -439,14 +439,14 @@ static void soft_reset(struct term *t) reset_sgr(t); } -static inline void sgr_set_slot(struct term *t, int code, uint32_t c) +static inline void sgr_set_slot(struct wsap_vtcore *t, int code, uint32_t c) { if (code == 38) t->cur_fg = c; else if (code == 48) t->cur_bg = c; else t->cur_ul = c; } -static inline void handle_sgr(struct term *t, const struct csi *csi) +static inline void handle_sgr(struct wsap_vtcore *t, const struct csi *csi) { if (csi->nparams == 0) { reset_sgr(t); @@ -456,20 +456,20 @@ static inline void handle_sgr(struct term *t, const struct csi *csi) if (csi->nparams == 1 && !csi->subparams) { int p = csi->params[0]; if (p == 0) { reset_sgr(t); return; } - if ((unsigned)(p - 30) < 8) { t->cur_fg = term_color_index(p - 30); return; } - if ((unsigned)(p - 40) < 8) { t->cur_bg = term_color_index(p - 40); return; } - if ((unsigned)(p - 90) < 8) { t->cur_fg = term_color_index(p - 90 + 8); return; } - if ((unsigned)(p - 100) < 8) { t->cur_bg = term_color_index(p - 100 + 8); return; } + if ((unsigned)(p - 30) < 8) { t->cur_fg = wsap_vtcore_color_index(p - 30); return; } + if ((unsigned)(p - 40) < 8) { t->cur_bg = wsap_vtcore_color_index(p - 40); return; } + if ((unsigned)(p - 90) < 8) { t->cur_fg = wsap_vtcore_color_index(p - 90 + 8); return; } + if ((unsigned)(p - 100) < 8) { t->cur_bg = wsap_vtcore_color_index(p - 100 + 8); return; } if (p == 1) { t->bold = true; return; } - if (p == 39) { t->cur_fg = TERM_COLOR_FG; return; } - if (p == 49) { t->cur_bg = TERM_COLOR_BG; return; } + if (p == 39) { t->cur_fg = WSAP_VTCORE_COLOR_FG; return; } + if (p == 49) { t->cur_bg = WSAP_VTCORE_COLOR_BG; return; } } if (!csi->subparams) { if (csi->nparams == 5 && csi->params[1] == 2 && (csi->params[0] == 38 || csi->params[0] == 48)) { sgr_set_slot(t, csi->params[0], - term_rgb(csi->params[2], csi->params[3], csi->params[4])); + wsap_vtcore_rgb(csi->params[2], csi->params[3], csi->params[4])); return; } @@ -477,16 +477,16 @@ static inline void handle_sgr(struct term *t, const struct csi *csi) (csi->params[0] == 38 || csi->params[0] == 48) && csi->params[5] == (csi->params[0] == 38 ? 48 : 38)) { sgr_set_slot(t, csi->params[0], - term_rgb(csi->params[2], csi->params[3], csi->params[4])); + wsap_vtcore_rgb(csi->params[2], csi->params[3], csi->params[4])); sgr_set_slot(t, csi->params[5], - term_rgb(csi->params[7], csi->params[8], csi->params[9])); + wsap_vtcore_rgb(csi->params[7], csi->params[8], csi->params[9])); return; } if (csi->nparams == 3 && csi->params[1] == 5 && (csi->params[0] == 38 || csi->params[0] == 48) && (unsigned)csi->params[2] < 256) { - sgr_set_slot(t, csi->params[0], term_color_index(csi->params[2])); + sgr_set_slot(t, csi->params[0], wsap_vtcore_color_index(csi->params[2])); return; } @@ -494,13 +494,13 @@ static inline void handle_sgr(struct term *t, const struct csi *csi) (csi->params[0] == 38 || csi->params[0] == 48) && csi->params[3] == (csi->params[0] == 38 ? 48 : 38) && (unsigned)csi->params[2] < 256 && (unsigned)csi->params[5] < 256) { - sgr_set_slot(t, csi->params[0], term_color_index(csi->params[2])); - sgr_set_slot(t, csi->params[3], term_color_index(csi->params[5])); + sgr_set_slot(t, csi->params[0], wsap_vtcore_color_index(csi->params[2])); + sgr_set_slot(t, csi->params[3], wsap_vtcore_color_index(csi->params[5])); return; } } - struct term_pen pen = { + struct wsap_vtcore_pen pen = { .fg = t->cur_fg, .bg = t->cur_bg, .ul = t->cur_ul, .underline = t->underline, .bold = t->bold, .faint = t->faint, .italic = t->italic, @@ -519,7 +519,7 @@ static inline void handle_sgr(struct term *t, const struct csi *csi) t->inverse = pen.inverse; } -#define TERM_PRIV_MODE_FIELDS(X) \ +#define WSAP_VTCORE_PRIV_MODE_FIELDS(X) \ X(1, application_cursor) \ X(12, cursor_blink) \ X(25, cursor_visible) \ @@ -528,16 +528,16 @@ static inline void handle_sgr(struct term *t, const struct csi *csi) X(2004, bracketed_paste) \ X(2026, synchronized_output) -#define TERM_ANSI_MODE_FIELDS(X) \ +#define WSAP_VTCORE_ANSI_MODE_FIELDS(X) \ X(4, insert_mode) \ X(20, lnm) -static int mode_get(const struct term *t, int mode, bool priv) +static int mode_get(const struct wsap_vtcore *t, int mode, bool priv) { if (priv) { switch (mode) { #define MODE_FIELD_GET(n, f) case n: return t->f; - TERM_PRIV_MODE_FIELDS(MODE_FIELD_GET) + WSAP_VTCORE_PRIV_MODE_FIELDS(MODE_FIELD_GET) #undef MODE_FIELD_GET case 5: return t->reverse_video; case 6: return t->origin_mode; @@ -552,30 +552,30 @@ static int mode_get(const struct term *t, int mode, bool priv) } switch (mode) { #define MODE_FIELD_GET(n, f) case n: return t->f; - TERM_ANSI_MODE_FIELDS(MODE_FIELD_GET) + WSAP_VTCORE_ANSI_MODE_FIELDS(MODE_FIELD_GET) #undef MODE_FIELD_GET } return -1; } -static int cursor_top(const struct term *t) { return t->origin_mode ? t->scroll_top : 0; } -static int cursor_bottom(const struct term *t) { return t->origin_mode ? t->scroll_bottom : t->rows - 1; } -static int cursor_left(const struct term *t) { return t->origin_mode && t->lr_margin_mode ? t->left_margin : 0; } -static int cursor_right(const struct term *t) { return t->origin_mode && t->lr_margin_mode ? t->right_margin : t->cols - 1; } +static int cursor_top(const struct wsap_vtcore *t) { return t->origin_mode ? t->scroll_top : 0; } +static int cursor_bottom(const struct wsap_vtcore *t) { return t->origin_mode ? t->scroll_bottom : t->rows - 1; } +static int cursor_left(const struct wsap_vtcore *t) { return t->origin_mode && t->lr_margin_mode ? t->left_margin : 0; } +static int cursor_right(const struct wsap_vtcore *t) { return t->origin_mode && t->lr_margin_mode ? t->right_margin : t->cols - 1; } -static void mode_set(struct term *t, int mode, bool enabled, bool priv) +static void mode_set(struct wsap_vtcore *t, int mode, bool enabled, bool priv) { if (!priv) { switch (mode) { #define MODE_FIELD_SET(n, f) case n: t->f = enabled; break; - TERM_ANSI_MODE_FIELDS(MODE_FIELD_SET) + WSAP_VTCORE_ANSI_MODE_FIELDS(MODE_FIELD_SET) #undef MODE_FIELD_SET } return; } switch (mode) { #define MODE_FIELD_SET(n, f) case n: t->f = enabled; return; - TERM_PRIV_MODE_FIELDS(MODE_FIELD_SET) + WSAP_VTCORE_PRIV_MODE_FIELDS(MODE_FIELD_SET) #undef MODE_FIELD_SET default: break; } @@ -591,10 +591,10 @@ static void mode_set(struct term *t, int mode, bool enabled, bool priv) t->autowrap = enabled; t->pending_wrap = false; } else if (mode == 1048) { - if (enabled) t->saved = term_cursor_save(t); + if (enabled) t->saved = wsap_vtcore_cursor_save(t); else sc_restore_cursor(t, &t->saved); } else if (mode == 47 || mode == 1047 || mode == 1049) { - term_screen_set_alternate(t, enabled); + wsap_vtcore_screen_set_alternate(t, enabled); } else if (mode_is_mouse(mode)) { t->mouse_mode = enabled ? mode : 0; } else if (mode == 69) { @@ -608,7 +608,7 @@ static void mode_set(struct term *t, int mode, bool enabled, bool priv) /* Vertical moves stop at a margin when they start inside the scroll * region (xterm, DEC STD 070). */ -static inline void move_v(struct term *t, int n, bool col0) +static inline void move_v(struct wsap_vtcore *t, int n, bool col0) { int top = t->cursor_y >= t->scroll_top ? t->scroll_top : 0; int bottom = t->cursor_y <= t->scroll_bottom ? t->scroll_bottom : t->rows - 1; @@ -616,7 +616,7 @@ static inline void move_v(struct term *t, int n, bool col0) : (n < bottom - t->cursor_y ? t->cursor_y + n : bottom); sc_move(t, col0 ? cursor_left(t) : t->cursor_x, y); } -static inline void move_h(struct term *t, int n, bool margin_aware) +static inline void move_h(struct wsap_vtcore *t, int n, bool margin_aware) { int right = margin_aware ? cursor_right(t) : t->cols - 1; int x = n < 0 ? (t->cursor_x >= -n ? t->cursor_x + n : 0) @@ -624,15 +624,15 @@ static inline void move_h(struct term *t, int n, bool margin_aware) sc_move(t, x, t->cursor_y); } -static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct csi *csi) +static inline WSAP_VTCORE_ALWAYS_INLINE void dispatch_csi(struct wsap_vtcore *t, const struct csi *csi) { - if (TERM_EXPECT(csi->final == 'm', 1)) { - if (TERM_EXPECT(!csi->prefix && !csi->intermediate, 1)) + if (WSAP_VTCORE_EXPECT(csi->final == 'm', 1)) { + if (WSAP_VTCORE_EXPECT(!csi->prefix && !csi->intermediate, 1)) handle_sgr(t, csi); return; } - if (TERM_EXPECT(csi->final == 'H' || csi->final == 'f', 0)) { - if (TERM_EXPECT(!csi->prefix && !csi->intermediate && !csi->subparams, 1)) { + if (WSAP_VTCORE_EXPECT(csi->final == 'H' || csi->final == 'f', 0)) { + if (WSAP_VTCORE_EXPECT(!csi->prefix && !csi->intermediate && !csi->subparams, 1)) { int64_t r = (int64_t)(csi->params[0] > 0 ? csi->params[0] - 1 : 0) + cursor_top(t); if (r > cursor_bottom(t)) r = cursor_bottom(t); int64_t c = (int64_t)(csi->nparams > 1 && csi->params[1] > 0 ? csi->params[1] - 1 : 0) + cursor_left(t); @@ -668,7 +668,7 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct switch (csi->final) { case 'r': { if (csi->intermediate == '$') { - term_sc_deccara(t, csi); + wsap_vtcore_sc_deccara(t, csi); break; } if (csi->prefix || csi->intermediate) break; @@ -684,7 +684,7 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct case 'L': case 'M': if (csi->prefix || t->cursor_y < t->scroll_top || t->cursor_y > t->scroll_bottom) break; - term_screen_scroll_region(t, t->cursor_y, t->scroll_bottom, + wsap_vtcore_screen_scroll_region(t, t->cursor_y, t->scroll_bottom, csi_count(csi), csi->final == 'L', false); /* IL and DL move the cursor to the left margin (xterm). */ sc_move(t, t->lr_margin_mode ? t->left_margin : 0, t->cursor_y); @@ -692,7 +692,7 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct case 'S': case 'T': if (csi->prefix || csi->nparams > 1) break; - term_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, + wsap_vtcore_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, csi_count(csi), csi->final == 'T', true); break; case 'd': { @@ -702,7 +702,7 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct break; } case 'b': - term_text_repeat(t, csi_count(csi)); + wsap_vtcore_text_repeat(t, csi_count(csi)); break; case 'A': move_v(t, -csi_count(csi), false); break; case 'B': move_v(t, csi_count(csi), false); break; @@ -727,25 +727,25 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct sc_move(t, t->origin_mode ? left : 0, cursor_top(t)); } } else if (!csi->prefix) { - t->saved = term_cursor_save(t); + t->saved = wsap_vtcore_cursor_save(t); } break; case 'I': case 'Z': - term_sc_tab(t, csi->final == 'I' ? csi_count(csi) : -csi_count(csi)); + wsap_vtcore_sc_tab(t, csi->final == 'I' ? csi_count(csi) : -csi_count(csi)); break; case 'g': if (csi->params[0] == 0) { t->tabs[t->cursor_x] = 0; t->custom_tabs = true; } else if (csi->params[0] == 3) { - term_tabs_clear(t); + wsap_vtcore_tabs_clear(t); } break; case 'W': if (csi->prefix == '?' && csi->params[0] == 5) { - term_tabs_clear(t); - term_tabs_default(t); + wsap_vtcore_tabs_clear(t); + wsap_vtcore_tabs_default(t); } break; case 'n': @@ -759,7 +759,7 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct } break; case 'J': - term_screen_erase(t, csi->params[0]); + wsap_vtcore_screen_erase(t, csi->params[0]); break; case 'X': { int n = csi_count(csi); @@ -772,13 +772,13 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct t->decsace = (uint8_t)csi->params[0]; break; case 'K': - term_screen_erase_line(t, csi->params[0]); + wsap_vtcore_screen_erase_line(t, csi->params[0]); break; case 'P': - term_screen_delete_chars(t, csi_count(csi)); + wsap_vtcore_screen_delete_chars(t, csi_count(csi)); break; case '@': - term_screen_insert_chars(t, csi_count(csi)); + wsap_vtcore_screen_insert_chars(t, csi_count(csi)); break; case 'c': { if (csi->prefix == '>') @@ -838,7 +838,7 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct snprintf(resp, sizeof(resp), "\033P>|%s\033\\", t->name); send_response(t, resp); } else if (!csi->prefix && csi->intermediate == ' ') { - term_sc_set_cursor_style(t, csi->nparams > 0 ? csi->params[0] : 0); + wsap_vtcore_sc_set_cursor_style(t, csi->nparams > 0 ? csi->params[0] : 0); } break; } @@ -861,7 +861,7 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct } /* Formats one trace line and hands it to the host's trace callback. */ -static void esc_tracef(const struct term *t, const char *fmt, ...) +static void esc_tracef(const struct wsap_vtcore *t, const char *fmt, ...) { char line[512]; va_list ap; @@ -875,7 +875,7 @@ static void esc_tracef(const struct term *t, const char *fmt, ...) #define ESC_TRACE(t, ...) \ do { if ((t)->cb.trace) esc_tracef((t), __VA_ARGS__); } while (0) -static void dispatch_esc(struct term *t, unsigned char ch) +static void dispatch_esc(struct wsap_vtcore *t, unsigned char ch) { t->state = ST_GROUND; switch (ch) { @@ -890,9 +890,9 @@ static void dispatch_esc(struct term *t, unsigned char ch) t->custom_tabs = true; break; case 'c': - if (t->alternate) term_screen_set_alternate(t, false); + if (t->alternate) wsap_vtcore_screen_set_alternate(t, false); soft_reset(t); - term_sc_reset(t); + wsap_vtcore_sc_reset(t); break; case '[': ESC_TRACE(t, "ESC[ → ST_CSI"); @@ -939,12 +939,12 @@ static void dispatch_esc(struct term *t, unsigned char ch) break; case 'M': if (t->cursor_y == t->scroll_top) - term_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, 1, true, false); + wsap_vtcore_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, 1, true, false); else sc_move(t, t->cursor_x, t->cursor_y > 0 ? t->cursor_y - 1 : 0); break; case '7': - t->saved = term_cursor_save(t); + t->saved = wsap_vtcore_cursor_save(t); break; case '8': sc_restore_cursor(t, &t->saved); @@ -954,7 +954,7 @@ static void dispatch_esc(struct term *t, unsigned char ch) } } -void term_escape_byte(struct term *t, unsigned char ch) +void wsap_vtcore_escape_byte(struct wsap_vtcore *t, unsigned char ch) { if (ch >= 0x80 && t->state != ST_OSC && t->state != ST_DCS && t->state != ST_IGNORE) { @@ -962,7 +962,7 @@ void term_escape_byte(struct term *t, unsigned char ch) t->osc_len = 0; t->dcs_len = 0; t->state = ST_GROUND; - term_text_ground(t, ch); + wsap_vtcore_text_ground(t, ch); return; } switch (t->state) { @@ -970,7 +970,7 @@ void term_escape_byte(struct term *t, unsigned char ch) ESC_TRACE(t, " ESC+0x%02x('%c')", ch, ch >= 0x20 && ch < 0x7f ? ch : '.'); if (ch < 0x20) { t->state = ST_GROUND; - term_text_ground(t, ch); + wsap_vtcore_text_ground(t, ch); } else { dispatch_esc(t, ch); } @@ -985,7 +985,7 @@ void term_escape_byte(struct term *t, unsigned char ch) } else if (ch < 0x20) { /* Other C0 controls run inside the sequence (ECMA-48 5.5, * xterm). */ - term_text_ground(t, ch); + wsap_vtcore_text_ground(t, ch); } break; case ST_CHARSET: @@ -997,15 +997,15 @@ void term_escape_byte(struct term *t, unsigned char ch) break; case ST_DOCS: if (ch != 'G' && ch != '@' && ch != '/') - term_text_ground(t, '%'); + wsap_vtcore_text_ground(t, '%'); t->state = ST_GROUND; if (ch != 'G' && ch != '@' && ch != '/') - term_text_ground(t, ch); + wsap_vtcore_text_ground(t, ch); break; case ST_DECALN: t->state = ST_GROUND; if (ch == '8') - term_sc_decaln(t); + wsap_vtcore_sc_decaln(t); break; case ST_IGNORE: if (ch == 0x07 || ch == 0x18 || ch == 0x1a) @@ -1018,21 +1018,21 @@ void term_escape_byte(struct term *t, unsigned char ch) t->state = ST_GROUND; else { t->state = ST_ESC; - term_escape_byte(t, ch); + wsap_vtcore_escape_byte(t, ch); } break; case ST_OSC: if (ch == 0x07) { - term_osc_finish(t); + wsap_vtcore_osc_finish(t); t->state = ST_GROUND; } else if (ch == 0x1b) { t->state = ST_STR_ESC; } else if (ch < 0x20) { t->osc_len = 0; t->state = ST_GROUND; - term_text_ground(t, ch); - } else if (term_osc_room(t) || term_osc_grow(t)) { - *term_osc_tail(t) = (char)ch; + wsap_vtcore_text_ground(t, ch); + } else if (wsap_vtcore_osc_room(t) || wsap_vtcore_osc_grow(t)) { + *wsap_vtcore_osc_tail(t) = (char)ch; t->osc_len++; } else { t->str_truncated = true; @@ -1048,7 +1048,7 @@ void term_escape_byte(struct term *t, unsigned char ch) } else if (ch < 0x20) { t->dcs_len = 0; t->state = ST_GROUND; - term_text_ground(t, ch); + wsap_vtcore_text_ground(t, ch); } else if (dcs_reserve(t, 1)) { t->dcs_buf[t->dcs_len++] = (char)ch; } else { @@ -1063,18 +1063,18 @@ void term_escape_byte(struct term *t, unsigned char ch) } else { t->dcs_len = 0; t->state = ST_ESC; - term_escape_byte(t, ch); + wsap_vtcore_escape_byte(t, ch); } break; case ST_STR_ESC: if (ch == '\\') { - term_osc_finish(t); + wsap_vtcore_osc_finish(t); t->state = ST_GROUND; } else { t->osc_len = 0; t->dcs_len = 0; t->state = ST_ESC; - term_escape_byte(t, ch); + wsap_vtcore_escape_byte(t, ch); } break; default: @@ -1082,24 +1082,24 @@ void term_escape_byte(struct term *t, unsigned char ch) } } -size_t term_escape_str(struct term *t, const char *buf, size_t len) +size_t wsap_vtcore_escape_str(struct wsap_vtcore *t, const char *buf, size_t len) { if (t->state == ST_IGNORE) { size_t take = scan_printable_span(buf, len, 0x80); if (take < len) - term_escape_byte(t, (unsigned char)buf[take++]); + wsap_vtcore_escape_byte(t, (unsigned char)buf[take++]); return take; } int is_osc = t->state == ST_OSC; size_t take = scan_printable_span(buf, len, 0x80); if (is_osc) { - size_t room = term_osc_room(t); - if (take > room && term_osc_grow(t)) - room = term_osc_room(t); + size_t room = wsap_vtcore_osc_room(t); + if (take > room && wsap_vtcore_osc_grow(t)) + room = wsap_vtcore_osc_room(t); if (room) { if (take > room) take = room; - memcpy(term_osc_tail(t), buf, take); + memcpy(wsap_vtcore_osc_tail(t), buf, take); t->osc_len += (int)take; } else { t->str_truncated = true; @@ -1117,16 +1117,16 @@ size_t term_escape_str(struct term *t, const char *buf, size_t len) } } if (take < len) - term_escape_byte(t, (unsigned char)buf[take++]); + wsap_vtcore_escape_byte(t, (unsigned char)buf[take++]); return take; } -size_t term_escape_csi(struct term *t, const char *buf, size_t len) +size_t wsap_vtcore_escape_csi(struct wsap_vtcore *t, const char *buf, size_t len) { size_t consumed; enum csi_result result = csi_read(&t->csi_parser, buf, len, &consumed); if (result == CSI_CONTROL) { - term_escape_byte(t, (unsigned char)buf[consumed++]); + wsap_vtcore_escape_byte(t, (unsigned char)buf[consumed++]); } else if (result == CSI_DISPATCH || result == CSI_DISCARD) { if (t->cb.trace) { const struct csi *c = &t->csi_parser.csi; @@ -1148,7 +1148,7 @@ size_t term_escape_csi(struct term *t, const char *buf, size_t len) return consumed; } -void term_escape_begin(struct term *t) +void wsap_vtcore_escape_begin(struct wsap_vtcore *t) { ESC_TRACE(t, "0x1b → ST_ESC"); t->state = ST_ESC; diff --git a/src/escape.h b/src/escape.h index a66d02c..cf58c75 100644 --- a/src/escape.h +++ b/src/escape.h @@ -1,10 +1,10 @@ -#ifndef TERM_ESCAPE_H -#define TERM_ESCAPE_H +#ifndef WSAP_VTCORE_ESCAPE_H +#define WSAP_VTCORE_ESCAPE_H #include "internal.h" -void term_escape_begin(struct term *t); -void term_escape_byte(struct term *t, unsigned char ch); -size_t term_escape_str(struct term *t, const char *buf, size_t len); -size_t term_escape_csi(struct term *t, const char *buf, size_t len); +void wsap_vtcore_escape_begin(struct wsap_vtcore *t); +void wsap_vtcore_escape_byte(struct wsap_vtcore *t, unsigned char ch); +size_t wsap_vtcore_escape_str(struct wsap_vtcore *t, const char *buf, size_t len); +size_t wsap_vtcore_escape_csi(struct wsap_vtcore *t, const char *buf, size_t len); #endif diff --git a/src/fastcsi.c b/src/fastcsi.c index 2e0f004..6f9d926 100644 --- a/src/fastcsi.c +++ b/src/fastcsi.c @@ -9,7 +9,7 @@ #include <stdint.h> #include <string.h> -TERM_ALWAYS_INLINE +WSAP_VTCORE_ALWAYS_INLINE static inline const char *parse_byte_delim(const char *s, const char *end, char delim, uint32_t *val) { if (s >= end) return NULL; @@ -45,7 +45,7 @@ static inline const char *parse_color_sequence(const char *p, const char *end, u if (!s) return NULL; s = parse_byte_delim(s, end, 'm', &b); if (!s) return NULL; - *color = term_rgb((int)r, (int)g, (int)b); + *color = wsap_vtcore_rgb((int)r, (int)g, (int)b); return s; } @@ -54,12 +54,12 @@ static const char *parse_256color(const char *p, const char *end, uint32_t *colo uint32_t v; const char *s = parse_byte_delim(p + 2, end, 'm', &v); if (!s) return NULL; - *color = term_color_index(v); + *color = wsap_vtcore_color_index(v); return s; } -TERM_NOINLINE -int term_try_fast_csi(struct term *t, const char *buf, size_t rem) +WSAP_VTCORE_NOINLINE +int wsap_vtcore_try_fast_csi(struct wsap_vtcore *t, const char *buf, size_t rem) { const char *end = buf + rem; const char *p = buf; @@ -94,11 +94,11 @@ int term_try_fast_csi(struct term *t, const char *buf, size_t rem) } if (p < end && (unsigned char)*p >= 0x20 && (unsigned char)*p < 0x7f) { char ch = *p++; - if (TERM_EXPECT(!flags_ok, 0)) { - flags_pad = term_flags_pad(t); + if (WSAP_VTCORE_EXPECT(!flags_ok, 0)) { + flags_pad = wsap_vtcore_flags_pad(t); flags_ok = true; } - if (TERM_EXPECT(!sc_put1_fast(t, ch, (struct text_pen){ fg, bg, flags_pad }), 0)) { + if (WSAP_VTCORE_EXPECT(!sc_put1_fast(t, ch, (struct text_pen){ fg, bg, flags_pad }), 0)) { t->cur_fg = fg; t->cur_bg = bg; sc_print_ascii(t, &ch, 1); @@ -116,20 +116,20 @@ int term_try_fast_csi(struct term *t, const char *buf, size_t rem) /* Recompute instead of zeroing. The cached flags carry the link * id, and reset_sgr leaves cur_link set, so zeroing here would * drop the hyperlink from every cell written after the reset. */ - flags_pad = term_flags_pad(t); + flags_pad = wsap_vtcore_flags_pad(t); flags_ok = true; p += p[0] == 'm' ? 1 : 2; } else if (p[0] == 'J' || (p[0] >= '0' && p[0] <= '3' && p + 1 < end && p[1] == 'J')) { t->cur_fg = fg; t->cur_bg = bg; - term_screen_erase(t, p[0] == 'J' ? 0 : p[0] - '0'); + wsap_vtcore_screen_erase(t, p[0] == 'J' ? 0 : p[0] - '0'); p += p[0] == 'J' ? 1 : 2; } else if (p[0] == 'K' || (p[0] >= '0' && p[0] <= '2' && p + 1 < end && p[1] == 'K')) { t->cur_fg = fg; t->cur_bg = bg; - term_screen_erase_line(t, p[0] == 'K' ? 0 : p[0] - '0'); + wsap_vtcore_screen_erase_line(t, p[0] == 'K' ? 0 : p[0] - '0'); p += p[0] == 'K' ? 1 : 2; } else if (!t->origin_mode && !t->lr_margin_mode && ((*p >= '0' && *p <= '9') || *p == ';' || @@ -166,7 +166,7 @@ int term_try_fast_csi(struct term *t, const char *buf, size_t rem) case 'E': ny += n; nx = 0; goto vmove; case 'F': ny -= n; nx = 0; goto vmove; vmove: - if (TERM_EXPECT(t->scroll_top != 0 || t->scroll_bottom != rows - 1, 0)) { + if (WSAP_VTCORE_EXPECT(t->scroll_top != 0 || t->scroll_bottom != rows - 1, 0)) { p = esc; goto done; } @@ -200,16 +200,16 @@ int term_try_fast_csi(struct term *t, const char *buf, size_t rem) case 24: t->underline = 0; break; case 27: t->inverse = false; break; case 29: t->strike = false; break; - case 39: fg = TERM_COLOR_FG; break; - case 49: bg = TERM_COLOR_BG; break; + case 39: fg = WSAP_VTCORE_COLOR_FG; break; + case 49: bg = WSAP_VTCORE_COLOR_BG; break; case 53: t->overline = true; break; case 55: t->overline = false; break; case 59: t->cur_ul = 0; break; default: - if ((unsigned)(v - 30) < 8) fg = term_color_index(v - 30); - else if ((unsigned)(v - 40) < 8) bg = term_color_index(v - 40); - else if ((unsigned)(v - 90) < 8) fg = term_color_index(v - 90 + 8); - else if ((unsigned)(v - 100) < 8) bg = term_color_index(v - 100 + 8); + if ((unsigned)(v - 30) < 8) fg = wsap_vtcore_color_index(v - 30); + else if ((unsigned)(v - 40) < 8) bg = wsap_vtcore_color_index(v - 40); + else if ((unsigned)(v - 90) < 8) fg = wsap_vtcore_color_index(v - 90 + 8); + else if ((unsigned)(v - 100) < 8) bg = wsap_vtcore_color_index(v - 100 + 8); break; } flags_ok = false; @@ -236,25 +236,25 @@ int term_try_fast_csi(struct term *t, const char *buf, size_t rem) uint32_t *slot = v == 38 ? &fg : v == 48 ? &bg : &t->cur_ul; if (j + 2 < nparams && pv[j + 1] == 5) { if (pv[j + 2] >= 0 && pv[j + 2] <= 255) - *slot = term_color_index(pv[j + 2]); + *slot = wsap_vtcore_color_index(pv[j + 2]); j += 2; } else if (j + 1 < nparams && pv[j + 1] == 2 && j + 4 < nparams) { - *slot = term_rgb(pv[j + 2], pv[j + 3], pv[j + 4]); + *slot = wsap_vtcore_rgb(pv[j + 2], pv[j + 3], pv[j + 4]); j += 4; } break; } - case 39: fg = TERM_COLOR_FG; break; - case 49: bg = TERM_COLOR_BG; break; + case 39: fg = WSAP_VTCORE_COLOR_FG; break; + case 49: bg = WSAP_VTCORE_COLOR_BG; break; case 53: t->overline = true; break; case 55: t->overline = false; break; case 59: t->cur_ul = 0; break; default: - if ((unsigned)(v - 30) < 8) fg = term_color_index(v - 30); - else if ((unsigned)(v - 40) < 8) bg = term_color_index(v - 40); - else if ((unsigned)(v - 90) < 8) fg = term_color_index(v - 90 + 8); - else if ((unsigned)(v - 100) < 8) bg = term_color_index(v - 100 + 8); + if ((unsigned)(v - 30) < 8) fg = wsap_vtcore_color_index(v - 30); + else if ((unsigned)(v - 40) < 8) bg = wsap_vtcore_color_index(v - 40); + else if ((unsigned)(v - 90) < 8) fg = wsap_vtcore_color_index(v - 90 + 8); + else if ((unsigned)(v - 100) < 8) bg = wsap_vtcore_color_index(v - 100 + 8); break; } } @@ -265,13 +265,13 @@ int term_try_fast_csi(struct term *t, const char *buf, size_t rem) case 'J': t->cur_fg = fg; t->cur_bg = bg; - term_screen_erase(t, pv[0]); + wsap_vtcore_screen_erase(t, pv[0]); p = q + 1; break; case 'K': t->cur_fg = fg; t->cur_bg = bg; - term_screen_erase_line(t, pv[0]); + wsap_vtcore_screen_erase_line(t, pv[0]); p = q + 1; break; case 'X': @@ -284,19 +284,19 @@ int term_try_fast_csi(struct term *t, const char *buf, size_t rem) case 'P': t->cur_fg = fg; t->cur_bg = bg; - term_screen_delete_chars(t, n); + wsap_vtcore_screen_delete_chars(t, n); p = q + 1; break; case '@': t->cur_fg = fg; t->cur_bg = bg; - term_screen_insert_chars(t, n); + wsap_vtcore_screen_insert_chars(t, n); p = q + 1; break; case 's': t->cur_fg = fg; t->cur_bg = bg; - t->saved = term_cursor_save(t); + t->saved = wsap_vtcore_cursor_save(t); p = q + 1; break; case 'u': @@ -325,8 +325,8 @@ tail: int avail = cols - t->cursor_x; int limit = end - p < (ptrdiff_t)avail ? (int)(end - p) : avail; int run = scan_ascii_run(p, limit); - if (TERM_EXPECT(!flags_ok, 0)) { - flags_pad = term_flags_pad(t); + if (WSAP_VTCORE_EXPECT(!flags_ok, 0)) { + flags_pad = wsap_vtcore_flags_pad(t); flags_ok = true; } if (!sc_ascii_fast(t, p, run, (struct text_pen){ fg, bg, flags_pad })) @@ -346,7 +346,7 @@ tail: if (p < end && *p == '\n') { t->cur_fg = fg; t->cur_bg = bg; - if (term_lnm(t)) sc_cr(t); + if (wsap_vtcore_lnm(t)) sc_cr(t); sc_linefeed(t, 1); p++; goto tail; diff --git a/src/gstore.c b/src/gstore.c index 813ea7d..a94af32 100644 --- a/src/gstore.c +++ b/src/gstore.c @@ -29,7 +29,7 @@ struct gslot { }; struct gstore { - struct term *term; + struct wsap_vtcore *term; uint32_t *arena; size_t arena_len; size_t arena_cap; @@ -68,15 +68,15 @@ static inline bool gentry_matches(const struct gstore *g, const struct gentry *e return !memcmp(&g->arena[e->offset], &cps[2], (size_t)(n - 2) * sizeof(*cps)); } -int term_gstore_expand(const struct gstore *g, uint32_t handle, uint32_t *cps, int cap) +int wsap_vtcore_gstore_expand(const struct gstore *g, uint32_t handle, uint32_t *cps, int cap) { if (cap <= 0) return 0; - if (!g || !term_grapheme_is_handle(handle)) { + if (!g || !wsap_vtcore_grapheme_is_handle(handle)) { cps[0] = handle; return 1; } - uint32_t idx = handle - TERM_GRAPHEME_HANDLE_BASE; + uint32_t idx = handle - WSAP_VTCORE_GRAPHEME_HANDLE_BASE; if (idx >= g->entries_count || !g->entries[idx].allocated) { cps[0] = 0xFFFD; return 1; @@ -124,8 +124,8 @@ static bool grow_slots(struct gstore *g) struct gentry *e = &g->entries[i]; if (!e->allocated) continue; - uint32_t cps_buf[TERM_GRAPHEME_MAX_LEN]; - int n = term_gstore_expand(g, TERM_GRAPHEME_HANDLE_BASE + i, cps_buf, TERM_GRAPHEME_MAX_LEN); + uint32_t cps_buf[WSAP_VTCORE_GRAPHEME_MAX_LEN]; + int n = wsap_vtcore_gstore_expand(g, WSAP_VTCORE_GRAPHEME_HANDLE_BASE + i, cps_buf, WSAP_VTCORE_GRAPHEME_MAX_LEN); uint64_t h = hash_cps(cps_buf, n); uint32_t h32 = (uint32_t)h ? (uint32_t)h : 1; gstore_insert_slot(g, h32, i); @@ -147,14 +147,14 @@ static uint32_t gstore_find(const struct gstore *g, const uint32_t *cps, int n, uint32_t e_idx = slot->entry_idx - 1; const struct gentry *e = &g->entries[e_idx]; if (e->allocated && gentry_matches(g, e, cps, n)) - return TERM_GRAPHEME_HANDLE_BASE + e_idx; + return WSAP_VTCORE_GRAPHEME_HANDLE_BASE + e_idx; } idx = (idx + 1) & mask; } return 0; } -struct gstore *term_gstore_new(struct term *t) +struct gstore *wsap_vtcore_gstore_new(struct wsap_vtcore *t) { struct gstore *g = calloc(1, sizeof(*g)); if (!g) @@ -164,7 +164,7 @@ struct gstore *term_gstore_new(struct term *t) return g; } -void term_gstore_free(struct gstore *g) +void wsap_vtcore_gstore_free(struct gstore *g) { if (!g) return; @@ -174,28 +174,28 @@ void term_gstore_free(struct gstore *g) free(g); } -uint32_t term_gstore_count(const struct gstore *g) +uint32_t wsap_vtcore_gstore_count(const struct gstore *g) { return g ? g->live_count : 0; } -void term_gstore_pin(struct gstore *g) +void wsap_vtcore_gstore_pin(struct gstore *g) { if (g) g->pin_depth++; } -void term_gstore_unpin(struct gstore *g) +void wsap_vtcore_gstore_unpin(struct gstore *g) { if (g && g->pin_depth > 0) g->pin_depth--; } -void term_gstore_mark(struct gstore *g, uint32_t handle) +void wsap_vtcore_gstore_mark(struct gstore *g, uint32_t handle) { - if (!g || !term_grapheme_is_handle(handle)) + if (!g || !wsap_vtcore_grapheme_is_handle(handle)) return; - uint32_t idx = handle - TERM_GRAPHEME_HANDLE_BASE; + uint32_t idx = handle - WSAP_VTCORE_GRAPHEME_HANDLE_BASE; if (idx < g->entries_count && g->entries[idx].allocated) g->entries[idx].mark = true; } @@ -204,19 +204,19 @@ static void sweep_mark_row(struct gstore *g, const struct cell *cells, int len) { for (int x = 0; x < len; x++) { uint32_t c = cells[x].c; - if (term_grapheme_is_handle(c)) - term_gstore_mark(g, c); + if (wsap_vtcore_grapheme_is_handle(c)) + wsap_vtcore_gstore_mark(g, c); } } -void term_gstore_sweep(struct gstore *g, struct term *t) +void wsap_vtcore_gstore_sweep(struct gstore *g, struct wsap_vtcore *t) { if (!g) return; if (t) { - if (term_grapheme_is_handle(t->last_char)) - term_gstore_mark(g, t->last_char); + if (wsap_vtcore_grapheme_is_handle(t->last_char)) + wsap_vtcore_gstore_mark(g, t->last_char); struct screen *s = &t->scr; for (int y = 0; y < s->rows; y++) { @@ -266,8 +266,8 @@ void term_gstore_sweep(struct gstore *g, struct term *t) live++; e->mark = false; if (g->slots) { - uint32_t cps_buf[TERM_GRAPHEME_MAX_LEN]; - int n = term_gstore_expand(g, TERM_GRAPHEME_HANDLE_BASE + i, cps_buf, TERM_GRAPHEME_MAX_LEN); + uint32_t cps_buf[WSAP_VTCORE_GRAPHEME_MAX_LEN]; + int n = wsap_vtcore_gstore_expand(g, WSAP_VTCORE_GRAPHEME_HANDLE_BASE + i, cps_buf, WSAP_VTCORE_GRAPHEME_MAX_LEN); uint64_t h = hash_cps(cps_buf, n); uint32_t h32 = (uint32_t)h ? (uint32_t)h : 1; gstore_insert_slot(g, h32, i); @@ -294,14 +294,14 @@ void term_gstore_sweep(struct gstore *g, struct term *t) g->sweep_threshold = 1024; } -uint32_t term_gstore_intern(struct gstore *g, const uint32_t *cps, int n) +uint32_t wsap_vtcore_gstore_intern(struct gstore *g, const uint32_t *cps, int n) { if (!g || n <= 0) return 0; if (n == 1) return cps[0]; - if (n > TERM_GRAPHEME_MAX_LEN) - n = TERM_GRAPHEME_MAX_LEN; + if (n > WSAP_VTCORE_GRAPHEME_MAX_LEN) + n = WSAP_VTCORE_GRAPHEME_MAX_LEN; uint64_t h = hash_cps(cps, n); uint32_t h32 = (uint32_t)h ? (uint32_t)h : 1; @@ -313,7 +313,7 @@ uint32_t term_gstore_intern(struct gstore *g, const uint32_t *cps, int n) if (g->term && g->pin_depth == 0 && (g->live_count >= g->sweep_threshold || g->live_count >= GSTORE_MAX_ENTRIES)) { - term_gstore_sweep(g, g->term); + wsap_vtcore_gstore_sweep(g, g->term); existing = gstore_find(g, cps, n, h32); if (existing) return existing; @@ -355,7 +355,7 @@ uint32_t term_gstore_intern(struct gstore *g, const uint32_t *cps, int n) if (n > 2) { size_t extra = (size_t)(n - 2); if (g->arena_len + extra > g->arena_cap) { - size_t new_cap = term_grow_cap(g->arena_cap ? g->arena_cap * 2 : 512, + size_t new_cap = wsap_vtcore_grow_cap(g->arena_cap ? g->arena_cap * 2 : 512, g->arena_len + extra); uint32_t *next = realloc(g->arena, new_cap * sizeof(*next)); if (!next) { @@ -375,5 +375,5 @@ uint32_t term_gstore_intern(struct gstore *g, const uint32_t *cps, int n) gstore_insert_slot(g, h32, entry_idx); g->live_count++; - return TERM_GRAPHEME_HANDLE_BASE + entry_idx; + return WSAP_VTCORE_GRAPHEME_HANDLE_BASE + entry_idx; } diff --git a/src/gstore.h b/src/gstore.h index 0cedd30..e4610ce 100644 --- a/src/gstore.h +++ b/src/gstore.h @@ -6,31 +6,31 @@ #include <stdint.h> struct gstore; -struct term; +struct wsap_vtcore; /* Create a grapheme store for a terminal. */ -struct gstore *term_gstore_new(struct term *t); +struct gstore *wsap_vtcore_gstore_new(struct wsap_vtcore *t); /* Free the grapheme store and its memory. */ -void term_gstore_free(struct gstore *g); +void wsap_vtcore_gstore_free(struct gstore *g); /* Store a cluster of code points. Return its handle. */ -uint32_t term_gstore_intern(struct gstore *g, const uint32_t *cps, int n); +uint32_t wsap_vtcore_gstore_intern(struct gstore *g, const uint32_t *cps, int n); /* Expand a handle to its code points. Return the count. */ -int term_gstore_expand(const struct gstore *g, uint32_t handle, uint32_t *cps, int cap); +int wsap_vtcore_gstore_expand(const struct gstore *g, uint32_t handle, uint32_t *cps, int cap); /* Mark reachable clusters and free unused ones. */ -void term_gstore_sweep(struct gstore *g, struct term *t); +void wsap_vtcore_gstore_sweep(struct gstore *g, struct wsap_vtcore *t); /* Mark one cluster handle as reachable. */ -void term_gstore_mark(struct gstore *g, uint32_t handle); +void wsap_vtcore_gstore_mark(struct gstore *g, uint32_t handle); /* Return the count of active clusters in the store. */ -uint32_t term_gstore_count(const struct gstore *g); +uint32_t wsap_vtcore_gstore_count(const struct gstore *g); /* Suppress automatic GC sweeps while temporary cell buffers hold handles. */ -void term_gstore_pin(struct gstore *g); -void term_gstore_unpin(struct gstore *g); +void wsap_vtcore_gstore_pin(struct gstore *g); +void wsap_vtcore_gstore_unpin(struct gstore *g); #endif @@ -42,7 +42,7 @@ #define ROWS_UNKNOWN 255 /* Bytes one cell can need, except a cluster. */ #define CELL_BYTES 5 -#define CLUSTER_BYTES (2 + TERM_GRAPHEME_MAX_LEN * 4) +#define CLUSTER_BYTES (2 + WSAP_VTCORE_GRAPHEME_MAX_LEN * 4) /* ---- Parts and pages ---- */ @@ -62,24 +62,24 @@ static inline struct hline *open_part(const struct hist *h) } /* Grow the ring so n more parts fit. The caller checks the fast path first. */ -static TERM_NOINLINE bool ring_grow(struct hist *h, uint64_t n) +static WSAP_VTCORE_NOINLINE bool ring_grow(struct hist *h, uint64_t n) { uint64_t cap = h->ring ? (uint64_t)h->ring_mask + 1 : 65536; if (cap < 65536) cap = 65536; - cap = term_grow_cap64(cap, h->head - h->tail + n); - struct hline *ring = term_aligned_alloc(64, (size_t)cap * sizeof(*ring)); + cap = wsap_vtcore_grow_cap64(cap, h->head - h->tail + n); + struct hline *ring = wsap_vtcore_aligned_alloc(64, (size_t)cap * sizeof(*ring)); if (!ring) return false; struct hist_block *blocks = calloc((size_t)cap / 16, sizeof(*blocks)); if (!blocks) { - term_aligned_free(ring); + wsap_vtcore_aligned_free(ring); return false; } uint32_t *exact = h->exact_rows ? calloc((size_t)cap, sizeof(*exact)) : NULL; if (h->exact_rows && !exact) { free(blocks); - term_aligned_free(ring); + wsap_vtcore_aligned_free(ring); return false; } for (uint64_t s = h->tail; s < h->head; s++) { @@ -89,7 +89,7 @@ static TERM_NOINLINE bool ring_grow(struct hist *h, uint64_t n) } free(h->exact_rows); h->exact_rows = exact; - term_aligned_free(h->ring); + wsap_vtcore_aligned_free(h->ring); free(h->blocks); h->blocks = blocks; h->ring = ring; @@ -101,7 +101,7 @@ static TERM_NOINLINE bool ring_grow(struct hist *h, uint64_t n) * keep it inline and leave only the rehash to a call. */ static inline bool ring_fit(struct hist *h, uint64_t n) { - if (TERM_EXPECT(h->ring && h->head - h->tail + n <= (uint64_t)h->ring_mask + 1, 1)) + if (WSAP_VTCORE_EXPECT(h->ring && h->head - h->tail + n <= (uint64_t)h->ring_mask + 1, 1)) return true; return ring_grow(h, n); } @@ -182,7 +182,7 @@ static inline bool line_valid(const struct hist *h, uint64_t id) return id >= h->base_id && id < h->base_id + h->lines; } -static TERM_ALWAYS_INLINE inline void page_drop_ref(struct hist *h, uint32_t pg) +static WSAP_VTCORE_ALWAYS_INLINE inline void page_drop_ref(struct hist *h, uint32_t pg) { if (--h->page_parts[pg] == 0) { if (pg == h->cur_page) @@ -196,7 +196,7 @@ static TERM_ALWAYS_INLINE inline void page_drop_ref(struct hist *h, uint32_t pg) static void rows_uncount(struct hist *h, uint64_t id) { if (id < h->rows_id) - h->counted_rows -= term_hist_line_estimate(h, id, h->wrap_cols); + h->counted_rows -= wsap_vtcore_hist_line_estimate(h, id, h->wrap_cols); } static void line_gone(struct hist *h) @@ -244,7 +244,7 @@ static bool evict_part(struct hist *h) return true; } -static TERM_NOINLINE void evict_line_parts(struct hist *h) +static WSAP_VTCORE_NOINLINE void evict_line_parts(struct hist *h) { uint64_t end = line_end(h, h->tail); if (part(h, end - 1)->flags & HLINE_OPEN) @@ -272,8 +272,8 @@ static inline void page_drop_n(struct hist *h, uint32_t pg, uint32_t n) } } -#if defined(TERM_KERNEL_AVX512) -TERM_TARGET_AVX512 +#if defined(WSAP_VTCORE_KERNEL_AVX512) +WSAP_VTCORE_TARGET_AVX512 static inline bool same_page_narrow_rows_avx512(const struct hline *p, uint32_t page) { const __m512i pg = _mm512_set1_epi32((int)(page << 16)); @@ -289,8 +289,8 @@ static inline bool same_page_narrow_rows_avx512(const struct hline *p, uint32_t } #endif -#if defined(TERM_KERNEL_AVX2) -TERM_TARGET_AVX2 +#if defined(WSAP_VTCORE_KERNEL_AVX2) +WSAP_VTCORE_TARGET_AVX2 static inline bool same_page_narrow_rows_avx2(const struct hline *p, uint32_t page) { const __m256i pg = _mm256_set1_epi32((int)(page << 16)); @@ -309,12 +309,12 @@ static inline bool same_page_narrow_rows_avx2(const struct hline *p, uint32_t pa /* Check 16 narrow rows. Each descriptor has four words. */ static inline bool same_page_narrow_rows(const struct hline *p, uint32_t page) { -#if defined(TERM_KERNEL_AVX512) - if (term_use_avx512()) +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (wsap_vtcore_use_avx512()) return same_page_narrow_rows_avx512(p, page); #endif -#if defined(TERM_KERNEL_AVX2) - if (term_use_avx2()) +#if defined(WSAP_VTCORE_KERNEL_AVX2) + if (wsap_vtcore_use_avx2()) return same_page_narrow_rows_avx2(p, page); #endif #if defined(__aarch64__) @@ -336,8 +336,8 @@ static inline bool same_page_narrow_rows(const struct hline *p, uint32_t page) #endif } -#if defined(TERM_KERNEL_AVX512) -TERM_TARGET_AVX512 +#if defined(WSAP_VTCORE_KERNEL_AVX512) +WSAP_VTCORE_TARGET_AVX512 static inline bool same_page_rows_64(const struct hline *p, uint32_t page, uint32_t *text_count, uint32_t *row_count) { @@ -352,7 +352,7 @@ static inline bool same_page_rows_64(const struct hline *p, uint32_t page, for (int i = 0; i < 64; i += 4) { __m512i v = _mm512_loadu_si512((const void *)(p + i)); __mmask16 empty = _mm512_cmpeq_epi32_mask(v, no_text) & 0x1111; - blanks += term_popcount32(empty); + blanks += wsap_vtcore_popcount32(empty); tag_fail |= (_mm512_test_epi32_mask(v, open) | _mm512_cmpeq_epi32_mask(_mm512_and_si512(v, unknown), unknown)) & 0x8888; pg_fail |= (uint16_t)(~(_mm512_cmpeq_epi32_mask(_mm512_and_si512(v, mask), pg) | empty) & 0x1111); @@ -400,8 +400,8 @@ static uint64_t evict_simple_run(struct hist *h, uint64_t k) continue; } } -#if defined(TERM_KERNEL_AVX512) - if (term_use_avx512() && (tail & 63) == 0 && n + 64 <= k && tail + 64 <= head && +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (wsap_vtcore_use_avx512() && (tail & 63) == 0 && n + 64 <= k && tail + 64 <= head && ((tail & rmask) + 64 <= rmask + 1)) { const struct hline *f = &ring[tail & rmask]; @@ -463,7 +463,7 @@ static uint64_t evict_simple_run(struct hist *h, uint64_t k) uint32_t or_all = t0 | t1 | t2 | t3 | t4 | t5 | t6 | t7 | t8 | t9 | t10 | t11 | t12 | t13 | t14 | t15; - if (TERM_EXPECT((or_all & 0x0030ffff) == 0 && + if (WSAP_VTCORE_EXPECT((or_all & 0x0030ffff) == 0 && (t0 >> 24) != 255 && (t1 >> 24) != 255 && (t2 >> 24) != 255 && (t3 >> 24) != 255 && (t4 >> 24) != 255 && (t5 >> 24) != 255 && (t6 >> 24) != 255 && (t7 >> 24) != 255 && (t8 >> 24) != 255 && (t9 >> 24) != 255 && (t10 >> 24) != 255 && (t11 >> 24) != 255 && @@ -568,16 +568,16 @@ static inline void evict_for(struct hist *h, uint64_t n) } /* Drop the oldest line with all its parts. It is never the open line. */ -static inline TERM_ALWAYS_INLINE void evict_line(struct hist *h) +static inline WSAP_VTCORE_ALWAYS_INLINE void evict_line(struct hist *h) { if (h->tail == h->head) return; const struct hline *f = part(h, h->tail); - if (TERM_EXPECT(!(f->flags & HLINE_OPEN) && + if (WSAP_VTCORE_EXPECT(!(f->flags & HLINE_OPEN) && (h->tail + 1 == h->head || !(part(h, h->tail + 1)->flags & HLINE_CONT)), 1)) { if (h->base_id < h->rows_id) h->counted_rows -= f->wrap_rows != ROWS_UNKNOWN - ? f->wrap_rows : term_hist_line_estimate(h, h->base_id, h->wrap_cols); + ? f->wrap_rows : wsap_vtcore_hist_line_estimate(h, h->base_id, h->wrap_cols); if (f->off != NO_TEXT) page_drop_ref(h, f->off >> 16); h->tail++; @@ -587,7 +587,7 @@ static inline TERM_ALWAYS_INLINE void evict_line(struct hist *h) evict_line_parts(h); } -static TERM_NOINLINE int page_next(struct hist *h) +static WSAP_VTCORE_NOINLINE int page_next(struct hist *h) { for (;;) { if (h->nfree) { @@ -597,7 +597,7 @@ static TERM_NOINLINE int page_next(struct hist *h) return (int)pg; } if (h->npages < h->max_pages) { - uint8_t *page = term_aligned_alloc(64, HIST_PAGE_SIZE); + uint8_t *page = wsap_vtcore_aligned_alloc(64, HIST_PAGE_SIZE); if (!page) return -1; uint32_t pg = h->npages++; @@ -620,7 +620,7 @@ static inline int page_for(struct hist *h, size_t need) if (need > HIST_PAGE_USABLE) return -1; uint32_t pg = h->cur_page; - if (TERM_EXPECT(pg < h->npages && h->page_used[pg] + need <= HIST_PAGE_USABLE, 1)) + if (WSAP_VTCORE_EXPECT(pg < h->npages && h->page_used[pg] + need <= HIST_PAGE_USABLE, 1)) return (int)pg; return page_next(h); } @@ -629,12 +629,12 @@ static inline int page_for(struct hist *h, size_t need) static inline int put_varint(uint8_t *p, uint32_t v) { - if (TERM_EXPECT(v < 0x80, 1)) { + if (WSAP_VTCORE_EXPECT(v < 0x80, 1)) { p[0] = (uint8_t)v; return 1; } p[0] = (uint8_t)(v | 0x80); - if (TERM_EXPECT(v < 0x4000, 1)) { + if (WSAP_VTCORE_EXPECT(v < 0x4000, 1)) { p[1] = (uint8_t)(v >> 7); return 2; } @@ -656,12 +656,12 @@ static inline int put_varint(uint8_t *p, uint32_t v) static inline int get_varint(const uint8_t *p, uint32_t *v) { uint8_t b0 = p[0]; - if (TERM_EXPECT((b0 & 0x80) == 0, 1)) { + if (WSAP_VTCORE_EXPECT((b0 & 0x80) == 0, 1)) { *v = b0; return 1; } uint8_t b1 = p[1]; - if (TERM_EXPECT((b1 & 0x80) == 0, 1)) { + if (WSAP_VTCORE_EXPECT((b1 & 0x80) == 0, 1)) { *v = (uint32_t)(b0 & 0x7f) | ((uint32_t)b1 << 7); return 2; } @@ -691,7 +691,7 @@ static inline uint8_t *emit_run(uint8_t *p, const struct pen_attr *base, const s uint32_t count) { /* Most runs change only colors and cover fewer than 128 cells. */ - if (TERM_EXPECT(count < 0x80 && pen_sl(pen) == pen_sl(base), 1)) { + if (WSAP_VTCORE_EXPECT(count < 0x80 && pen_sl(pen) == pen_sl(base), 1)) { uint32_t dfg = pen->fg != base->fg, dbg = pen->bg != base->bg; p[0] = (uint8_t)(dfg | (dbg << 1)); p[1] = (uint8_t)count; @@ -727,9 +727,9 @@ static inline const uint8_t *read_run(const uint8_t *p, struct pen_attr *pen, ui static bool runs_reserve(struct hist_runs *r, size_t extra) { - if (TERM_EXPECT(r->len + extra <= r->cap, 1)) + if (WSAP_VTCORE_EXPECT(r->len + extra <= r->cap, 1)) return true; - size_t cap = term_grow_cap(r->cap ? r->cap : 256, (size_t)r->len + extra); + size_t cap = wsap_vtcore_grow_cap(r->cap ? r->cap : 256, (size_t)r->len + extra); uint8_t *data = realloc(r->data, cap); if (!data) return false; @@ -746,7 +746,7 @@ static inline void runs_reset(struct hist_runs *r) r->count = 0; } -void term_hist_runs_emit_slow(struct hist_runs *r) +void wsap_vtcore_hist_runs_emit_slow(struct hist_runs *r) { r->len = (uint32_t)(emit_run(r->data + r->len, &r->base, &r->pen, r->count) - r->data); } @@ -812,11 +812,11 @@ struct enc { uint16_t wide; }; -#if defined(TERM_KERNEL_AVX512) +#if defined(WSAP_VTCORE_KERNEL_AVX512) /* The prefix of cells where (lane & keep) - target <= span holds in every * lane. Their code points go to dst as bytes. Eight cells per step; the * last step uses masked loads. */ -TERM_TARGET_AVX512 +WSAP_VTCORE_TARGET_AVX512 static inline int narrow_prefix_avx512(const struct cell *cells, int len, uint8_t *dst, __m512i keep, __m512i target, __m512i span) { @@ -834,7 +834,7 @@ static inline int narrow_prefix_avx512(const struct cell *cells, int len, uint8_ if (ok0 != m0 || ok1 != m1) { /* Keep the cells before the first failing one. */ uint32_t bad = (uint32_t)(~ok0 & m0) | ((uint32_t)(~ok1 & m1) << 16); - int good = term_ctz32(bad) / 4; + int good = wsap_vtcore_ctz32(bad) / 4; _mm_mask_storeu_epi8(dst + k, (__mmask16)((1u << good) - 1), _mm512_cvtepi32_epi8(cp)); return k + good; } @@ -846,7 +846,7 @@ static inline int narrow_prefix_avx512(const struct cell *cells, int len, uint8_ return len; } -TERM_TARGET_AVX512 +WSAP_VTCORE_TARGET_AVX512 static inline int narrow_any_pen_prefix_avx512(const struct cell *cells, int len, uint8_t *dst) { const __m512i keep = _mm512_setr_epi32(-1, 0, 0, SHAPE_FLAGS, -1, 0, 0, SHAPE_FLAGS, @@ -856,7 +856,7 @@ static inline int narrow_any_pen_prefix_avx512(const struct cell *cells, int len return narrow_prefix_avx512(cells, len, dst, keep, target, span); } -TERM_TARGET_AVX512 +WSAP_VTCORE_TARGET_AVX512 static inline int narrow_uniform_prefix_avx512(const struct cell *cells, int len, uint8_t *dst) { uint32_t sl = (uint32_t)(cells[0].flags & STYLE_FLAGS) | ((uint32_t)cells[0].pad << 16); @@ -875,8 +875,8 @@ static inline int narrow_uniform_prefix_avx512(const struct cell *cells, int len * to dst. */ static inline int narrow_any_pen_prefix(const struct cell *cells, int len, uint8_t *dst) { -#if defined(TERM_KERNEL_AVX512) - if (term_use_avx512()) +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (wsap_vtcore_use_avx512()) return narrow_any_pen_prefix_avx512(cells, len, dst); #endif int k = 0; @@ -890,7 +890,7 @@ static inline int narrow_any_pen_prefix(const struct cell *cells, int len, uint8 /* Add the pens of n cells to r, one run per change. Cells carry no * underline color, so no pen here has one. */ -static TERM_NOINLINE uint32_t runs_scan(struct hist_runs *r, const struct cell *cells, int n) +static WSAP_VTCORE_NOINLINE uint32_t runs_scan(struct hist_runs *r, const struct cell *cells, int n) { uint32_t links = 0; uint32_t pfg = r->pen.fg, pbg = r->pen.bg; @@ -903,13 +903,13 @@ static TERM_NOINLINE uint32_t runs_scan(struct hist_runs *r, const struct cell * const struct cell *c = &cells[i]; uint32_t sl = (uint32_t)(c->flags & STYLE_FLAGS) | ((uint32_t)c->pad << 16); links |= c->pad; - if (TERM_EXPECT(((c->fg ^ pfg) | (c->bg ^ pbg) | (sl ^ psl)) != 0, 0)) { + if (WSAP_VTCORE_EXPECT(((c->fg ^ pfg) | (c->bg ^ pbg) | (sl ^ psl)) != 0, 0)) { if (count) { uint32_t header = (pfg != bfg ? RUN_FG : 0) | (pbg != bbg ? RUN_BG : 0) | ((uint16_t)psl != (uint16_t)bsl ? RUN_ATTR : 0) | ((psl >> 16) != (bsl >> 16) ? RUN_LINK : 0); rp[0] = (uint8_t)header; - if (TERM_EXPECT(count < 0x80, 1)) { + if (WSAP_VTCORE_EXPECT(count < 0x80, 1)) { rp[1] = (uint8_t)count; rp += 2; } else { @@ -919,7 +919,7 @@ static TERM_NOINLINE uint32_t runs_scan(struct hist_runs *r, const struct cell * rp += (header & RUN_FG) ? 4 : 0; put_u32(rp, pbg); rp += (header & RUN_BG) ? 4 : 0; - if (TERM_EXPECT(header & (RUN_ATTR | RUN_LINK), 0)) { + if (WSAP_VTCORE_EXPECT(header & (RUN_ATTR | RUN_LINK), 0)) { if (header & RUN_ATTR) { put_u16(rp, (uint16_t)psl); rp += 2; } if (header & RUN_LINK) { put_u16(rp, (uint16_t)(psl >> 16)); rp += 2; } } @@ -945,8 +945,8 @@ static TERM_NOINLINE uint32_t runs_scan(struct hist_runs *r, const struct cell * * Their bytes go to dst. */ static inline int narrow_uniform_prefix(const struct cell *cells, int len, uint8_t *dst) { -#if defined(TERM_KERNEL_AVX512) - if (term_use_avx512()) +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (wsap_vtcore_use_avx512()) return narrow_uniform_prefix_avx512(cells, len, dst); #endif uint32_t sl = (uint32_t)(cells[0].flags & STYLE_FLAGS) | ((uint32_t)cells[0].pad << 16); @@ -961,11 +961,11 @@ static inline int narrow_uniform_prefix(const struct cell *cells, int len, uint8 return k; } -#if defined(TERM_KERNEL_AVX512) +#if defined(WSAP_VTCORE_KERNEL_AVX512) /* Encode a prefix of cells with the pen of cells[0] and no clusters, eight * cells at a time. Return the cells used; runcells counts the cells that * are not trail cells. */ -TERM_TARGET_AVX512 +WSAP_VTCORE_TARGET_AVX512 static int uniform_utf8_prefix(const struct cell *cells, int len, uint8_t *dst, struct enc *o, uint32_t *runcells) { @@ -1019,11 +1019,11 @@ static int uniform_utf8_prefix(const struct cell *cells, int len, uint8_t *dst, bm = _mm256_maskz_mov_epi32((__mmask8)~m_trail, bm); __mmask32 keep_bytes = _mm256_movepi8_mask(bm); _mm256_storeu_si256((__m256i *)(void *)(dst + bytes), _mm256_maskz_compress_epi8(keep_bytes, w)); - bytes += (uint32_t)term_popcount32(keep_bytes); - uint32_t trails = (uint32_t)term_popcount32(m_trail); - ncells += 8u - trails + (uint32_t)term_popcount32(m_wide); + bytes += (uint32_t)wsap_vtcore_popcount32(keep_bytes); + uint32_t trails = (uint32_t)wsap_vtcore_popcount32(m_trail); + ncells += 8u - trails + (uint32_t)wsap_vtcore_popcount32(m_wide); *runcells += 8u - trails; - nwide += (uint32_t)term_popcount32(m_wide); + nwide += (uint32_t)wsap_vtcore_popcount32(m_wide); wide |= m_wide; ascii &= (uint32_t)(uint8_t)~(ge80 & ~m_trail); } @@ -1036,11 +1036,11 @@ static int uniform_utf8_prefix(const struct cell *cells, int len, uint8_t *dst, } #endif -static TERM_NOINLINE size_t encode_cluster(uint8_t *dst, const struct gstore *g, +static WSAP_VTCORE_NOINLINE size_t encode_cluster(uint8_t *dst, const struct gstore *g, uint32_t handle, uint16_t f) { - uint32_t cps[TERM_GRAPHEME_MAX_LEN]; - int n = term_gstore_expand(g, handle, cps, TERM_GRAPHEME_MAX_LEN); + uint32_t cps[WSAP_VTCORE_GRAPHEME_MAX_LEN]; + int n = wsap_vtcore_gstore_expand(g, handle, cps, WSAP_VTCORE_GRAPHEME_MAX_LEN); size_t b = 0; dst[b++] = PREFIX_CLUSTER; dst[b++] = (uint8_t)((n & 0x1f) | ((f & CELL_WIDE) ? 0x80 : 0) | @@ -1053,7 +1053,7 @@ static TERM_NOINLINE size_t encode_cluster(uint8_t *dst, const struct gstore *g, static size_t encode_shaped(uint8_t *dst, uint32_t cp, uint16_t f, const struct gstore *g, uint8_t *flags) { - if (term_grapheme_is_handle(cp)) { + if (wsap_vtcore_grapheme_is_handle(cp)) { *flags |= HLINE_HAS_CLUSTER | ((f & CELL_WIDE) ? HLINE_HAS_WIDE : 0); return encode_cluster(dst, g, cp, f); } @@ -1118,8 +1118,8 @@ static int encode_cells(struct hist_runs *r, const struct cell *cells, int n, ui *o = (struct enc){ .bytes = (uint32_t)i, .cells = (uint32_t)i, .flags = (uint8_t)(HLINE_NARROW | (c0->pad ? HLINE_HAS_LINK : 0)) }; } -#if defined(TERM_KERNEL_AVX512) - if (term_use_avx512() && n - i >= 8 && ((cells[i].flags & SHAPE_FLAGS) || cells[i].c >= 0x80)) { +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (wsap_vtcore_use_avx512() && n - i >= 8 && ((cells[i].flags & SHAPE_FLAGS) || cells[i].c >= 0x80)) { /* Text with one pen, eight cells per step. */ struct enc u; uint32_t runcells = 0; @@ -1155,18 +1155,18 @@ static int encode_cells(struct hist_runs *r, const struct cell *cells, int n, ui continue; uint32_t cp = c->c; bool simple = !(f & (CELL_WIDE | CELL_EMOJI | CELL_TEXT)) && cp - 0x20u < 0x60u; - if (!simple && term_grapheme_is_handle(cp) && + if (!simple && wsap_vtcore_grapheme_is_handle(cp) && bytes + CLUSTER_BYTES + (size_t)(n - i) * CELL_BYTES > cap) break; uint32_t sl = (uint32_t)(f & STYLE_FLAGS) | ((uint32_t)c->pad << 16); links |= c->pad; - if (TERM_EXPECT(((c->fg ^ pfg) | (c->bg ^ pbg) | (sl ^ psl)) != 0, 0)) { + if (WSAP_VTCORE_EXPECT(((c->fg ^ pfg) | (c->bg ^ pbg) | (sl ^ psl)) != 0, 0)) { if (count) { uint32_t header = (pfg != bfg ? RUN_FG : 0) | (pbg != bbg ? RUN_BG : 0) | ((uint16_t)psl != (uint16_t)bsl ? RUN_ATTR : 0) | ((psl >> 16) != (bsl >> 16) ? RUN_LINK : 0); *rp++ = (uint8_t)header; - if (TERM_EXPECT(count < 0x80, 1)) + if (WSAP_VTCORE_EXPECT(count < 0x80, 1)) *rp++ = (uint8_t)count; else rp += put_varint(rp, count); @@ -1174,7 +1174,7 @@ static int encode_cells(struct hist_runs *r, const struct cell *cells, int n, ui rp += (header & RUN_FG) ? 4 : 0; put_u32(rp, pbg); rp += (header & RUN_BG) ? 4 : 0; - if (TERM_EXPECT(header & (RUN_ATTR | RUN_LINK), 0)) { + if (WSAP_VTCORE_EXPECT(header & (RUN_ATTR | RUN_LINK), 0)) { if (header & RUN_ATTR) { put_u16(rp, (uint16_t)psl); rp += 2; } if (header & RUN_LINK) { put_u16(rp, (uint16_t)(psl >> 16)); rp += 2; } } @@ -1189,7 +1189,7 @@ static int encode_cells(struct hist_runs *r, const struct cell *cells, int n, ui } count++; nwide += (f & CELL_WIDE) != 0; - if (TERM_EXPECT(simple, 1)) { + if (WSAP_VTCORE_EXPECT(simple, 1)) { dst[bytes++] = (uint8_t)cp; ncells++; continue; @@ -1408,7 +1408,7 @@ static void close_part(struct hist *h, struct hline *p) p->flags &= (uint8_t)~HLINE_OPEN; } -void term_hist_close_open_line(struct hist *h) +void wsap_vtcore_hist_close_open_line(struct hist *h) { struct hline *p = open_part(h); if (!p) @@ -1424,7 +1424,7 @@ void term_hist_close_open_line(struct hist *h) uint64_t first = line_first(h, id); uint64_t rows = first == h->head - 1 ? cheap_rows(p->cells, p->wide, cols) - : cheap_rows(term_hist_line_cells(h, id), term_hist_line_wide(h, id), cols); + : cheap_rows(wsap_vtcore_hist_line_cells(h, id), wsap_vtcore_hist_line_wide(h, id), cols); if (!rows && h->walk_on) { walk_advance(h); rows = h->walk_rows; @@ -1440,7 +1440,7 @@ static struct hline *open_room(struct hist *h, struct hline *p, size_t text_need { uint32_t start = p->off & 0xffff; size_t runs = h->runs.len + runs_need + RUN_MAX; - if (TERM_EXPECT(start + p->text_len + text_need + runs <= HIST_PAGE_USABLE && + if (WSAP_VTCORE_EXPECT(start + p->text_len + text_need + runs <= HIST_PAGE_USABLE && p->cells + add_cells <= HIST_MAX_PART_CELLS && runs <= UINT16_MAX, 1)) return p; @@ -1547,7 +1547,7 @@ static inline void part_add(struct hist *h, struct hline *p, const struct enc *e h->page_used[p->off >> 16] = (p->off & 0xffff) + p->text_len; } -void term_hist_push_row(struct hist *h, const struct cell *cells, int len, bool wrapped, +void wsap_vtcore_hist_push_row(struct hist *h, const struct cell *cells, int len, bool wrapped, const struct gstore *g) { if (!h->line_limit) @@ -1555,7 +1555,7 @@ void term_hist_push_row(struct hist *h, const struct cell *cells, int len, bool struct hline *p = open_part(h); if (!p) { if (len <= 0 && !wrapped) { - term_hist_push_blank(h, 1); + wsap_vtcore_hist_push_blank(h, 1); return; } if (!wrapped && push_uniform_line(h, cells, len)) @@ -1582,12 +1582,12 @@ void term_hist_push_row(struct hist *h, const struct cell *cells, int len, bool return; } if (!wrapped) - term_hist_close_open_line(h); + wsap_vtcore_hist_close_open_line(h); else if (h->wrap_cols && (h->walk_on || (p->flags & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER)))) walk_advance(h); } -void term_hist_push_ascii(struct hist *h, const char *bytes, int n, const struct pen_attr *pen, +void wsap_vtcore_hist_push_ascii(struct hist *h, const char *bytes, int n, const struct pen_attr *pen, bool wrapped) { if (!h->line_limit) @@ -1598,7 +1598,7 @@ void term_hist_push_ascii(struct hist *h, const char *bytes, int n, const struct struct hline *p = open_part(h); if (!p) { if (n <= 0 && !wrapped) { - term_hist_push_blank(h, 1); + wsap_vtcore_hist_push_blank(h, 1); return; } /* A default-pen line: one copy and one descriptor. */ @@ -1643,7 +1643,7 @@ void term_hist_push_ascii(struct hist *h, const char *bytes, int n, const struct n -= chunk; } if (!wrapped) - term_hist_close_open_line(h); + wsap_vtcore_hist_close_open_line(h); else if (h->wrap_cols && h->walk_on) walk_advance(h); } @@ -1663,7 +1663,7 @@ static void text_row_readd(struct hist *h, const struct text_row *row) hist_runs_add(&h->runs, &rr->pen, rr->count); } -void term_hist_push_text(struct hist *h, const struct text_row *row, bool wrapped) +void wsap_vtcore_hist_push_text(struct hist *h, const struct text_row *row, bool wrapped) { if (!h->line_limit) return; @@ -1672,7 +1672,7 @@ void term_hist_push_text(struct hist *h, const struct text_row *row, bool wrappe size_t runs_need = (size_t)rr->len * RUN_MAX / 2 + 2 * RUN_MAX; if (!p) { if (row->cells == 0 && !wrapped) { - term_hist_push_blank(h, 1); + wsap_vtcore_hist_push_blank(h, 1); return; } if (!wrapped && pen_attr_is_default(&row->start)) { @@ -1738,7 +1738,7 @@ void term_hist_push_text(struct hist *h, const struct text_row *row, bool wrappe } part_add(h, p, &(struct enc){ row->text_len, row->cells, row->flags, row->wide }); if (!wrapped) - term_hist_close_open_line(h); + wsap_vtcore_hist_close_open_line(h); else if (h->wrap_cols && (h->walk_on || (p->flags & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER)))) walk_advance(h); } @@ -1754,8 +1754,8 @@ struct hist_stream_state { /* Write the narrow descriptors of ends[i..stop) in blocks, while a block * fits before the ring wraps. Return the first line left for the caller. */ -#if defined(TERM_KERNEL_AVX512) -TERM_TARGET_AVX512 +#if defined(WSAP_VTCORE_KERNEL_AVX512) +WSAP_VTCORE_TARGET_AVX512 static int lf_rows_avx512(struct hist *restrict h, const uint16_t *restrict ends, int i, int stop, uint32_t cols, struct hist_stream_state *state) { @@ -1771,7 +1771,7 @@ static int lf_rows_avx512(struct hist *restrict h, const uint16_t *restrict ends __m512i end = _mm512_cvtepu16_epi32(_mm256_loadu_si256((const __m256i *)(ends + i + 1))); __m512i lens = _mm512_sub_epi32(_mm512_sub_epi32(end, start), _mm512_set1_epi32(1)); __mmask16 empty = _mm512_cmpeq_epi32_mask(lens, _mm512_setzero_si512()); - uint32_t refs = 16 - term_popcount32(empty); + uint32_t refs = 16 - wsap_vtcore_popcount32(empty); text_count += refs; __m512i offsets = _mm512_mask_mov_epi32(_mm512_add_epi32(start, _mm512_set1_epi32((int)base)), empty, _mm512_set1_epi32(-1)); @@ -1821,8 +1821,8 @@ static int lf_rows_avx512(struct hist *restrict h, const uint16_t *restrict ends } #endif -#if defined(TERM_KERNEL_AVX2) -TERM_TARGET_AVX2 +#if defined(WSAP_VTCORE_KERNEL_AVX2) +WSAP_VTCORE_TARGET_AVX2 static int lf_rows_avx2(struct hist *restrict h, const uint16_t *restrict ends, int i, int stop, uint32_t cols, struct hist_stream_state *state) { @@ -1841,7 +1841,7 @@ static int lf_rows_avx2(struct hist *restrict h, const uint16_t *restrict ends, __m128i end = _mm_cvtepu16_epi32(_mm_loadl_epi64((const __m128i *)(ends + i + 1))); __m128i lens = _mm_sub_epi32(_mm_sub_epi32(end, start), _mm_set1_epi32(1)); __m128i empty = _mm_cmpeq_epi32(lens, _mm_setzero_si128()); - refs = 4 - term_popcount32((unsigned)_mm_movemask_ps(_mm_castsi128_ps(empty))); + refs = 4 - wsap_vtcore_popcount32((unsigned)_mm_movemask_ps(_mm_castsi128_ps(empty))); __m128i offsets = _mm_or_si128(_mm_add_epi32(start, _mm_set1_epi32((int)base)), empty); __m128i rs = _mm_set1_epi32(1); if (cols == 1) rs = _mm_max_epu32(lens, rs); @@ -1883,12 +1883,12 @@ static int lf_rows_avx2(struct hist *restrict h, const uint16_t *restrict ends, static inline int lf_rows(struct hist *restrict h, const uint16_t *restrict ends, int i, int stop, uint32_t cols, struct hist_stream_state *state) { -#if defined(TERM_KERNEL_AVX512) - if (term_use_avx512()) +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (wsap_vtcore_use_avx512()) return lf_rows_avx512(h, ends, i, stop, cols, state); #endif -#if defined(TERM_KERNEL_AVX2) - if (term_use_avx2()) +#if defined(WSAP_VTCORE_KERNEL_AVX2) + if (wsap_vtcore_use_avx2()) return lf_rows_avx2(h, ends, i, stop, cols, state); #endif #if defined(__aarch64__) @@ -1949,14 +1949,14 @@ static inline int lf_rows(struct hist *restrict h, const uint16_t *restrict ends return i; } -TERM_NOINLINE -void term_hist_push_ascii_lf(struct hist *restrict h, const char *restrict bytes, +WSAP_VTCORE_NOINLINE +void wsap_vtcore_hist_push_ascii_lf(struct hist *restrict h, const char *restrict bytes, const uint16_t *restrict ends, int count) { if (!h->line_limit) return; int i = 0; if (count && hist_is_open(h)) { - term_hist_push_ascii(h, bytes + ends[0], ends[1] - ends[0] - 1, NULL, false); + wsap_vtcore_hist_push_ascii(h, bytes + ends[0], ends[1] - ends[0] - 1, NULL, false); i++; } uint32_t cols = h->wrap_cols ? h->wrap_cols : 1; @@ -2034,8 +2034,8 @@ static_assert(offsetof(struct hist_ascii_line, len) == 8, "len is in the second /* Write the narrow one-row descriptors of lines[i..stream_end) in blocks, * while a block fits before the ring wraps. first is the first byte of * the page copy at base. Return the first line left for the caller. */ -#if defined(TERM_KERNEL_AVX512) -TERM_TARGET_AVX512 +#if defined(WSAP_VTCORE_KERNEL_AVX512) +WSAP_VTCORE_TARGET_AVX512 static int stream_lines_avx512(struct hist *restrict h, const struct hist_ascii_line *lines, int i, int stream_end, struct hist_stream_state *state) { @@ -2065,7 +2065,7 @@ static int stream_lines_avx512(struct hist *restrict h, const struct hist_ascii_ _mm512_inserti64x4(_mm512_castsi256_si512(lo), hi, 1), _mm512_set1_epi32(UINT16_MAX)); __mmask16 empty = _mm512_cmpeq_epi32_mask(lens, _mm512_setzero_si512()); - uint32_t refs = 16 - term_popcount32(empty); + uint32_t refs = 16 - wsap_vtcore_popcount32(empty); text_count += refs; offsets = _mm512_mask_mov_epi32(offsets, empty, _mm512_set1_epi32(-1)); __m512i tags = _mm512_set1_epi32((1u << 24) | (HLINE_NARROW << 16)); @@ -2099,8 +2099,8 @@ static int stream_lines_avx512(struct hist *restrict h, const struct hist_ascii_ } #endif -#if defined(TERM_KERNEL_AVX2) -TERM_TARGET_AVX2 +#if defined(WSAP_VTCORE_KERNEL_AVX2) +WSAP_VTCORE_TARGET_AVX2 static int stream_lines_avx2(struct hist *restrict h, const struct hist_ascii_line *lines, int i, int stream_end, struct hist_stream_state *state) { @@ -2118,7 +2118,7 @@ static int stream_lines_avx2(struct hist *restrict h, const struct hist_ascii_li _mm_i32gather_epi32((const int *)((const char *)(lines + i) + 8), index, 1), _mm_set1_epi32(UINT16_MAX)); __m128i empty = _mm_cmpeq_epi32(lens, _mm_setzero_si128()); - refs = 4 - term_popcount32((unsigned)_mm_movemask_ps(_mm_castsi128_ps(empty))); + refs = 4 - wsap_vtcore_popcount32((unsigned)_mm_movemask_ps(_mm_castsi128_ps(empty))); __m128i offsets = _mm_add_epi32(ptrs, _mm_set1_epi32((int)(base - (uint32_t)(uintptr_t)first))); offsets = _mm_or_si128(offsets, empty); @@ -2142,12 +2142,12 @@ static int stream_lines_avx2(struct hist *restrict h, const struct hist_ascii_li static inline int stream_lines(struct hist *restrict h, const struct hist_ascii_line *lines, int i, int stream_end, struct hist_stream_state *state) { -#if defined(TERM_KERNEL_AVX512) - if (term_use_avx512()) +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (wsap_vtcore_use_avx512()) return stream_lines_avx512(h, lines, i, stream_end, state); #endif -#if defined(TERM_KERNEL_AVX2) - if (term_use_avx2()) +#if defined(WSAP_VTCORE_KERNEL_AVX2) + if (wsap_vtcore_use_avx2()) return stream_lines_avx2(h, lines, i, stream_end, state); #endif #if defined(__aarch64__) @@ -2179,7 +2179,7 @@ static inline int stream_lines(struct hist *restrict h, const struct hist_ascii_ return i; } -void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *lines, int count, +void wsap_vtcore_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *lines, int count, const struct pen_attr *pen) { if (!h->line_limit) @@ -2196,15 +2196,15 @@ void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *li lines[end].len <= INT32_MAX - bytes) { bytes += lines[end++].len; } - term_hist_push_ascii(h, l->ptr, bytes, pen, true); + wsap_vtcore_hist_push_ascii(h, l->ptr, bytes, pen, true); i = end; continue; } if (!def || hist_is_open(h)) { if (l->len == 0 && !l->wrapped) - term_hist_push_blank(h, 1); + wsap_vtcore_hist_push_blank(h, 1); else - term_hist_push_ascii(h, l->ptr, l->len, pen, l->wrapped); + wsap_vtcore_hist_push_ascii(h, l->ptr, l->len, pen, l->wrapped); i++; continue; } @@ -2230,7 +2230,7 @@ void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *li size_t span = (size_t)(next->ptr - l->ptr) + next->len; if (span > room) break; - if (TERM_EXPECT(next->len > (uint32_t)cols, 0)) + if (WSAP_VTCORE_EXPECT(next->len > (uint32_t)cols, 0)) extra_rows += rows_narrow(next->len, cols) - 1; stream_end++; } @@ -2259,7 +2259,7 @@ void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *li struct hline *dst = &h->ring[state.head++ & h->ring_mask]; if (len) { uint32_t line_off = base + (uint32_t)(lines[i].ptr - l->ptr); - if (TERM_EXPECT(len <= cols, 1)) { + if (WSAP_VTCORE_EXPECT(len <= cols, 1)) { part_put_narrow(dst, line_off, len); } else { part_put_narrow_rows(dst, line_off, len, rows_narrow(len, cols)); @@ -2309,7 +2309,7 @@ void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *li uint32_t len = lines[i].len; /* A blank line: no text, no page slot, one row. The scan does * not stop on it, so the batch keeps its room and its setup. */ - if (TERM_EXPECT(len == 0, 0)) { + if (WSAP_VTCORE_EXPECT(len == 0, 0)) { ring[head++ & rmask] = HLINE_BLANK; rows_add++; continue; @@ -2317,7 +2317,7 @@ void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *li bytes_copy_small(page + off, lines[i].ptr, (int)len); n_text++; any_text = true; - if (TERM_EXPECT(len <= cols, 1)) { + if (WSAP_VTCORE_EXPECT(len <= cols, 1)) { part_put_narrow(&ring[head++ & rmask], page_off | off, len); rows_add++; } else { @@ -2340,12 +2340,12 @@ void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *li } } -void term_hist_push_blank(struct hist *h, size_t n) +void wsap_vtcore_hist_push_blank(struct hist *h, size_t n) { if (!h->line_limit || n == 0) return; if (hist_is_open(h)) { - term_hist_close_open_line(h); + wsap_vtcore_hist_close_open_line(h); n--; } if (n == 0) @@ -2361,7 +2361,7 @@ void term_hist_push_blank(struct hist *h, size_t n) } if (n >= h->line_limit) { uint64_t end = hist_end_id(h) + n; - term_hist_clear(h); + wsap_vtcore_hist_clear(h); h->base_id = h->rows_id = end - h->line_limit; n = h->line_limit; h->all_blank = true; @@ -2429,7 +2429,7 @@ static void runs_iter_init(struct runs_iter *it, const struct hist *h, const str /* Take up to n cells of the current run. it->pen is their pen. */ static inline uint32_t runs_take(struct runs_iter *it, uint32_t n) { - while (TERM_EXPECT(it->left == 0, 0)) { + while (WSAP_VTCORE_EXPECT(it->left == 0, 0)) { if (it->p < it->end) { it->p = read_run(it->p, &it->pen, &it->left); } else if (it->pending) { @@ -2516,21 +2516,21 @@ static const uint8_t *text_cell(const uint8_t *s, const uint8_t *end, struct gst } uint8_t k = s[1]; s += 2; - uint32_t cps[TERM_GRAPHEME_MAX_LEN]; + uint32_t cps[WSAP_VTCORE_GRAPHEME_MAX_LEN]; int n = 0; for (int i = 0; i < (k & 0x1f) && s < end; i++) { uint32_t c; s += get_utf8(s, end, &c); - if (n < TERM_GRAPHEME_MAX_LEN) + if (n < WSAP_VTCORE_GRAPHEME_MAX_LEN) cps[n++] = c; } - *cp = n == 0 ? ' ' : (g && n > 1) ? term_gstore_intern(g, cps, n) : cps[0]; + *cp = n == 0 ? ' ' : (g && n > 1) ? wsap_vtcore_gstore_intern(g, cps, n) : cps[0]; *shape = (uint16_t)(((k & 0x80) ? CELL_WIDE : 0) | ((k & 0x40) ? CELL_EMOJI : 0) | ((k & 0x20) ? CELL_TEXT : 0)); return s; } -uint64_t term_hist_line_cells(const struct hist *h, uint64_t id) +uint64_t wsap_vtcore_hist_line_cells(const struct hist *h, uint64_t id) { if (!line_valid(h, id)) return 0; @@ -2545,7 +2545,7 @@ uint64_t term_hist_line_cells(const struct hist *h, uint64_t id) return cells; } -uint64_t term_hist_line_wide(const struct hist *h, uint64_t id) +uint64_t wsap_vtcore_hist_line_wide(const struct hist *h, uint64_t id) { if (!line_valid(h, id)) return 0; @@ -2560,7 +2560,7 @@ uint64_t term_hist_line_wide(const struct hist *h, uint64_t id) return wide; } -uint8_t term_hist_line_flags(const struct hist *h, uint64_t id) +uint8_t wsap_vtcore_hist_line_flags(const struct hist *h, uint64_t id) { if (!line_valid(h, id)) return 0; @@ -2596,7 +2596,7 @@ static int line_rows_walk(const struct hist *h, uint64_t first, uint64_t end, in return rows; } -int term_hist_line_rows(const struct hist *h, uint64_t id, int cols) +int wsap_vtcore_hist_line_rows(const struct hist *h, uint64_t id, int cols) { if (cols <= 0 || !line_valid(h, id)) return 0; @@ -2604,7 +2604,7 @@ int term_hist_line_rows(const struct hist *h, uint64_t id, int cols) const struct hline *f = part(h, first); if (cols == h->wrap_cols) { if (id < h->rows_id && - ((f->flags & HLINE_ROWS_EXACT) || !(term_hist_line_flags(h, id) & HLINE_HAS_WIDE))) { + ((f->flags & HLINE_ROWS_EXACT) || !(wsap_vtcore_hist_line_flags(h, id) & HLINE_HAS_WIDE))) { if (f->wrap_rows != ROWS_UNKNOWN) return f->wrap_rows; if ((f->flags & HLINE_ROWS_EXACT) && h->exact_rows) @@ -2614,9 +2614,9 @@ int term_hist_line_rows(const struct hist *h, uint64_t id, int cols) h->walk_off == part(h, h->walk_seq)->text_len) return (int)h->walk_rows; } - uint64_t cells = term_hist_line_cells(h, id); + uint64_t cells = wsap_vtcore_hist_line_cells(h, id); if (cells <= (uint64_t)cols || - !(term_hist_line_flags(h, id) & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER))) + !(wsap_vtcore_hist_line_flags(h, id) & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER))) return (int)rows_narrow(cells, cols); return line_rows_walk(h, first, line_end(h, first), cols); } @@ -2672,7 +2672,7 @@ static bool line_narrow(const struct hist *h, uint64_t first, uint64_t end) return true; } -int term_hist_decode_segments(const struct hist *h, uint64_t id, int start_seg, int count, int cols, +int wsap_vtcore_hist_decode_segments(const struct hist *h, uint64_t id, int start_seg, int count, int cols, struct cell *out, int *lens, struct gstore *g) { if (count <= 0 || start_seg < 0 || cols <= 0 || !line_valid(h, id)) @@ -2730,7 +2730,7 @@ int term_hist_decode_segments(const struct hist *h, uint64_t id, int start_seg, } if (g) - term_gstore_pin(g); + wsap_vtcore_gstore_pin(g); int row = 0, col = 0; int end_seg = start_seg + count; uint64_t s = first; @@ -2787,14 +2787,14 @@ int term_hist_decode_segments(const struct hist *h, uint64_t id, int start_seg, int seg_idx = row - start_seg; struct cell *row_out = out + (size_t)seg_idx * (size_t)cols; if (col < cols) - row_out[col] = (struct cell){ ' ', TERM_COLOR_FG, TERM_COLOR_BG, CELL_WRAP_PAD, 0 }; + row_out[col] = (struct cell){ ' ', WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG, CELL_WRAP_PAD, 0 }; if (lens) lens[seg_idx] = col < cols ? cols : col; row++; col = 0; if (row == end_seg) { if (g) - term_gstore_unpin(g); + wsap_vtcore_gstore_unpin(g); dec->epoch = h->index_epoch; dec->id = id; dec->cols = (uint16_t)cols; @@ -2820,7 +2820,7 @@ int term_hist_decode_segments(const struct hist *h, uint64_t id, int start_seg, } if (row == end_seg) { if (g) - term_gstore_unpin(g); + wsap_vtcore_gstore_unpin(g); dec->epoch = h->index_epoch; dec->id = id; dec->cols = (uint16_t)cols; @@ -2841,15 +2841,15 @@ int term_hist_decode_segments(const struct hist *h, uint64_t id, int start_seg, } dec->valid = false; if (g) - term_gstore_unpin(g); + wsap_vtcore_gstore_unpin(g); return decoded; } -int term_hist_decode_segment(const struct hist *h, uint64_t id, int seg, int cols, +int wsap_vtcore_hist_decode_segment(const struct hist *h, uint64_t id, int seg, int cols, struct cell *out, struct gstore *g) { int len = 0; - int got = term_hist_decode_segments(h, id, seg, 1, cols, out, &len, g); + int got = wsap_vtcore_hist_decode_segments(h, id, seg, 1, cols, out, &len, g); return got > 0 ? len : 0; } @@ -2859,7 +2859,7 @@ static int decode_line(const struct hist *h, uint64_t first, uint64_t end, { int n = 0; if (g) - term_gstore_pin(g); + wsap_vtcore_gstore_pin(g); for (uint64_t s = first; s < end; s++) { const struct hline *p = part(h, s); if (!p->text_len) @@ -2882,11 +2882,11 @@ static int decode_line(const struct hist *h, uint64_t first, uint64_t end, } } if (g) - term_gstore_unpin(g); + wsap_vtcore_gstore_unpin(g); return n; } -int term_hist_text_decode(const struct text_row *row, struct cell *out, int cap, struct gstore *g) +int wsap_vtcore_hist_text_decode(const struct text_row *row, struct cell *out, int cap, struct gstore *g) { struct runs_iter it; runs_iter_runs(&it, &row->runs, &row->start); @@ -2921,7 +2921,7 @@ int term_hist_text_decode(const struct text_row *row, struct cell *out, int cap, return n < cap ? n : cap; } -void term_hist_text_mark_links(const struct text_row *row, void (*mark)(void *ud, uint16_t link), void *ud) +void wsap_vtcore_hist_text_mark_links(const struct text_row *row, void (*mark)(void *ud, uint16_t link), void *ud) { if (!(row->flags & HLINE_HAS_LINK) && !row->start.link) return; @@ -2940,7 +2940,7 @@ void term_hist_text_mark_links(const struct text_row *row, void (*mark)(void *ud mark(ud, it.pending_pen.link); } -void term_hist_mark_links(const struct hist *h, void (*mark)(void *ud, uint16_t link), void *ud) +void wsap_vtcore_hist_mark_links(const struct hist *h, void (*mark)(void *ud, uint16_t link), void *ud) { for (uint64_t s = h->tail; s < h->head; s++) { const struct hline *p = part(h, s); @@ -2976,7 +2976,7 @@ static void drop_head_part(struct hist *h) cont_trim(h); } -int term_hist_peek_last_line(const struct hist *h, struct cell *out, int cap, struct gstore *g) +int wsap_vtcore_hist_peek_last_line(const struct hist *h, struct cell *out, int cap, struct gstore *g) { if (h->lines == 0) return 0; @@ -2984,13 +2984,13 @@ int term_hist_peek_last_line(const struct hist *h, struct cell *out, int cap, st return decode_line(h, line_first(h, id), h->head, out, cap, g); } -int term_hist_pop_line(struct hist *h, struct cell *out, int cap, struct gstore *g) +int wsap_vtcore_hist_pop_line(struct hist *h, struct cell *out, int cap, struct gstore *g) { if (h->lines == 0) return 0; uint64_t id = hist_end_id(h) - 1; uint64_t first = line_first(h, id); - int n = out ? decode_line(h, first, h->head, out, cap, g) : (int)term_hist_line_cells(h, id); + int n = out ? decode_line(h, first, h->head, out, cap, g) : (int)wsap_vtcore_hist_line_cells(h, id); if (id < h->rows_id) { rows_uncount(h, id); h->rows_id = id; @@ -3001,8 +3001,8 @@ int term_hist_pop_line(struct hist *h, struct cell *out, int cap, struct gstore h->index_epoch++; if (h->lines) { uint64_t last = hist_end_id(h) - 1; - h->last_cells = term_hist_line_cells(h, last); - h->last_wide = term_hist_line_wide(h, last); + h->last_cells = wsap_vtcore_hist_line_cells(h, last); + h->last_wide = wsap_vtcore_hist_line_wide(h, last); h->last_id = last; } runs_reset(&h->runs); @@ -3015,21 +3015,21 @@ int term_hist_pop_line(struct hist *h, struct cell *out, int cap, struct gstore return n; } -int term_hist_pop_tail_cells(struct hist *h, int n, struct cell *out, struct gstore *g) +int wsap_vtcore_hist_pop_tail_cells(struct hist *h, int n, struct cell *out, struct gstore *g) { if (h->lines == 0 || n <= 0) return 0; - uint64_t total = term_hist_line_cells(h, hist_end_id(h) - 1); + uint64_t total = wsap_vtcore_hist_line_cells(h, hist_end_id(h) - 1); if (total == 0) { - term_hist_pop_line(h, NULL, 0, g); + wsap_vtcore_hist_pop_line(h, NULL, 0, g); return 0; } struct cell *all = malloc((size_t)total * sizeof(*all)); if (!all) return 0; if (g) - term_gstore_pin(g); - int got = term_hist_pop_line(h, all, (int)total, g); + wsap_vtcore_gstore_pin(g); + int got = wsap_vtcore_hist_pop_line(h, all, (int)total, g); int take = n < got ? n : got; int keep = got - take; if (keep > 0 && (all[keep].flags & CELL_TRAIL)) { @@ -3041,17 +3041,17 @@ int term_hist_pop_tail_cells(struct hist *h, int n, struct cell *out, struct gst if (keep > 0) { uint16_t cols = h->wrap_cols ? h->wrap_cols : 1; for (int i = 0; i < keep; i += cols) - term_hist_push_row(h, all + i, keep - i < cols ? keep - i : cols, true, g); + wsap_vtcore_hist_push_row(h, all + i, keep - i < cols ? keep - i : cols, true, g); } if (g) - term_gstore_unpin(g); + wsap_vtcore_gstore_unpin(g); free(all); return take; } /* ---- Rows ---- */ -void term_hist_set_width(struct hist *h, int cols) +void wsap_vtcore_hist_set_width(struct hist *h, int cols) { if (h->wrap_cols == cols) return; @@ -3061,7 +3061,7 @@ void term_hist_set_width(struct hist *h, int cols) h->walk_on = false; } -uint64_t term_hist_line_estimate(const struct hist *h, uint64_t id, int cols) +uint64_t wsap_vtcore_hist_line_estimate(const struct hist *h, uint64_t id, int cols) { if (!line_valid(h, id)) return 0; @@ -3071,18 +3071,18 @@ uint64_t term_hist_line_estimate(const struct hist *h, uint64_t id, int cols) return first->wrap_rows != ROWS_UNKNOWN ? first->wrap_rows : h->exact_rows[line_first(h, id) & h->ring_mask]; } - uint64_t cells = term_hist_line_cells(h, id); + uint64_t cells = wsap_vtcore_hist_line_cells(h, id); if (cols == 1) - cells -= term_hist_line_wide(h, id); + cells -= wsap_vtcore_hist_line_wide(h, id); return rows_narrow(cells, cols); } -void term_hist_refine_rows(struct hist *h, uint64_t id, int cols, int rows) +void wsap_vtcore_hist_refine_rows(struct hist *h, uint64_t id, int cols, int rows) { if (cols != h->wrap_cols || id >= h->rows_id || id < h->base_id) return; uint64_t seq = line_first(h, id); - uint64_t old = term_hist_line_estimate(h, id, cols); + uint64_t old = wsap_vtcore_hist_line_estimate(h, id, cols); if (rows >= ROWS_UNKNOWN) { if (!h->exact_rows) { h->exact_rows = calloc((size_t)h->ring_mask + 1, sizeof(*h->exact_rows)); @@ -3098,53 +3098,53 @@ void term_hist_refine_rows(struct hist *h, uint64_t id, int cols, int rows) } /* Fill descriptor counts only. This never reads the encoded text. */ -void term_hist_prepare_rows(struct hist *h, int cols) +void wsap_vtcore_hist_prepare_rows(struct hist *h, int cols) { if (cols != h->wrap_cols) - term_hist_set_width(h, cols); + wsap_vtcore_hist_set_width(h, cols); uint64_t stop = hist_end_id(h) - (hist_is_open(h) ? 1 : 0); for (; h->rows_id < stop; h->rows_id++) { - uint64_t rows = term_hist_line_estimate(h, h->rows_id, cols); + uint64_t rows = wsap_vtcore_hist_line_estimate(h, h->rows_id, cols); struct hline *first = part(h, line_first(h, h->rows_id)); first->wrap_rows = row_count_byte(rows); first->flags &= (uint8_t)~HLINE_ROWS_EXACT; if (rows < ROWS_UNKNOWN && - (!(term_hist_line_flags(h, h->rows_id) & HLINE_HAS_WIDE) || cols == 1)) + (!(wsap_vtcore_hist_line_flags(h, h->rows_id) & HLINE_HAS_WIDE) || cols == 1)) first->flags |= HLINE_ROWS_EXACT; h->counted_rows += rows; } } -uint64_t term_hist_estimated_rows(const struct hist *h, int cols) +uint64_t wsap_vtcore_hist_estimated_rows(const struct hist *h, int cols) { if (!h || cols <= 0 || !h->lines) return 0; uint64_t total = cols == h->wrap_cols ? h->counted_rows : 0; uint64_t first = cols == h->wrap_cols ? h->rows_id : h->base_id; for (uint64_t id = first; id < hist_end_id(h); id++) - total += term_hist_line_estimate(h, id, cols); + total += wsap_vtcore_hist_line_estimate(h, id, cols); return total; } -uint64_t term_hist_rows(const struct hist *h, int cols) +uint64_t wsap_vtcore_hist_rows(const struct hist *h, int cols) { if (!h || cols <= 0) return 0; uint64_t total = 0; for (uint64_t id = hist_first_id(h); id < hist_end_id(h); id++) - total += (uint64_t)term_hist_line_rows(h, id, cols); + total += (uint64_t)wsap_vtcore_hist_line_rows(h, id, cols); return total; } /* Locate a row boundary by its cell offset. Wide wrap pads do not count. */ -uint64_t term_hist_segment_cell(const struct hist *h, uint64_t id, int seg, int cols) +uint64_t wsap_vtcore_hist_segment_cell(const struct hist *h, uint64_t id, int seg, int cols) { if (!line_valid(h, id)) return 0; uint64_t base = id == h->base_cell_id ? h->base_cell : 0; if (seg <= 0) return base; - if (!(term_hist_line_flags(h, id) & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER))) + if (!(wsap_vtcore_hist_line_flags(h, id) & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER))) return base + (uint64_t)seg * cols; uint64_t first = line_first(h, id), end = line_end(h, first), cells = 0; int row = 0, col = 0; @@ -3168,14 +3168,14 @@ uint64_t term_hist_segment_cell(const struct hist *h, uint64_t id, int seg, int return base + cells; } -int term_hist_cell_segment(const struct hist *h, uint64_t id, uint64_t cell, int cols) +int wsap_vtcore_hist_cell_segment(const struct hist *h, uint64_t id, uint64_t cell, int cols) { if (!line_valid(h, id) || cols <= 0) return 0; uint64_t base = id == h->base_cell_id ? h->base_cell : 0; cell = cell > base ? cell - base : 0; - if (!(term_hist_line_flags(h, id) & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER))) { - uint64_t cells = term_hist_line_cells(h, id); + if (!(wsap_vtcore_hist_line_flags(h, id) & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER))) { + uint64_t cells = wsap_vtcore_hist_line_cells(h, id); if (cells && cell >= cells) cell = cells - 1; return (int)(cell / cols); @@ -3205,7 +3205,7 @@ int term_hist_cell_segment(const struct hist *h, uint64_t id, uint64_t cell, int /* ---- Life cycle ---- */ -bool term_hist_init(struct hist *h, int line_limit, size_t byte_cap) +bool wsap_vtcore_hist_init(struct hist *h, int line_limit, size_t byte_cap) { memset(h, 0, sizeof(*h)); h->all_blank = true; @@ -3227,22 +3227,22 @@ bool term_hist_init(struct hist *h, int line_limit, size_t byte_cap) h->page_parts = calloc(h->max_pages, sizeof(*h->page_parts)); h->free_pages = malloc(h->max_pages * sizeof(*h->free_pages)); if (!h->pages || !h->page_used || !h->page_parts || !h->free_pages || !ring_fit(h, 1)) { - term_hist_free(h); + wsap_vtcore_hist_free(h); return false; } return true; } -void term_hist_free(struct hist *h) +void wsap_vtcore_hist_free(struct hist *h) { if (h->pages) for (uint32_t i = 0; i < h->npages; i++) - term_aligned_free(h->pages[i]); + wsap_vtcore_aligned_free(h->pages[i]); free(h->pages); free(h->page_used); free(h->page_parts); free(h->free_pages); - term_aligned_free(h->ring); + wsap_vtcore_aligned_free(h->ring); free(h->blocks); free(h->exact_rows); free(h->cont); @@ -3250,7 +3250,7 @@ void term_hist_free(struct hist *h) memset(h, 0, sizeof(*h)); } -void term_hist_clear(struct hist *h) +void wsap_vtcore_hist_clear(struct hist *h) { h->index_epoch++; uint64_t end = hist_end_id(h); @@ -92,7 +92,7 @@ struct text_row { #define TEXT_ROW_RUNS(cols) (((size_t)(cols) + 2) * 22) /* Emit the pending run in the general form. */ -void term_hist_runs_emit_slow(struct hist_runs *r); +void wsap_vtcore_hist_runs_emit_slow(struct hist_runs *r); /* Close the pending run and start one with the given pen. The caller * sized the buffer. A run that changes only colors and covers fewer than @@ -102,7 +102,7 @@ static inline void hist_runs_switch(struct hist_runs *r, struct text_pen pen) { if (r->count) { uint32_t psl = pen_sl(&r->pen); - if (TERM_EXPECT(r->count < 0x80 && psl == pen_sl(&r->base), 1)) { + if (WSAP_VTCORE_EXPECT(r->count < 0x80 && psl == pen_sl(&r->base), 1)) { uint8_t *p = r->data + r->len; uint32_t dfg = r->pen.fg != r->base.fg, dbg = r->pen.bg != r->base.bg; p[0] = (uint8_t)(dfg | dbg << 1); @@ -112,7 +112,7 @@ static inline void hist_runs_switch(struct hist_runs *r, struct text_pen pen) memcpy(p, &r->pen.bg, 4); r->len = (uint32_t)(p + dbg * 4 - r->data); } else { - term_hist_runs_emit_slow(r); + wsap_vtcore_hist_runs_emit_slow(r); } pen_set(&r->base, r->pen.fg, r->pen.bg, psl); } @@ -160,8 +160,8 @@ static inline void text_row_unshare(struct text_row *row) } /* Write the cells of a text row to out; return the cell count. */ -int term_hist_text_decode(const struct text_row *row, struct cell *out, int cap, struct gstore *g); -void term_hist_text_mark_links(const struct text_row *row, void (*mark)(void *ud, uint16_t link), void *ud); +int wsap_vtcore_hist_text_decode(const struct text_row *row, struct cell *out, int cap, struct gstore *g); +void wsap_vtcore_hist_text_mark_links(const struct text_row *row, void (*mark)(void *ud, uint16_t link), void *ud); struct hist_dec_cache { const uint8_t *p, *end; @@ -225,34 +225,34 @@ static inline uint32_t rows_narrow(uint64_t cells, int cols) (uint32_t)((cells + (uint64_t)cols - 1) / (uint64_t)cols); } -bool term_hist_init(struct hist *h, int line_limit, size_t byte_cap); -void term_hist_free(struct hist *h); -void term_hist_clear(struct hist *h); +bool wsap_vtcore_hist_init(struct hist *h, int line_limit, size_t byte_cap); +void wsap_vtcore_hist_free(struct hist *h); +void wsap_vtcore_hist_clear(struct hist *h); /* Push one screen row. It joins the open line, or starts a new line. A * wrapped row leaves the line open for the next row. */ -void term_hist_push_row(struct hist *h, const struct cell *cells, int len, bool wrapped, +void wsap_vtcore_hist_push_row(struct hist *h, const struct cell *cells, int len, bool wrapped, const struct gstore *g); -void term_hist_push_ascii(struct hist *h, const char *bytes, int n, +void wsap_vtcore_hist_push_ascii(struct hist *h, const char *bytes, int n, const struct pen_attr *pen, bool wrapped); -void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *lines, +void wsap_vtcore_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *lines, int count, const struct pen_attr *pen); /* Ends include LF. ends[0] is the start of the first line. */ -void term_hist_push_ascii_lf(struct hist *h, const char *bytes, const uint16_t *ends, int count); -/* Push a text row as one screen row, like term_hist_push_row(). */ -void term_hist_push_text(struct hist *h, const struct text_row *row, bool wrapped); +void wsap_vtcore_hist_push_ascii_lf(struct hist *h, const char *bytes, const uint16_t *ends, int count); +/* Push a text row as one screen row, like wsap_vtcore_hist_push_row(). */ +void wsap_vtcore_hist_push_text(struct hist *h, const struct text_row *row, bool wrapped); /* Push n empty unwrapped rows. The first one closes an open line. */ -void term_hist_push_blank(struct hist *h, size_t n); -void term_hist_close_open_line(struct hist *h); +void wsap_vtcore_hist_push_blank(struct hist *h, size_t n); +void wsap_vtcore_hist_close_open_line(struct hist *h); /* Remove the last line. Write its cells to out (at most cap) and return the * number of cells in the line. */ -int term_hist_pop_line(struct hist *h, struct cell *out, int cap, struct gstore *g); -/* Copy the last line's cells to out, as term_hist_pop_line() does, and keep the line. +int wsap_vtcore_hist_pop_line(struct hist *h, struct cell *out, int cap, struct gstore *g); +/* Copy the last line's cells to out, as wsap_vtcore_hist_pop_line() does, and keep the line. * Return the number of cells in the line. */ -int term_hist_peek_last_line(const struct hist *h, struct cell *out, int cap, struct gstore *g); +int wsap_vtcore_hist_peek_last_line(const struct hist *h, struct cell *out, int cap, struct gstore *g); /* Take up to n cells back off the end of the last line. Return the count. */ -int term_hist_pop_tail_cells(struct hist *h, int n, struct cell *out, struct gstore *g); +int wsap_vtcore_hist_pop_tail_cells(struct hist *h, int n, struct cell *out, struct gstore *g); static inline uint64_t hist_first_id(const struct hist *h) { @@ -269,29 +269,29 @@ static inline bool hist_is_open(const struct hist *h) return h->head != h->tail && (h->ring[(h->head - 1) & h->ring_mask].flags & HLINE_OPEN); } -uint64_t term_hist_line_cells(const struct hist *h, uint64_t id); -uint64_t term_hist_line_wide(const struct hist *h, uint64_t id); -uint8_t term_hist_line_flags(const struct hist *h, uint64_t id); -int term_hist_line_rows(const struct hist *h, uint64_t id, int cols); -int term_hist_decode_segment(const struct hist *h, uint64_t id, int seg, int cols, +uint64_t wsap_vtcore_hist_line_cells(const struct hist *h, uint64_t id); +uint64_t wsap_vtcore_hist_line_wide(const struct hist *h, uint64_t id); +uint8_t wsap_vtcore_hist_line_flags(const struct hist *h, uint64_t id); +int wsap_vtcore_hist_line_rows(const struct hist *h, uint64_t id, int cols); +int wsap_vtcore_hist_decode_segment(const struct hist *h, uint64_t id, int seg, int cols, struct cell *out, struct gstore *g); -int term_hist_decode_segments(const struct hist *h, uint64_t id, int start_seg, int count, int cols, +int wsap_vtcore_hist_decode_segments(const struct hist *h, uint64_t id, int start_seg, int count, int cols, struct cell *out, int *lens, struct gstore *g); -uint64_t term_hist_segment_cell(const struct hist *h, uint64_t id, int seg, int cols); -int term_hist_cell_segment(const struct hist *h, uint64_t id, uint64_t cell, int cols); +uint64_t wsap_vtcore_hist_segment_cell(const struct hist *h, uint64_t id, int seg, int cols); +int wsap_vtcore_hist_cell_segment(const struct hist *h, uint64_t id, uint64_t cell, int cols); -void term_hist_mark_links(const struct hist *h, void (*mark)(void *ud, uint16_t link), void *ud); +void wsap_vtcore_hist_mark_links(const struct hist *h, void (*mark)(void *ud, uint16_t link), void *ud); /* Set the width that pushed rows have. It costs O(1): the stored row counts * become stale. Reads count them without changing the history. */ -void term_hist_set_width(struct hist *h, int cols); +void wsap_vtcore_hist_set_width(struct hist *h, int cols); /* Rows of all retained lines at cols. */ -uint64_t term_hist_rows(const struct hist *h, int cols); -uint64_t term_hist_line_estimate(const struct hist *h, uint64_t id, int cols); -uint64_t term_hist_estimated_rows(const struct hist *h, int cols); -void term_hist_prepare_rows(struct hist *h, int cols); -void term_hist_refine_rows(struct hist *h, uint64_t id, int cols, int rows); +uint64_t wsap_vtcore_hist_rows(const struct hist *h, int cols); +uint64_t wsap_vtcore_hist_line_estimate(const struct hist *h, uint64_t id, int cols); +uint64_t wsap_vtcore_hist_estimated_rows(const struct hist *h, int cols); +void wsap_vtcore_hist_prepare_rows(struct hist *h, int cols); +void wsap_vtcore_hist_refine_rows(struct hist *h, uint64_t id, int cols, int rows); #endif diff --git a/src/hist_view.c b/src/hist_view.c index 362e995..1cbbb07 100644 --- a/src/hist_view.c +++ b/src/hist_view.c @@ -3,7 +3,7 @@ #include <stdlib.h> #include <string.h> -void term_hist_view_free(struct hist_view *v) +void wsap_vtcore_hist_view_free(struct hist_view *v) { if (!v) return; @@ -37,10 +37,10 @@ static bool current(const struct hist_view *v, const struct hist *h, int cols) return v->index_cols == cols && v->epoch == h->index_epoch && v->first_id == hist_first_id(h) && v->end_id == hist_end_id(h) && v->head == h->head && v->tail == h->tail && - v->last_cells == (h->lines ? term_hist_line_cells(h, hist_end_id(h) - 1) : 0); + v->last_cells == (h->lines ? wsap_vtcore_hist_line_cells(h, hist_end_id(h) - 1) : 0); } -bool term_hist_view_sync(struct hist_view *v, const struct hist *h, int cols) +bool wsap_vtcore_hist_view_sync(struct hist_view *v, const struct hist *h, int cols) { if (current(v, h, cols)) return true; @@ -54,7 +54,7 @@ bool term_hist_view_sync(struct hist_view *v, const struct hist *h, int cols) if (h->lines > v->cap || !v->cap) { if (h->lines > (UINT32_C(1) << 31)) return false; - uint32_t cap = term_next_pow2_32(h->lines < 16 ? 16 : h->lines); + uint32_t cap = wsap_vtcore_next_pow2_32(h->lines < 16 ? 16 : h->lines); if (cap == UINT32_MAX) return false; uint64_t *tree = calloc((size_t)cap + 1, sizeof(*tree)); @@ -75,7 +75,7 @@ bool term_hist_view_sync(struct hist_view *v, const struct hist *h, int cols) memset(v->counts, 0, (size_t)v->cap * sizeof(*v->counts)); memset(v->fenwick, 0, ((size_t)v->cap + 1) * sizeof(*v->fenwick)); for (uint64_t id = first; id < end; id++) - v->counts[(uint32_t)id & (v->cap - 1)] = (uint32_t)term_hist_line_estimate(h, id, cols); + v->counts[(uint32_t)id & (v->cap - 1)] = (uint32_t)wsap_vtcore_hist_line_estimate(h, id, cols); /* Build all tree nodes in one pass. */ for (uint32_t i = 1; i <= v->cap; i++) { v->fenwick[i] += v->counts[i - 1]; @@ -88,10 +88,10 @@ bool term_hist_view_sync(struct hist_view *v, const struct hist *h, int cols) for (uint64_t id = v->first_id; id < first; id++) set_count(v, id, 0); /* Only the old final line can grow or close. */ - if (v->end_id > first && term_hist_line_cells(h, v->end_id - 1) != v->last_cells) - set_count(v, v->end_id - 1, (uint32_t)term_hist_line_estimate(h, v->end_id - 1, cols)); + if (v->end_id > first && wsap_vtcore_hist_line_cells(h, v->end_id - 1) != v->last_cells) + set_count(v, v->end_id - 1, (uint32_t)wsap_vtcore_hist_line_estimate(h, v->end_id - 1, cols)); for (uint64_t id = v->end_id; id < end; id++) - set_count(v, id, (uint32_t)term_hist_line_estimate(h, id, cols)); + set_count(v, id, (uint32_t)wsap_vtcore_hist_line_estimate(h, id, cols)); } v->first_id = first; v->end_id = end; @@ -99,7 +99,7 @@ bool term_hist_view_sync(struct hist_view *v, const struct hist *h, int cols) v->epoch = h->index_epoch; v->head = h->head; v->tail = h->tail; - v->last_cells = h->lines ? term_hist_line_cells(h, end - 1) : 0; + v->last_cells = h->lines ? wsap_vtcore_hist_line_cells(h, end - 1) : 0; return true; } @@ -110,14 +110,14 @@ static uint64_t anchor_extra(const struct hist_view *v, const struct hist *h, in if (!v->anchor.active || id < hist_first_id(h) || id >= hist_end_id(h)) return 0; uint64_t estimated = current(v, h, cols) ? v->counts[(uint32_t)id & (v->cap - 1)] : - term_hist_line_estimate(h, id, cols); - uint64_t exact = (uint64_t)term_hist_line_rows(h, id, cols); + wsap_vtcore_hist_line_estimate(h, id, cols); + uint64_t exact = (uint64_t)wsap_vtcore_hist_line_rows(h, id, cols); return exact > estimated ? exact - estimated : 0; } -uint64_t term_hist_view_rows(const struct hist_view *v, const struct hist *h, int cols) +uint64_t wsap_vtcore_hist_view_rows(const struct hist_view *v, const struct hist *h, int cols) { - uint64_t rows = current(v, h, cols) ? v->total_rows : term_hist_estimated_rows(h, cols); + uint64_t rows = current(v, h, cols) ? v->total_rows : wsap_vtcore_hist_estimated_rows(h, cols); return rows + anchor_extra(v, h, cols); } @@ -149,7 +149,7 @@ static uint32_t select_slot(const struct hist_view *v, uint64_t row, int *seg) return slot; } -bool term_hist_view_find_row(const struct hist_view *v, const struct hist *h, int row, +bool wsap_vtcore_hist_view_find_row(const struct hist_view *v, const struct hist *h, int row, int cols, uint64_t *id, int *seg) { if (!current(v, h, cols)) { @@ -157,7 +157,7 @@ bool term_hist_view_find_row(const struct hist_view *v, const struct hist *h, in return false; uint64_t target = (uint64_t)row; for (uint64_t line = hist_first_id(h); line < hist_end_id(h); line++) { - uint64_t count = term_hist_line_estimate(h, line, cols); + uint64_t count = wsap_vtcore_hist_line_estimate(h, line, cols); if (target < count) { *id = line; *seg = (int)target; @@ -183,56 +183,56 @@ static int rows_as_int(uint64_t rows) return rows > INT_MAX ? INT_MAX : (int)rows; } -int term_hist_view_scroll_offset(const struct hist_view *v, const struct hist *h, int cols) +int wsap_vtcore_hist_view_scroll_offset(const struct hist_view *v, const struct hist *h, int cols) { if (!v->anchor.active || !h->lines) return 0; uint64_t id = v->anchor.line_id; if (id < hist_first_id(h)) - return rows_as_int(term_hist_view_rows(v, h, cols)); + return rows_as_int(wsap_vtcore_hist_view_rows(v, h, cols)); if (id >= hist_end_id(h)) return 0; int seg = v->cols == cols ? (int)v->anchor.seg : - term_hist_cell_segment(h, id, v->anchor.cell, cols); + wsap_vtcore_hist_cell_segment(h, id, v->anchor.cell, cols); uint64_t rows = 0; if (current(v, h, cols)) rows = v->total_rows - before(v, id); else for (; id < hist_end_id(h); id++) - rows += term_hist_line_estimate(h, id, cols); + rows += wsap_vtcore_hist_line_estimate(h, id, cols); rows += anchor_extra(v, h, cols); return rows > (uint64_t)seg ? rows_as_int(rows - seg) : 0; } -void term_hist_view_note_push(struct hist_view *v, const struct hist *h, int cols) +void wsap_vtcore_hist_view_note_push(struct hist_view *v, const struct hist *h, int cols) { if (!v->anchor.active) return; if (v->anchor.line_id < hist_first_id(h)) v->anchor = (struct view_anchor){ .line_id = hist_first_id(h), .active = true }; - uint64_t base = term_hist_segment_cell(h, v->anchor.line_id, 0, cols); + uint64_t base = wsap_vtcore_hist_segment_cell(h, v->anchor.line_id, 0, cols); if (v->anchor.base_cell != base) { if (v->anchor.cell < base) v->anchor.cell = base; - v->anchor.seg = (uint32_t)term_hist_cell_segment(h, v->anchor.line_id, v->anchor.cell, cols); + v->anchor.seg = (uint32_t)wsap_vtcore_hist_cell_segment(h, v->anchor.line_id, v->anchor.cell, cols); v->anchor.base_cell = base; } } -void term_hist_view_rewrap(struct hist_view *v, const struct hist *h, int cols) +void wsap_vtcore_hist_view_rewrap(struct hist_view *v, const struct hist *h, int cols) { - term_hist_view_note_push(v, h, cols); + wsap_vtcore_hist_view_note_push(v, h, cols); if (v->anchor.active) { if (v->anchor.line_id >= hist_end_id(h)) v->anchor = (struct view_anchor){0}; else - v->anchor.seg = (uint32_t)term_hist_cell_segment(h, v->anchor.line_id, v->anchor.cell, cols); + v->anchor.seg = (uint32_t)wsap_vtcore_hist_cell_segment(h, v->anchor.line_id, v->anchor.cell, cols); } v->cols = cols; v->index_cols = 0; } -void term_hist_view_scroll_to(struct hist_view *v, const struct hist *h, int cols, +void wsap_vtcore_hist_view_scroll_to(struct hist_view *v, const struct hist *h, int cols, struct line_pos screen_top, int offset) { (void)screen_top; @@ -241,22 +241,22 @@ void term_hist_view_scroll_to(struct hist_view *v, const struct hist *h, int col return; } /* Allocation failure uses the read-only history walk. */ - uint64_t total = term_hist_view_rows(v, h, cols); + uint64_t total = wsap_vtcore_hist_view_rows(v, h, cols); if ((uint64_t)offset > total) offset = rows_as_int(total); uint64_t id; int seg; uint64_t row = total - offset; - if (row > INT_MAX || !term_hist_view_find_row(v, h, (int)row, cols, &id, &seg)) + if (row > INT_MAX || !wsap_vtcore_hist_view_find_row(v, h, (int)row, cols, &id, &seg)) return; v->anchor = (struct view_anchor){ .line_id = id, .seg = (uint32_t)seg, - .cell = term_hist_segment_cell(h, id, seg, cols), - .base_cell = term_hist_segment_cell(h, id, 0, cols), .active = true }; + .cell = wsap_vtcore_hist_segment_cell(h, id, seg, cols), + .base_cell = wsap_vtcore_hist_segment_cell(h, id, 0, cols), .active = true }; v->cols = cols; } /* Relative movement visits only the logical lines it crosses. */ -void term_hist_view_scroll(struct hist_view *v, const struct hist *h, int cols, +void wsap_vtcore_hist_view_scroll(struct hist_view *v, const struct hist *h, int cols, struct line_pos screen_top, int lines) { (void)screen_top; @@ -270,22 +270,22 @@ void term_hist_view_scroll(struct hist_view *v, const struct hist *h, int cols, id = hist_first_id(h); if (id >= hist_end_id(h)) id = hist_end_id(h) - 1; - seg = v->cols == cols ? (int64_t)v->anchor.seg : term_hist_cell_segment(h, id, v->anchor.cell, cols); + seg = v->cols == cols ? (int64_t)v->anchor.seg : wsap_vtcore_hist_cell_segment(h, id, v->anchor.cell, cols); } else { if (lines < 0) return; id = hist_end_id(h) - 1; - seg = term_hist_line_rows(h, id, cols); + seg = wsap_vtcore_hist_line_rows(h, id, cols); } seg -= (int64_t)lines; if (lines > 0) { while (seg < 0 && id > hist_first_id(h)) - seg += term_hist_line_rows(h, --id, cols); + seg += wsap_vtcore_hist_line_rows(h, --id, cols); if (seg < 0) seg = 0; } else { for (;;) { - int count = term_hist_line_rows(h, id, cols); + int count = wsap_vtcore_hist_line_rows(h, id, cols); if (seg < count) break; seg -= count; @@ -296,13 +296,13 @@ void term_hist_view_scroll(struct hist_view *v, const struct hist *h, int cols, } } v->anchor = (struct view_anchor){ .line_id = id, .seg = (uint32_t)seg, - .cell = term_hist_segment_cell(h, id, (int)seg, cols), - .base_cell = term_hist_segment_cell(h, id, 0, cols), .active = true }; + .cell = wsap_vtcore_hist_segment_cell(h, id, (int)seg, cols), + .base_cell = wsap_vtcore_hist_segment_cell(h, id, 0, cols), .active = true }; v->cols = cols; } /* A viewport walks exact segments from its anchor, never an estimated row. */ -bool term_hist_view_row_pos(const struct hist_view *v, const struct hist *h, int cols, +bool wsap_vtcore_hist_view_row_pos(const struct hist_view *v, const struct hist *h, int cols, int screen_rows, struct line_pos screen_top, int y, struct hist_view_pos *pos) { @@ -310,14 +310,14 @@ bool term_hist_view_row_pos(const struct hist_view *v, const struct hist *h, int if (v->anchor.active && h->lines) { uint64_t id = v->anchor.line_id; int seg = v->cols == cols ? (int)v->anchor.seg : - term_hist_cell_segment(h, id, v->anchor.cell, cols); + wsap_vtcore_hist_cell_segment(h, id, v->anchor.cell, cols); if (id < hist_first_id(h)) { id = hist_first_id(h); seg = 0; } int64_t target = (int64_t)seg + y; while (id < hist_end_id(h)) { - int count = term_hist_line_rows(h, id, cols); + int count = wsap_vtcore_hist_line_rows(h, id, cols); if (target < count) { pos->id = id; pos->seg = (int)target; @@ -334,7 +334,7 @@ bool term_hist_view_row_pos(const struct hist_view *v, const struct hist *h, int } /* Wide line counts become exact when the viewport visits them. */ -void term_hist_view_refine(struct hist_view *v, struct hist *h, int cols, int rows) +void wsap_vtcore_hist_view_refine(struct hist_view *v, struct hist *h, int cols, int rows) { if (!v->anchor.active || !current(v, h, cols)) return; @@ -346,9 +346,9 @@ void term_hist_view_refine(struct hist_view *v, struct hist *h, int cols, int ro seg = 0; } for (; id < hist_end_id(h) && remaining > 0; id++) { - int count = term_hist_line_rows(h, id, cols); + int count = wsap_vtcore_hist_line_rows(h, id, cols); set_count(v, id, (uint32_t)count); - term_hist_refine_rows(h, id, cols, count); + wsap_vtcore_hist_refine_rows(h, id, cols, count); remaining -= count - seg; seg = 0; } diff --git a/src/hist_view.h b/src/hist_view.h index 61b4e89..165ab0b 100644 --- a/src/hist_view.h +++ b/src/hist_view.h @@ -1,5 +1,5 @@ -#ifndef TERM_HIST_VIEW_H -#define TERM_HIST_VIEW_H +#ifndef WSAP_VTCORE_HIST_VIEW_H +#define WSAP_VTCORE_HIST_VIEW_H #include "hist.h" @@ -30,20 +30,20 @@ struct hist_view { int index_cols; }; -void term_hist_view_free(struct hist_view *v); +void wsap_vtcore_hist_view_free(struct hist_view *v); /* Update the index during snapshot capture. Reads do not change it. */ -bool term_hist_view_sync(struct hist_view *v, const struct hist *h, int cols); -void term_hist_view_refine(struct hist_view *v, struct hist *h, int cols, int rows); -uint64_t term_hist_view_rows(const struct hist_view *v, const struct hist *h, int cols); -bool term_hist_view_find_row(const struct hist_view *v, const struct hist *h, int row, +bool wsap_vtcore_hist_view_sync(struct hist_view *v, const struct hist *h, int cols); +void wsap_vtcore_hist_view_refine(struct hist_view *v, struct hist *h, int cols, int rows); +uint64_t wsap_vtcore_hist_view_rows(const struct hist_view *v, const struct hist *h, int cols); +bool wsap_vtcore_hist_view_find_row(const struct hist_view *v, const struct hist *h, int row, int cols, uint64_t *id, int *seg); /* Read the offset from the anchor at the current width. */ -int term_hist_view_scroll_offset(const struct hist_view *v, const struct hist *h, int cols); -void term_hist_view_scroll(struct hist_view *v, const struct hist *h, int cols, +int wsap_vtcore_hist_view_scroll_offset(const struct hist_view *v, const struct hist *h, int cols); +void wsap_vtcore_hist_view_scroll(struct hist_view *v, const struct hist *h, int cols, struct line_pos screen_top, int lines); -void term_hist_view_scroll_to(struct hist_view *v, const struct hist *h, int cols, +void wsap_vtcore_hist_view_scroll_to(struct hist_view *v, const struct hist *h, int cols, struct line_pos screen_top, int offset); struct hist_view_pos { @@ -53,10 +53,10 @@ struct hist_view_pos { }; /* Clamp an evicted anchor. This does not update the index on the write path. */ -void term_hist_view_note_push(struct hist_view *v, const struct hist *h, int cols); -void term_hist_view_rewrap(struct hist_view *v, const struct hist *h, int cols); +void wsap_vtcore_hist_view_note_push(struct hist_view *v, const struct hist *h, int cols); +void wsap_vtcore_hist_view_rewrap(struct hist_view *v, const struct hist *h, int cols); -bool term_hist_view_row_pos(const struct hist_view *v, const struct hist *h, int cols, +bool wsap_vtcore_hist_view_row_pos(const struct hist_view *v, const struct hist *h, int cols, int screen_rows, struct line_pos screen_top, int y, struct hist_view_pos *pos); diff --git a/src/input.c b/src/input.c index 2f0cd5c..7f76bb7 100644 --- a/src/input.c +++ b/src/input.c @@ -1,4 +1,4 @@ -#include "term.h" +#include "wsap_vtcore.h" #include "unicode/utf8.h" #include <string.h> @@ -53,18 +53,18 @@ static inline void sb_u32(struct seqbuf *sb, uint32_t val) static inline void sb_utf8(struct seqbuf *sb, uint32_t cp) { char tmp[8]; - size_t n = (size_t)term_utf8_encode(cp, tmp); + size_t n = (size_t)wsap_vtcore_utf8_encode(cp, tmp); sb_bytes(sb, tmp, n); } -static struct term_input_result sb_result(const struct seqbuf *sb, const char *buf) +static struct wsap_vtcore_input_result sb_result(const struct seqbuf *sb, const char *buf) { if (sb->overflow) - return (struct term_input_result){ .status = TERM_INPUT_BUFFER_FULL }; + return (struct wsap_vtcore_input_result){ .status = WSAP_VTCORE_INPUT_BUFFER_FULL }; size_t len = (size_t)(sb->p - buf); - return (struct term_input_result){ - .status = len ? TERM_INPUT_BYTES : TERM_INPUT_CONSUMED, + return (struct wsap_vtcore_input_result){ + .status = len ? WSAP_VTCORE_INPUT_BYTES : WSAP_VTCORE_INPUT_CONSUMED, .len = len, }; } @@ -74,122 +74,122 @@ struct kitty_desc { char final; }; -static const struct kitty_desc kitty_desc[TERM_KEY_COUNT] = { - [TERM_KEY_RETURN] = { 13, 'u' }, - [TERM_KEY_BACKSPACE] = { 127, 'u' }, - [TERM_KEY_TAB] = { 9, 'u' }, - [TERM_KEY_ESCAPE] = { 27, 'u' }, - - [TERM_KEY_UP] = { 1, 'A' }, - [TERM_KEY_DOWN] = { 1, 'B' }, - [TERM_KEY_RIGHT] = { 1, 'C' }, - [TERM_KEY_LEFT] = { 1, 'D' }, - [TERM_KEY_HOME] = { 1, 'H' }, - [TERM_KEY_END] = { 1, 'F' }, - [TERM_KEY_PAGE_UP] = { 5, '~' }, - [TERM_KEY_PAGE_DOWN] = { 6, '~' }, - [TERM_KEY_INSERT] = { 2, '~' }, - [TERM_KEY_DELETE] = { 3, '~' }, - - [TERM_KEY_F1] = { 1, 'P' }, - [TERM_KEY_F2] = { 1, 'Q' }, - [TERM_KEY_F3] = { 13, '~' }, - [TERM_KEY_F4] = { 1, 'S' }, - [TERM_KEY_F5] = { 15, '~' }, - [TERM_KEY_F6] = { 17, '~' }, - [TERM_KEY_F7] = { 18, '~' }, - [TERM_KEY_F8] = { 19, '~' }, - [TERM_KEY_F9] = { 20, '~' }, - [TERM_KEY_F10] = { 21, '~' }, - [TERM_KEY_F11] = { 23, '~' }, - [TERM_KEY_F12] = { 24, '~' }, - [TERM_KEY_F13] = { 57376, 'u' }, - [TERM_KEY_F14] = { 57377, 'u' }, - [TERM_KEY_F15] = { 57378, 'u' }, - [TERM_KEY_F16] = { 57379, 'u' }, - [TERM_KEY_F17] = { 57380, 'u' }, - [TERM_KEY_F18] = { 57381, 'u' }, - [TERM_KEY_F19] = { 57382, 'u' }, - [TERM_KEY_F20] = { 57383, 'u' }, - [TERM_KEY_F21] = { 57384, 'u' }, - [TERM_KEY_F22] = { 57385, 'u' }, - [TERM_KEY_F23] = { 57386, 'u' }, - [TERM_KEY_F24] = { 57387, 'u' }, - [TERM_KEY_F25] = { 57388, 'u' }, - [TERM_KEY_F26] = { 57389, 'u' }, - [TERM_KEY_F27] = { 57390, 'u' }, - [TERM_KEY_F28] = { 57391, 'u' }, - [TERM_KEY_F29] = { 57392, 'u' }, - [TERM_KEY_F30] = { 57393, 'u' }, - [TERM_KEY_F31] = { 57394, 'u' }, - [TERM_KEY_F32] = { 57395, 'u' }, - [TERM_KEY_F33] = { 57396, 'u' }, - [TERM_KEY_F34] = { 57397, 'u' }, - [TERM_KEY_F35] = { 57398, 'u' }, - - [TERM_KEY_KP_0] = { 57399, 'u' }, - [TERM_KEY_KP_1] = { 57400, 'u' }, - [TERM_KEY_KP_2] = { 57401, 'u' }, - [TERM_KEY_KP_3] = { 57402, 'u' }, - [TERM_KEY_KP_4] = { 57403, 'u' }, - [TERM_KEY_KP_5] = { 57404, 'u' }, - [TERM_KEY_KP_6] = { 57405, 'u' }, - [TERM_KEY_KP_7] = { 57406, 'u' }, - [TERM_KEY_KP_8] = { 57407, 'u' }, - [TERM_KEY_KP_9] = { 57408, 'u' }, - [TERM_KEY_KP_DECIMAL] = { 57409, 'u' }, - [TERM_KEY_KP_DIVIDE] = { 57410, 'u' }, - [TERM_KEY_KP_MULTIPLY] = { 57411, 'u' }, - [TERM_KEY_KP_SUBTRACT] = { 57412, 'u' }, - [TERM_KEY_KP_ADD] = { 57413, 'u' }, - [TERM_KEY_KP_ENTER] = { 57414, 'u' }, - [TERM_KEY_KP_EQUAL] = { 57415, 'u' }, - [TERM_KEY_KP_SEPARATOR] = { 57416, 'u' }, - [TERM_KEY_KP_LEFT] = { 57417, 'u' }, - [TERM_KEY_KP_RIGHT] = { 57418, 'u' }, - [TERM_KEY_KP_UP] = { 57419, 'u' }, - [TERM_KEY_KP_DOWN] = { 57420, 'u' }, - [TERM_KEY_KP_PAGE_UP] = { 57421, 'u' }, - [TERM_KEY_KP_PAGE_DOWN] = { 57422, 'u' }, - [TERM_KEY_KP_HOME] = { 57423, 'u' }, - [TERM_KEY_KP_END] = { 57424, 'u' }, - [TERM_KEY_KP_INSERT] = { 57425, 'u' }, - [TERM_KEY_KP_DELETE] = { 57426, 'u' }, - [TERM_KEY_KP_BEGIN] = { 1, 'E' }, - - [TERM_KEY_CAPS_LOCK] = { 57358, 'u' }, - [TERM_KEY_SCROLL_LOCK] = { 57359, 'u' }, - [TERM_KEY_NUM_LOCK] = { 57360, 'u' }, - [TERM_KEY_PRINT_SCREEN] = { 57361, 'u' }, - [TERM_KEY_PAUSE] = { 57362, 'u' }, - [TERM_KEY_MENU] = { 57363, 'u' }, - - [TERM_KEY_MEDIA_PLAY] = { 57428, 'u' }, - [TERM_KEY_MEDIA_PAUSE] = { 57429, 'u' }, - [TERM_KEY_MEDIA_STOP] = { 57432, 'u' }, - [TERM_KEY_MEDIA_FORWARD] = { 57433, 'u' }, - [TERM_KEY_MEDIA_REWIND] = { 57434, 'u' }, - [TERM_KEY_MEDIA_NEXT] = { 57435, 'u' }, - [TERM_KEY_MEDIA_PREV] = { 57436, 'u' }, - [TERM_KEY_MEDIA_RECORD] = { 57437, 'u' }, - [TERM_KEY_VOLUME_DOWN] = { 57438, 'u' }, - [TERM_KEY_VOLUME_UP] = { 57439, 'u' }, - [TERM_KEY_MUTE] = { 57440, 'u' }, - - [TERM_KEY_LSHIFT] = { 57441, 'u' }, - [TERM_KEY_LCTRL] = { 57442, 'u' }, - [TERM_KEY_LALT] = { 57443, 'u' }, - [TERM_KEY_LSUPER] = { 57444, 'u' }, - [TERM_KEY_LHYPER] = { 57445, 'u' }, - [TERM_KEY_LMETA] = { 57446, 'u' }, - [TERM_KEY_RSHIFT] = { 57447, 'u' }, - [TERM_KEY_RCTRL] = { 57448, 'u' }, - [TERM_KEY_RALT] = { 57449, 'u' }, - [TERM_KEY_RSUPER] = { 57450, 'u' }, - [TERM_KEY_RHYPER] = { 57451, 'u' }, - [TERM_KEY_RMETA] = { 57452, 'u' }, - [TERM_KEY_ISO_LEVEL3_SHIFT] = { 57453, 'u' }, - [TERM_KEY_ISO_LEVEL5_SHIFT] = { 57454, 'u' }, +static const struct kitty_desc kitty_desc[WSAP_VTCORE_KEY_COUNT] = { + [WSAP_VTCORE_KEY_RETURN] = { 13, 'u' }, + [WSAP_VTCORE_KEY_BACKSPACE] = { 127, 'u' }, + [WSAP_VTCORE_KEY_TAB] = { 9, 'u' }, + [WSAP_VTCORE_KEY_ESCAPE] = { 27, 'u' }, + + [WSAP_VTCORE_KEY_UP] = { 1, 'A' }, + [WSAP_VTCORE_KEY_DOWN] = { 1, 'B' }, + [WSAP_VTCORE_KEY_RIGHT] = { 1, 'C' }, + [WSAP_VTCORE_KEY_LEFT] = { 1, 'D' }, + [WSAP_VTCORE_KEY_HOME] = { 1, 'H' }, + [WSAP_VTCORE_KEY_END] = { 1, 'F' }, + [WSAP_VTCORE_KEY_PAGE_UP] = { 5, '~' }, + [WSAP_VTCORE_KEY_PAGE_DOWN] = { 6, '~' }, + [WSAP_VTCORE_KEY_INSERT] = { 2, '~' }, + [WSAP_VTCORE_KEY_DELETE] = { 3, '~' }, + + [WSAP_VTCORE_KEY_F1] = { 1, 'P' }, + [WSAP_VTCORE_KEY_F2] = { 1, 'Q' }, + [WSAP_VTCORE_KEY_F3] = { 13, '~' }, + [WSAP_VTCORE_KEY_F4] = { 1, 'S' }, + [WSAP_VTCORE_KEY_F5] = { 15, '~' }, + [WSAP_VTCORE_KEY_F6] = { 17, '~' }, + [WSAP_VTCORE_KEY_F7] = { 18, '~' }, + [WSAP_VTCORE_KEY_F8] = { 19, '~' }, + [WSAP_VTCORE_KEY_F9] = { 20, '~' }, + [WSAP_VTCORE_KEY_F10] = { 21, '~' }, + [WSAP_VTCORE_KEY_F11] = { 23, '~' }, + [WSAP_VTCORE_KEY_F12] = { 24, '~' }, + [WSAP_VTCORE_KEY_F13] = { 57376, 'u' }, + [WSAP_VTCORE_KEY_F14] = { 57377, 'u' }, + [WSAP_VTCORE_KEY_F15] = { 57378, 'u' }, + [WSAP_VTCORE_KEY_F16] = { 57379, 'u' }, + [WSAP_VTCORE_KEY_F17] = { 57380, 'u' }, + [WSAP_VTCORE_KEY_F18] = { 57381, 'u' }, + [WSAP_VTCORE_KEY_F19] = { 57382, 'u' }, + [WSAP_VTCORE_KEY_F20] = { 57383, 'u' }, + [WSAP_VTCORE_KEY_F21] = { 57384, 'u' }, + [WSAP_VTCORE_KEY_F22] = { 57385, 'u' }, + [WSAP_VTCORE_KEY_F23] = { 57386, 'u' }, + [WSAP_VTCORE_KEY_F24] = { 57387, 'u' }, + [WSAP_VTCORE_KEY_F25] = { 57388, 'u' }, + [WSAP_VTCORE_KEY_F26] = { 57389, 'u' }, + [WSAP_VTCORE_KEY_F27] = { 57390, 'u' }, + [WSAP_VTCORE_KEY_F28] = { 57391, 'u' }, + [WSAP_VTCORE_KEY_F29] = { 57392, 'u' }, + [WSAP_VTCORE_KEY_F30] = { 57393, 'u' }, + [WSAP_VTCORE_KEY_F31] = { 57394, 'u' }, + [WSAP_VTCORE_KEY_F32] = { 57395, 'u' }, + [WSAP_VTCORE_KEY_F33] = { 57396, 'u' }, + [WSAP_VTCORE_KEY_F34] = { 57397, 'u' }, + [WSAP_VTCORE_KEY_F35] = { 57398, 'u' }, + + [WSAP_VTCORE_KEY_KP_0] = { 57399, 'u' }, + [WSAP_VTCORE_KEY_KP_1] = { 57400, 'u' }, + [WSAP_VTCORE_KEY_KP_2] = { 57401, 'u' }, + [WSAP_VTCORE_KEY_KP_3] = { 57402, 'u' }, + [WSAP_VTCORE_KEY_KP_4] = { 57403, 'u' }, + [WSAP_VTCORE_KEY_KP_5] = { 57404, 'u' }, + [WSAP_VTCORE_KEY_KP_6] = { 57405, 'u' }, + [WSAP_VTCORE_KEY_KP_7] = { 57406, 'u' }, + [WSAP_VTCORE_KEY_KP_8] = { 57407, 'u' }, + [WSAP_VTCORE_KEY_KP_9] = { 57408, 'u' }, + [WSAP_VTCORE_KEY_KP_DECIMAL] = { 57409, 'u' }, + [WSAP_VTCORE_KEY_KP_DIVIDE] = { 57410, 'u' }, + [WSAP_VTCORE_KEY_KP_MULTIPLY] = { 57411, 'u' }, + [WSAP_VTCORE_KEY_KP_SUBTRACT] = { 57412, 'u' }, + [WSAP_VTCORE_KEY_KP_ADD] = { 57413, 'u' }, + [WSAP_VTCORE_KEY_KP_ENTER] = { 57414, 'u' }, + [WSAP_VTCORE_KEY_KP_EQUAL] = { 57415, 'u' }, + [WSAP_VTCORE_KEY_KP_SEPARATOR] = { 57416, 'u' }, + [WSAP_VTCORE_KEY_KP_LEFT] = { 57417, 'u' }, + [WSAP_VTCORE_KEY_KP_RIGHT] = { 57418, 'u' }, + [WSAP_VTCORE_KEY_KP_UP] = { 57419, 'u' }, + [WSAP_VTCORE_KEY_KP_DOWN] = { 57420, 'u' }, + [WSAP_VTCORE_KEY_KP_PAGE_UP] = { 57421, 'u' }, + [WSAP_VTCORE_KEY_KP_PAGE_DOWN] = { 57422, 'u' }, + [WSAP_VTCORE_KEY_KP_HOME] = { 57423, 'u' }, + [WSAP_VTCORE_KEY_KP_END] = { 57424, 'u' }, + [WSAP_VTCORE_KEY_KP_INSERT] = { 57425, 'u' }, + [WSAP_VTCORE_KEY_KP_DELETE] = { 57426, 'u' }, + [WSAP_VTCORE_KEY_KP_BEGIN] = { 1, 'E' }, + + [WSAP_VTCORE_KEY_CAPS_LOCK] = { 57358, 'u' }, + [WSAP_VTCORE_KEY_SCROLL_LOCK] = { 57359, 'u' }, + [WSAP_VTCORE_KEY_NUM_LOCK] = { 57360, 'u' }, + [WSAP_VTCORE_KEY_PRINT_SCREEN] = { 57361, 'u' }, + [WSAP_VTCORE_KEY_PAUSE] = { 57362, 'u' }, + [WSAP_VTCORE_KEY_MENU] = { 57363, 'u' }, + + [WSAP_VTCORE_KEY_MEDIA_PLAY] = { 57428, 'u' }, + [WSAP_VTCORE_KEY_MEDIA_PAUSE] = { 57429, 'u' }, + [WSAP_VTCORE_KEY_MEDIA_STOP] = { 57432, 'u' }, + [WSAP_VTCORE_KEY_MEDIA_FORWARD] = { 57433, 'u' }, + [WSAP_VTCORE_KEY_MEDIA_REWIND] = { 57434, 'u' }, + [WSAP_VTCORE_KEY_MEDIA_NEXT] = { 57435, 'u' }, + [WSAP_VTCORE_KEY_MEDIA_PREV] = { 57436, 'u' }, + [WSAP_VTCORE_KEY_MEDIA_RECORD] = { 57437, 'u' }, + [WSAP_VTCORE_KEY_VOLUME_DOWN] = { 57438, 'u' }, + [WSAP_VTCORE_KEY_VOLUME_UP] = { 57439, 'u' }, + [WSAP_VTCORE_KEY_MUTE] = { 57440, 'u' }, + + [WSAP_VTCORE_KEY_LSHIFT] = { 57441, 'u' }, + [WSAP_VTCORE_KEY_LCTRL] = { 57442, 'u' }, + [WSAP_VTCORE_KEY_LALT] = { 57443, 'u' }, + [WSAP_VTCORE_KEY_LSUPER] = { 57444, 'u' }, + [WSAP_VTCORE_KEY_LHYPER] = { 57445, 'u' }, + [WSAP_VTCORE_KEY_LMETA] = { 57446, 'u' }, + [WSAP_VTCORE_KEY_RSHIFT] = { 57447, 'u' }, + [WSAP_VTCORE_KEY_RCTRL] = { 57448, 'u' }, + [WSAP_VTCORE_KEY_RALT] = { 57449, 'u' }, + [WSAP_VTCORE_KEY_RSUPER] = { 57450, 'u' }, + [WSAP_VTCORE_KEY_RHYPER] = { 57451, 'u' }, + [WSAP_VTCORE_KEY_RMETA] = { 57452, 'u' }, + [WSAP_VTCORE_KEY_ISO_LEVEL3_SHIFT] = { 57453, 'u' }, + [WSAP_VTCORE_KEY_ISO_LEVEL5_SHIFT] = { 57454, 'u' }, }; struct legacy_desc { @@ -197,61 +197,61 @@ struct legacy_desc { char final; bool app_cursor; char keypad_ss3; - enum term_key equiv; + enum wsap_vtcore_key equiv; }; -static const struct legacy_desc legacy_desc[TERM_KEY_COUNT] = { - [TERM_KEY_UP] = { .tilde = 0, .final = 'A', .app_cursor = true }, - [TERM_KEY_DOWN] = { .tilde = 0, .final = 'B', .app_cursor = true }, - [TERM_KEY_RIGHT] = { .tilde = 0, .final = 'C', .app_cursor = true }, - [TERM_KEY_LEFT] = { .tilde = 0, .final = 'D', .app_cursor = true }, - [TERM_KEY_HOME] = { .tilde = 0, .final = 'H', .app_cursor = true }, - [TERM_KEY_END] = { .tilde = 0, .final = 'F', .app_cursor = true }, - [TERM_KEY_PAGE_UP] = { .tilde = 5, .final = '~' }, - [TERM_KEY_PAGE_DOWN] = { .tilde = 6, .final = '~' }, - [TERM_KEY_INSERT] = { .tilde = 2, .final = '~' }, - [TERM_KEY_DELETE] = { .tilde = 3, .final = '~' }, - - [TERM_KEY_F1] = { .tilde = 0, .final = 'P' }, - [TERM_KEY_F2] = { .tilde = 0, .final = 'Q' }, - [TERM_KEY_F3] = { .tilde = 0, .final = 'R' }, - [TERM_KEY_F4] = { .tilde = 0, .final = 'S' }, - [TERM_KEY_F5] = { .tilde = 15, .final = '~' }, - [TERM_KEY_F6] = { .tilde = 17, .final = '~' }, - [TERM_KEY_F7] = { .tilde = 18, .final = '~' }, - [TERM_KEY_F8] = { .tilde = 19, .final = '~' }, - [TERM_KEY_F9] = { .tilde = 20, .final = '~' }, - [TERM_KEY_F10] = { .tilde = 21, .final = '~' }, - [TERM_KEY_F11] = { .tilde = 23, .final = '~' }, - [TERM_KEY_F12] = { .tilde = 24, .final = '~' }, - - [TERM_KEY_KP_0] = { .keypad_ss3 = 'p' }, - [TERM_KEY_KP_1] = { .keypad_ss3 = 'q' }, - [TERM_KEY_KP_2] = { .keypad_ss3 = 'r' }, - [TERM_KEY_KP_3] = { .keypad_ss3 = 's' }, - [TERM_KEY_KP_4] = { .keypad_ss3 = 't' }, - [TERM_KEY_KP_5] = { .keypad_ss3 = 'u' }, - [TERM_KEY_KP_6] = { .keypad_ss3 = 'v' }, - [TERM_KEY_KP_7] = { .keypad_ss3 = 'w' }, - [TERM_KEY_KP_8] = { .keypad_ss3 = 'x' }, - [TERM_KEY_KP_9] = { .keypad_ss3 = 'y' }, - [TERM_KEY_KP_DECIMAL] = { .keypad_ss3 = 'n' }, - [TERM_KEY_KP_DIVIDE] = { .keypad_ss3 = 'o' }, - [TERM_KEY_KP_MULTIPLY] = { .keypad_ss3 = 'j' }, - [TERM_KEY_KP_SUBTRACT] = { .keypad_ss3 = 'm' }, - [TERM_KEY_KP_ADD] = { .keypad_ss3 = 'k' }, - [TERM_KEY_KP_ENTER] = { .keypad_ss3 = 'M', .equiv = TERM_KEY_RETURN }, - [TERM_KEY_KP_LEFT] = { .equiv = TERM_KEY_LEFT }, - [TERM_KEY_KP_RIGHT] = { .equiv = TERM_KEY_RIGHT }, - [TERM_KEY_KP_UP] = { .equiv = TERM_KEY_UP }, - [TERM_KEY_KP_DOWN] = { .equiv = TERM_KEY_DOWN }, - [TERM_KEY_KP_PAGE_UP] = { .equiv = TERM_KEY_PAGE_UP }, - [TERM_KEY_KP_PAGE_DOWN] = { .equiv = TERM_KEY_PAGE_DOWN }, - [TERM_KEY_KP_HOME] = { .equiv = TERM_KEY_HOME }, - [TERM_KEY_KP_END] = { .equiv = TERM_KEY_END }, - [TERM_KEY_KP_INSERT] = { .equiv = TERM_KEY_INSERT }, - [TERM_KEY_KP_DELETE] = { .equiv = TERM_KEY_DELETE }, - [TERM_KEY_KP_BEGIN] = { .tilde = 0, .final = 'E' }, +static const struct legacy_desc legacy_desc[WSAP_VTCORE_KEY_COUNT] = { + [WSAP_VTCORE_KEY_UP] = { .tilde = 0, .final = 'A', .app_cursor = true }, + [WSAP_VTCORE_KEY_DOWN] = { .tilde = 0, .final = 'B', .app_cursor = true }, + [WSAP_VTCORE_KEY_RIGHT] = { .tilde = 0, .final = 'C', .app_cursor = true }, + [WSAP_VTCORE_KEY_LEFT] = { .tilde = 0, .final = 'D', .app_cursor = true }, + [WSAP_VTCORE_KEY_HOME] = { .tilde = 0, .final = 'H', .app_cursor = true }, + [WSAP_VTCORE_KEY_END] = { .tilde = 0, .final = 'F', .app_cursor = true }, + [WSAP_VTCORE_KEY_PAGE_UP] = { .tilde = 5, .final = '~' }, + [WSAP_VTCORE_KEY_PAGE_DOWN] = { .tilde = 6, .final = '~' }, + [WSAP_VTCORE_KEY_INSERT] = { .tilde = 2, .final = '~' }, + [WSAP_VTCORE_KEY_DELETE] = { .tilde = 3, .final = '~' }, + + [WSAP_VTCORE_KEY_F1] = { .tilde = 0, .final = 'P' }, + [WSAP_VTCORE_KEY_F2] = { .tilde = 0, .final = 'Q' }, + [WSAP_VTCORE_KEY_F3] = { .tilde = 0, .final = 'R' }, + [WSAP_VTCORE_KEY_F4] = { .tilde = 0, .final = 'S' }, + [WSAP_VTCORE_KEY_F5] = { .tilde = 15, .final = '~' }, + [WSAP_VTCORE_KEY_F6] = { .tilde = 17, .final = '~' }, + [WSAP_VTCORE_KEY_F7] = { .tilde = 18, .final = '~' }, + [WSAP_VTCORE_KEY_F8] = { .tilde = 19, .final = '~' }, + [WSAP_VTCORE_KEY_F9] = { .tilde = 20, .final = '~' }, + [WSAP_VTCORE_KEY_F10] = { .tilde = 21, .final = '~' }, + [WSAP_VTCORE_KEY_F11] = { .tilde = 23, .final = '~' }, + [WSAP_VTCORE_KEY_F12] = { .tilde = 24, .final = '~' }, + + [WSAP_VTCORE_KEY_KP_0] = { .keypad_ss3 = 'p' }, + [WSAP_VTCORE_KEY_KP_1] = { .keypad_ss3 = 'q' }, + [WSAP_VTCORE_KEY_KP_2] = { .keypad_ss3 = 'r' }, + [WSAP_VTCORE_KEY_KP_3] = { .keypad_ss3 = 's' }, + [WSAP_VTCORE_KEY_KP_4] = { .keypad_ss3 = 't' }, + [WSAP_VTCORE_KEY_KP_5] = { .keypad_ss3 = 'u' }, + [WSAP_VTCORE_KEY_KP_6] = { .keypad_ss3 = 'v' }, + [WSAP_VTCORE_KEY_KP_7] = { .keypad_ss3 = 'w' }, + [WSAP_VTCORE_KEY_KP_8] = { .keypad_ss3 = 'x' }, + [WSAP_VTCORE_KEY_KP_9] = { .keypad_ss3 = 'y' }, + [WSAP_VTCORE_KEY_KP_DECIMAL] = { .keypad_ss3 = 'n' }, + [WSAP_VTCORE_KEY_KP_DIVIDE] = { .keypad_ss3 = 'o' }, + [WSAP_VTCORE_KEY_KP_MULTIPLY] = { .keypad_ss3 = 'j' }, + [WSAP_VTCORE_KEY_KP_SUBTRACT] = { .keypad_ss3 = 'm' }, + [WSAP_VTCORE_KEY_KP_ADD] = { .keypad_ss3 = 'k' }, + [WSAP_VTCORE_KEY_KP_ENTER] = { .keypad_ss3 = 'M', .equiv = WSAP_VTCORE_KEY_RETURN }, + [WSAP_VTCORE_KEY_KP_LEFT] = { .equiv = WSAP_VTCORE_KEY_LEFT }, + [WSAP_VTCORE_KEY_KP_RIGHT] = { .equiv = WSAP_VTCORE_KEY_RIGHT }, + [WSAP_VTCORE_KEY_KP_UP] = { .equiv = WSAP_VTCORE_KEY_UP }, + [WSAP_VTCORE_KEY_KP_DOWN] = { .equiv = WSAP_VTCORE_KEY_DOWN }, + [WSAP_VTCORE_KEY_KP_PAGE_UP] = { .equiv = WSAP_VTCORE_KEY_PAGE_UP }, + [WSAP_VTCORE_KEY_KP_PAGE_DOWN] = { .equiv = WSAP_VTCORE_KEY_PAGE_DOWN }, + [WSAP_VTCORE_KEY_KP_HOME] = { .equiv = WSAP_VTCORE_KEY_HOME }, + [WSAP_VTCORE_KEY_KP_END] = { .equiv = WSAP_VTCORE_KEY_END }, + [WSAP_VTCORE_KEY_KP_INSERT] = { .equiv = WSAP_VTCORE_KEY_INSERT }, + [WSAP_VTCORE_KEY_KP_DELETE] = { .equiv = WSAP_VTCORE_KEY_DELETE }, + [WSAP_VTCORE_KEY_KP_BEGIN] = { .tilde = 0, .final = 'E' }, }; enum input_mod_key { @@ -268,42 +268,42 @@ enum input_mod_key { struct mod_desc { enum input_mod_key group; - enum term_key partner; + enum wsap_vtcore_key partner; }; -static const struct mod_desc mod_desc[TERM_KEY_COUNT] = { - [TERM_KEY_LSHIFT] = { MOD_KEY_SHIFT, TERM_KEY_RSHIFT }, - [TERM_KEY_RSHIFT] = { MOD_KEY_SHIFT, TERM_KEY_LSHIFT }, - [TERM_KEY_LCTRL] = { MOD_KEY_CTRL, TERM_KEY_RCTRL }, - [TERM_KEY_RCTRL] = { MOD_KEY_CTRL, TERM_KEY_LCTRL }, - [TERM_KEY_LALT] = { MOD_KEY_ALT, TERM_KEY_RALT }, - [TERM_KEY_RALT] = { MOD_KEY_ALT, TERM_KEY_LALT }, - [TERM_KEY_LSUPER] = { MOD_KEY_SUPER, TERM_KEY_RSUPER }, - [TERM_KEY_RSUPER] = { MOD_KEY_SUPER, TERM_KEY_LSUPER }, - [TERM_KEY_LHYPER] = { MOD_KEY_HYPER, TERM_KEY_RHYPER }, - [TERM_KEY_RHYPER] = { MOD_KEY_HYPER, TERM_KEY_LHYPER }, - [TERM_KEY_LMETA] = { MOD_KEY_META, TERM_KEY_RMETA }, - [TERM_KEY_RMETA] = { MOD_KEY_META, TERM_KEY_LMETA }, - [TERM_KEY_ISO_LEVEL3_SHIFT] = { MOD_KEY_ISO3, TERM_KEY_NONE }, - [TERM_KEY_ISO_LEVEL5_SHIFT] = { MOD_KEY_ISO5, TERM_KEY_NONE }, +static const struct mod_desc mod_desc[WSAP_VTCORE_KEY_COUNT] = { + [WSAP_VTCORE_KEY_LSHIFT] = { MOD_KEY_SHIFT, WSAP_VTCORE_KEY_RSHIFT }, + [WSAP_VTCORE_KEY_RSHIFT] = { MOD_KEY_SHIFT, WSAP_VTCORE_KEY_LSHIFT }, + [WSAP_VTCORE_KEY_LCTRL] = { MOD_KEY_CTRL, WSAP_VTCORE_KEY_RCTRL }, + [WSAP_VTCORE_KEY_RCTRL] = { MOD_KEY_CTRL, WSAP_VTCORE_KEY_LCTRL }, + [WSAP_VTCORE_KEY_LALT] = { MOD_KEY_ALT, WSAP_VTCORE_KEY_RALT }, + [WSAP_VTCORE_KEY_RALT] = { MOD_KEY_ALT, WSAP_VTCORE_KEY_LALT }, + [WSAP_VTCORE_KEY_LSUPER] = { MOD_KEY_SUPER, WSAP_VTCORE_KEY_RSUPER }, + [WSAP_VTCORE_KEY_RSUPER] = { MOD_KEY_SUPER, WSAP_VTCORE_KEY_LSUPER }, + [WSAP_VTCORE_KEY_LHYPER] = { MOD_KEY_HYPER, WSAP_VTCORE_KEY_RHYPER }, + [WSAP_VTCORE_KEY_RHYPER] = { MOD_KEY_HYPER, WSAP_VTCORE_KEY_LHYPER }, + [WSAP_VTCORE_KEY_LMETA] = { MOD_KEY_META, WSAP_VTCORE_KEY_RMETA }, + [WSAP_VTCORE_KEY_RMETA] = { MOD_KEY_META, WSAP_VTCORE_KEY_LMETA }, + [WSAP_VTCORE_KEY_ISO_LEVEL3_SHIFT] = { MOD_KEY_ISO3, WSAP_VTCORE_KEY_NONE }, + [WSAP_VTCORE_KEY_ISO_LEVEL5_SHIFT] = { MOD_KEY_ISO5, WSAP_VTCORE_KEY_NONE }, }; static const unsigned mod_group_input_mod[MOD_KEY_COUNT] = { - TERM_MOD_SHIFT, TERM_MOD_CTRL, TERM_MOD_ALT, - TERM_MOD_SUPER, TERM_MOD_HYPER, TERM_MOD_META, + WSAP_VTCORE_MOD_SHIFT, WSAP_VTCORE_MOD_CTRL, WSAP_VTCORE_MOD_ALT, + WSAP_VTCORE_MOD_SUPER, WSAP_VTCORE_MOD_HYPER, WSAP_VTCORE_MOD_META, 0, 0, }; -static inline bool key_is_modifier(enum term_key k) +static inline bool key_is_modifier(enum wsap_vtcore_key k) { - return (unsigned)k < TERM_KEY_COUNT && - (mod_desc[k].partner != TERM_KEY_NONE || + return (unsigned)k < WSAP_VTCORE_KEY_COUNT && + (mod_desc[k].partner != WSAP_VTCORE_KEY_NONE || mod_desc[k].group == MOD_KEY_ISO3 || mod_desc[k].group == MOD_KEY_ISO5); } -static unsigned effective_mods(const struct term_keyboard_state *s, - const struct term_key_event *ev) +static unsigned effective_mods(const struct wsap_vtcore_keyboard_state *s, + const struct wsap_vtcore_key_event *ev) { unsigned mods = ev->mods; if (!key_is_modifier(ev->key)) return mods; @@ -312,8 +312,8 @@ static unsigned effective_mods(const struct term_keyboard_state *s, if (d->group >= MOD_KEY_ISO3) return mods; unsigned bit = mod_group_input_mod[d->group]; - bool other_held = term_keyboard_key_down(s, d->partner); - if (ev->action != TERM_KEY_RELEASE || other_held) mods |= bit; + bool other_held = wsap_vtcore_keyboard_key_down(s, d->partner); + if (ev->action != WSAP_VTCORE_KEY_RELEASE || other_held) mods |= bit; else mods &= ~bit; return mods; } @@ -325,13 +325,13 @@ static void format_kitty(struct seqbuf *sb, uint32_t code, char final, { sb_bytes(sb, "\033[", 2); if (final != 'u' && final != '~' && code <= 1 && !shifted && !base && - !mods && !(flags & TERM_KEYBOARD_EVENT_TYPES) && !report_text) { + !mods && !(flags & WSAP_VTCORE_KEYBOARD_EVENT_TYPES) && !report_text) { sb_ch(sb, final); return; } sb_u32(sb, code); - if ((flags & TERM_KEYBOARD_ALTERNATE_KEYS) && !functional) { + if ((flags & WSAP_VTCORE_KEYBOARD_ALTERNATE_KEYS) && !functional) { if (shifted) { sb_ch(sb, ':'); sb_u32(sb, shifted); @@ -342,11 +342,11 @@ static void format_kitty(struct seqbuf *sb, uint32_t code, char final, sb_u32(sb, base); } } - if (mods || (flags & TERM_KEYBOARD_EVENT_TYPES) || report_text) { + if (mods || (flags & WSAP_VTCORE_KEYBOARD_EVENT_TYPES) || report_text) { sb_ch(sb, ';'); sb_u32(sb, mods + 1); } - if ((flags & TERM_KEYBOARD_EVENT_TYPES) && event != 1) { + if ((flags & WSAP_VTCORE_KEYBOARD_EVENT_TYPES) && event != 1) { sb_ch(sb, ':'); sb_u32(sb, event); } @@ -357,55 +357,55 @@ static void format_kitty(struct seqbuf *sb, uint32_t code, char final, sb_ch(sb, final); } -static bool encode_kitty(const struct term_keyboard_state *s, - const struct term_key_event *ev, - const struct term_modes *m, +static bool encode_kitty(const struct wsap_vtcore_keyboard_state *s, + const struct wsap_vtcore_key_event *ev, + const struct wsap_vtcore_modes *m, struct seqbuf *sb) { unsigned flags = m->keyboard; - unsigned event = ev->action == TERM_KEY_PRESS ? 1u : - ev->action == TERM_KEY_REPEAT ? 2u : 3u; - if (!flags) return ev->action == TERM_KEY_RELEASE; + unsigned event = ev->action == WSAP_VTCORE_KEY_PRESS ? 1u : + ev->action == WSAP_VTCORE_KEY_REPEAT ? 2u : 3u; + if (!flags) return ev->action == WSAP_VTCORE_KEY_RELEASE; const struct kitty_desc *d = &kitty_desc[ev->key]; bool functional = d->code != 0; char final = functional ? d->final : 'u'; - bool all = (flags & TERM_KEYBOARD_ALL_KEYS) != 0; + bool all = (flags & WSAP_VTCORE_KEYBOARD_ALL_KEYS) != 0; - bool lock = ev->key == TERM_KEY_CAPS_LOCK || ev->key == TERM_KEY_SCROLL_LOCK || - ev->key == TERM_KEY_NUM_LOCK; + bool lock = ev->key == WSAP_VTCORE_KEY_CAPS_LOCK || ev->key == WSAP_VTCORE_KEY_SCROLL_LOCK || + ev->key == WSAP_VTCORE_KEY_NUM_LOCK; if ((key_is_modifier(ev->key) || lock) && !all) return true; unsigned mods = effective_mods(s, ev); - if (ev->action == TERM_KEY_PRESS) { - if (ev->key == TERM_KEY_CAPS_LOCK) mods ^= TERM_MOD_CAPS; - if (ev->key == TERM_KEY_NUM_LOCK) mods ^= TERM_MOD_NUM; + if (ev->action == WSAP_VTCORE_KEY_PRESS) { + if (ev->key == WSAP_VTCORE_KEY_CAPS_LOCK) mods ^= WSAP_VTCORE_MOD_CAPS; + if (ev->key == WSAP_VTCORE_KEY_NUM_LOCK) mods ^= WSAP_VTCORE_MOD_NUM; } - bool plain_control = ev->key == TERM_KEY_RETURN || ev->key == TERM_KEY_TAB || - ev->key == TERM_KEY_BACKSPACE; - if (ev->action == TERM_KEY_RELEASE && - (!(flags & TERM_KEYBOARD_EVENT_TYPES) || (!all && plain_control))) + bool plain_control = ev->key == WSAP_VTCORE_KEY_RETURN || ev->key == WSAP_VTCORE_KEY_TAB || + ev->key == WSAP_VTCORE_KEY_BACKSPACE; + if (ev->action == WSAP_VTCORE_KEY_RELEASE && + (!(flags & WSAP_VTCORE_KEYBOARD_EVENT_TYPES) || (!all && plain_control))) return true; - const unsigned command_mods = TERM_MOD_ALT | TERM_MOD_CTRL | - TERM_MOD_SUPER | TERM_MOD_HYPER | - TERM_MOD_META; + const unsigned command_mods = WSAP_VTCORE_MOD_ALT | WSAP_VTCORE_MOD_CTRL | + WSAP_VTCORE_MOD_SUPER | WSAP_VTCORE_MOD_HYPER | + WSAP_VTCORE_MOD_META; uint32_t text = ev->text; bool has_text = text >= 32 && !(text >= 127 && text < 160) && !(mods & command_mods); - if (!all && has_text) return ev->action == TERM_KEY_RELEASE; + if (!all && has_text) return ev->action == WSAP_VTCORE_KEY_RELEASE; if (!all && plain_control && !(mods & 63)) - return ev->action == TERM_KEY_RELEASE; - if (!(flags & (TERM_KEYBOARD_DISAMBIGUATE | TERM_KEYBOARD_EVENT_TYPES | TERM_KEYBOARD_ALL_KEYS))) - return ev->action == TERM_KEY_RELEASE; + return ev->action == WSAP_VTCORE_KEY_RELEASE; + if (!(flags & (WSAP_VTCORE_KEYBOARD_DISAMBIGUATE | WSAP_VTCORE_KEYBOARD_EVENT_TYPES | WSAP_VTCORE_KEYBOARD_ALL_KEYS))) + return ev->action == WSAP_VTCORE_KEY_RELEASE; uint32_t code = d->code, shifted = 0, base = 0; if (!functional) { code = ev->codepoint; - if (flags & TERM_KEYBOARD_ALTERNATE_KEYS) { - shifted = (mods & TERM_MOD_SHIFT) ? ev->shifted : 0; + if (flags & WSAP_VTCORE_KEYBOARD_ALTERNATE_KEYS) { + shifted = (mods & WSAP_VTCORE_MOD_SHIFT) ? ev->shifted : 0; base = ev->base; if (shifted == code) shifted = 0; if (base == code) base = 0; @@ -413,25 +413,25 @@ static bool encode_kitty(const struct term_keyboard_state *s, } if (!code) return true; - bool report_text = all && (flags & TERM_KEYBOARD_ASSOCIATED_TEXT) && has_text && - ev->action != TERM_KEY_RELEASE; + bool report_text = all && (flags & WSAP_VTCORE_KEYBOARD_ASSOCIATED_TEXT) && has_text && + ev->action != WSAP_VTCORE_KEY_RELEASE; format_kitty(sb, code, final, flags, functional, shifted, base, mods & 0xff, event, report_text, text); return true; } -static uint32_t control_base_char(const struct term_key_event *ev) +static uint32_t control_base_char(const struct wsap_vtcore_key_event *ev) { - uint32_t ch = ((ev->mods & TERM_MOD_SHIFT) && ev->shifted) + uint32_t ch = ((ev->mods & WSAP_VTCORE_MOD_SHIFT) && ev->shifted) ? ev->shifted : ev->codepoint; return ch < 0x80 ? ch : 0; } -static bool encode_legacy(const struct term_key_event *ev, - const struct term_modes *m, +static bool encode_legacy(const struct wsap_vtcore_key_event *ev, + const struct wsap_vtcore_modes *m, struct seqbuf *sb) { - if (m->app_keypad && (unsigned)ev->keypad < TERM_KEY_COUNT && + if (m->app_keypad && (unsigned)ev->keypad < WSAP_VTCORE_KEY_COUNT && legacy_desc[ev->keypad].keypad_ss3) { sb_bytes(sb, "\033O", 2); sb_ch(sb, legacy_desc[ev->keypad].keypad_ss3); @@ -439,7 +439,7 @@ static bool encode_legacy(const struct term_key_event *ev, } uint32_t ch = control_base_char(ev); - if ((ev->mods & TERM_MOD_CTRL) && ch) { + if ((ev->mods & WSAP_VTCORE_MOD_CTRL) && ch) { if ((ch >= 'a' && ch <= 'z') || (ch >= '@' && ch <= '_')) { sb_ch(sb, (char)(ch & 0x1f)); return true; @@ -450,13 +450,13 @@ static bool encode_legacy(const struct term_key_event *ev, unsigned csi = ev->mods & 63; unsigned p = csi + 1; - bool shift = (ev->mods & TERM_MOD_SHIFT) != 0; + bool shift = (ev->mods & WSAP_VTCORE_MOD_SHIFT) != 0; - enum term_key k = ev->key; - if (legacy_desc[k].equiv != TERM_KEY_NONE) + enum wsap_vtcore_key k = ev->key; + if (legacy_desc[k].equiv != WSAP_VTCORE_KEY_NONE) k = legacy_desc[k].equiv; - if ((unsigned)k < TERM_KEY_COUNT) { + if ((unsigned)k < WSAP_VTCORE_KEY_COUNT) { const struct legacy_desc *d = &legacy_desc[k]; if (d->final) { if (d->tilde) { @@ -483,15 +483,15 @@ static bool encode_legacy(const struct term_key_event *ev, } switch (k) { - case TERM_KEY_RETURN: sb_ch(sb, '\r'); return true; - case TERM_KEY_BACKSPACE: + case WSAP_VTCORE_KEY_RETURN: sb_ch(sb, '\r'); return true; + case WSAP_VTCORE_KEY_BACKSPACE: sb_ch(sb, m->backarrow_bs ? '\x08' : '\x7f'); return true; - case TERM_KEY_TAB: + case WSAP_VTCORE_KEY_TAB: if (shift) { sb_bytes(sb, "\033[Z", 3); } else { sb_ch(sb, '\t'); } return true; - case TERM_KEY_ESCAPE: sb_ch(sb, '\033'); return true; + case WSAP_VTCORE_KEY_ESCAPE: sb_ch(sb, '\033'); return true; default: break; } @@ -502,64 +502,64 @@ static bool encode_legacy(const struct term_key_event *ev, return false; } -void term_keyboard_update(struct term_keyboard_state *s, const struct term_key_event *ev) +void wsap_vtcore_keyboard_update(struct wsap_vtcore_keyboard_state *s, const struct wsap_vtcore_key_event *ev) { - if (!s || !ev || ev->key <= TERM_KEY_NONE || ev->key >= TERM_KEY_COUNT) + if (!s || !ev || ev->key <= WSAP_VTCORE_KEY_NONE || ev->key >= WSAP_VTCORE_KEY_COUNT) return; - if (ev->action == TERM_KEY_RELEASE) + if (ev->action == WSAP_VTCORE_KEY_RELEASE) s->down[ev->key >> 6] &= ~(1ull << (ev->key & 63)); - else if (ev->action == TERM_KEY_PRESS || ev->action == TERM_KEY_REPEAT) + else if (ev->action == WSAP_VTCORE_KEY_PRESS || ev->action == WSAP_VTCORE_KEY_REPEAT) s->down[ev->key >> 6] |= 1ull << (ev->key & 63); } -bool term_keyboard_key_down(const struct term_keyboard_state *s, enum term_key key) +bool wsap_vtcore_keyboard_key_down(const struct wsap_vtcore_keyboard_state *s, enum wsap_vtcore_key key) { - return s && key > TERM_KEY_NONE && (unsigned)key < TERM_KEY_COUNT && + return s && key > WSAP_VTCORE_KEY_NONE && (unsigned)key < WSAP_VTCORE_KEY_COUNT && ((s->down[key >> 6] >> (key & 63)) & 1); } -static inline bool legacy_is_escape(const struct term_key_event *ev, - const struct term_modes *m) +static inline bool legacy_is_escape(const struct wsap_vtcore_key_event *ev, + const struct wsap_vtcore_modes *m) { - if (m->app_keypad && (unsigned)ev->keypad < TERM_KEY_COUNT && + if (m->app_keypad && (unsigned)ev->keypad < WSAP_VTCORE_KEY_COUNT && legacy_desc[ev->keypad].keypad_ss3) return true; - if ((ev->mods & TERM_MOD_CTRL) && control_base_char(ev) == '[') + if ((ev->mods & WSAP_VTCORE_MOD_CTRL) && control_base_char(ev) == '[') return true; - enum term_key k = ev->key; - if (legacy_desc[k].equiv != TERM_KEY_NONE) + enum wsap_vtcore_key k = ev->key; + if (legacy_desc[k].equiv != WSAP_VTCORE_KEY_NONE) k = legacy_desc[k].equiv; - if ((unsigned)k < TERM_KEY_COUNT && legacy_desc[k].final) + if ((unsigned)k < WSAP_VTCORE_KEY_COUNT && legacy_desc[k].final) return true; - if (k == TERM_KEY_ESCAPE) + if (k == WSAP_VTCORE_KEY_ESCAPE) return true; - if (k == TERM_KEY_TAB && (ev->mods & TERM_MOD_SHIFT)) + if (k == WSAP_VTCORE_KEY_TAB && (ev->mods & WSAP_VTCORE_MOD_SHIFT)) return true; if (ev->text == '\033') return true; return false; } -struct term_input_result term_input_encode_key(const struct term_keyboard_state *s, - const struct term_key_event *ev, - const struct term_modes *m, +struct wsap_vtcore_input_result wsap_vtcore_input_encode_key(const struct wsap_vtcore_keyboard_state *s, + const struct wsap_vtcore_key_event *ev, + const struct wsap_vtcore_modes *m, char *buf, size_t buf_sz) { - struct term_input_result out = {0}; + struct wsap_vtcore_input_result out = {0}; if (!ev || !m || !buf || - (ev->action != TERM_KEY_PRESS && ev->action != TERM_KEY_REPEAT && - ev->action != TERM_KEY_RELEASE) || - (unsigned)ev->key >= TERM_KEY_COUNT) + (ev->action != WSAP_VTCORE_KEY_PRESS && ev->action != WSAP_VTCORE_KEY_REPEAT && + ev->action != WSAP_VTCORE_KEY_RELEASE) || + (unsigned)ev->key >= WSAP_VTCORE_KEY_COUNT) return out; struct seqbuf sb = { .p = buf, .left = buf_sz }; bool handled = encode_kitty(s, ev, m, &sb); if (!handled) { - if (ev->action == TERM_KEY_RELEASE) + if (ev->action == WSAP_VTCORE_KEY_RELEASE) return out; - if ((ev->mods & TERM_MOD_ALT) && !legacy_is_escape(ev, m)) + if ((ev->mods & WSAP_VTCORE_MOD_ALT) && !legacy_is_escape(ev, m)) sb_ch(&sb, '\033'); handled = encode_legacy(ev, m, &sb); @@ -571,45 +571,45 @@ struct term_input_result term_input_encode_key(const struct term_keyboard_state return sb_result(&sb, buf); } -struct term_input_result term_input_encode_mouse(const struct term_mouse_event *ev, - const struct term_modes *m, +struct wsap_vtcore_input_result wsap_vtcore_input_encode_mouse(const struct wsap_vtcore_mouse_event *ev, + const struct wsap_vtcore_modes *m, char *buf, size_t buf_sz) { - struct term_input_result out = {0}; + struct wsap_vtcore_input_result out = {0}; if (!ev || !m || !buf) return out; - if (!m->mouse || (ev->mods & TERM_MOD_SHIFT)) return out; + if (!m->mouse || (ev->mods & WSAP_VTCORE_MOD_SHIFT)) return out; - out.status = TERM_INPUT_CONSUMED; - if (ev->kind == TERM_MOUSE_LEAVE) return out; - struct term_vector2i cell = ev->pos; + out.status = WSAP_VTCORE_INPUT_CONSUMED; + if (ev->kind == WSAP_VTCORE_MOUSE_LEAVE) return out; + struct wsap_vtcore_vector2i cell = ev->pos; if (cell.x < 0 || cell.y < 0 || cell.x >= m->grid.x || cell.y >= m->grid.y) return out; - if (m->mouse == TERM_MOUSE_X10 && (ev->kind == TERM_MOUSE_RELEASE || ev->kind == TERM_MOUSE_MOTION)) { + if (m->mouse == WSAP_VTCORE_MOUSE_X10 && (ev->kind == WSAP_VTCORE_MOUSE_RELEASE || ev->kind == WSAP_VTCORE_MOUSE_MOTION)) { return out; } - if (ev->kind == TERM_MOUSE_MOTION && (m->mouse == TERM_MOUSE_NORMAL || - (m->mouse == TERM_MOUSE_BUTTON && ev->button == TERM_MOUSE_BUTTON_NONE))) { + if (ev->kind == WSAP_VTCORE_MOUSE_MOTION && (m->mouse == WSAP_VTCORE_MOUSE_NORMAL || + (m->mouse == WSAP_VTCORE_MOUSE_BUTTON && ev->button == WSAP_VTCORE_MOUSE_BUTTON_NONE))) { return out; } int button; - if (ev->button >= TERM_MOUSE_BUTTON_PRIMARY && ev->button <= TERM_MOUSE_BUTTON_NONE) + if (ev->button >= WSAP_VTCORE_MOUSE_BUTTON_PRIMARY && ev->button <= WSAP_VTCORE_MOUSE_BUTTON_NONE) button = ev->button; - else if (ev->button >= TERM_MOUSE_BUTTON_EXTRA_1 && ev->button <= TERM_MOUSE_BUTTON_EXTRA_4) - button = 128 + ev->button - TERM_MOUSE_BUTTON_EXTRA_1; - else if (ev->button >= TERM_MOUSE_WHEEL_UP && ev->button <= TERM_MOUSE_WHEEL_RIGHT) - button = 64 + ev->button - TERM_MOUSE_WHEEL_UP; + else if (ev->button >= WSAP_VTCORE_MOUSE_BUTTON_EXTRA_1 && ev->button <= WSAP_VTCORE_MOUSE_BUTTON_EXTRA_4) + button = 128 + ev->button - WSAP_VTCORE_MOUSE_BUTTON_EXTRA_1; + else if (ev->button >= WSAP_VTCORE_MOUSE_WHEEL_UP && ev->button <= WSAP_VTCORE_MOUSE_WHEEL_RIGHT) + button = 64 + ev->button - WSAP_VTCORE_MOUSE_WHEEL_UP; else { return out; } int mods = 0; - if (ev->mods & TERM_MOD_ALT) mods |= 8; - if (ev->mods & TERM_MOD_CTRL) mods |= 16; + if (ev->mods & WSAP_VTCORE_MOD_ALT) mods |= 8; + if (ev->mods & WSAP_VTCORE_MOD_CTRL) mods |= 16; - int code = button | mods | (ev->kind == TERM_MOUSE_MOTION ? 32 : 0); - int legacy_code = ev->kind == TERM_MOUSE_RELEASE ? 3 | mods : code; - struct term_vector2i report = m->mouse_encoding == TERM_MOUSE_ENC_SGR_PIXELS + int code = button | mods | (ev->kind == WSAP_VTCORE_MOUSE_MOTION ? 32 : 0); + int legacy_code = ev->kind == WSAP_VTCORE_MOUSE_RELEASE ? 3 | mods : code; + struct wsap_vtcore_vector2i report = m->mouse_encoding == WSAP_VTCORE_MOUSE_ENC_SGR_PIXELS ? ev->pixel : cell; if (report.x < 0 || report.y < 0) return out; @@ -618,16 +618,16 @@ struct term_input_result term_input_encode_mouse(const struct term_mouse_event * struct seqbuf sb = { .p = buf, .left = buf_sz }; - if (m->mouse_encoding == TERM_MOUSE_ENC_SGR || - m->mouse_encoding == TERM_MOUSE_ENC_SGR_PIXELS) { + if (m->mouse_encoding == WSAP_VTCORE_MOUSE_ENC_SGR || + m->mouse_encoding == WSAP_VTCORE_MOUSE_ENC_SGR_PIXELS) { sb_bytes(&sb, "\033[<", 3); sb_u32(&sb, (uint32_t)code); sb_ch(&sb, ';'); sb_u32(&sb, report_x); sb_ch(&sb, ';'); sb_u32(&sb, report_y); - sb_ch(&sb, ev->kind == TERM_MOUSE_RELEASE ? 'm' : 'M'); - } else if (m->mouse_encoding == TERM_MOUSE_ENC_URXVT) { + sb_ch(&sb, ev->kind == WSAP_VTCORE_MOUSE_RELEASE ? 'm' : 'M'); + } else if (m->mouse_encoding == WSAP_VTCORE_MOUSE_ENC_URXVT) { sb_bytes(&sb, "\033[", 2); sb_u32(&sb, (uint32_t)(legacy_code + 32)); sb_ch(&sb, ';'); @@ -635,7 +635,7 @@ struct term_input_result term_input_encode_mouse(const struct term_mouse_event * sb_ch(&sb, ';'); sb_u32(&sb, (uint32_t)(cell.y + 1)); sb_ch(&sb, 'M'); - } else if (m->mouse_encoding == TERM_MOUSE_ENC_UTF8) { + } else if (m->mouse_encoding == WSAP_VTCORE_MOUSE_ENC_UTF8) { sb_bytes(&sb, "\033[M", 3); sb_utf8(&sb, (unsigned)legacy_code + 32); sb_utf8(&sb, (unsigned)cell.x + 33); @@ -665,11 +665,11 @@ static bool is_direction_format(uint32_t cp) cp == 0xfeff; } -struct term_input_result term_input_encode_paste(const struct term_modes *m, +struct wsap_vtcore_input_result wsap_vtcore_input_encode_paste(const struct wsap_vtcore_modes *m, const char *text, size_t len, char *buf, size_t capacity) { - struct term_input_result out = {0}; + struct wsap_vtcore_input_result out = {0}; if (!m || !buf || (!text && len)) return out; struct seqbuf sb = { .p = buf, .left = capacity }; @@ -677,7 +677,7 @@ struct term_input_result term_input_encode_paste(const struct term_modes *m, char *body = sb.p; for (size_t i = 0; i < len;) { if (sb.overflow) break; - size_t run = term_scan_printable_span(text + i, len - i, 0x7f); + size_t run = wsap_vtcore_scan_printable_span(text + i, len - i, 0x7f); if (run > 0) { sb_bytes(&sb, text + i, run); i += run; @@ -695,7 +695,7 @@ struct term_input_result term_input_encode_paste(const struct term_modes *m, continue; } uint32_t cp; - int n = term_utf8_decode_one(text + i, len - i, &cp); + int n = wsap_vtcore_utf8_decode_one(text + i, len - i, &cp); if (!n) { i++; continue; } if (cp >= 0xa0 && !is_direction_format(cp)) { sb_bytes(&sb, text + i, (size_t)n); @@ -703,7 +703,7 @@ struct term_input_result term_input_encode_paste(const struct term_modes *m, i += (size_t)n; } - out.status = TERM_INPUT_CONSUMED; + out.status = WSAP_VTCORE_INPUT_CONSUMED; if (!sb.overflow && sb.p == body) return out; if (m->bracketed_paste) sb_bytes(&sb, "\033[201~", 6); return sb_result(&sb, buf); diff --git a/src/internal.h b/src/internal.h index 676413c..81ab53f 100644 --- a/src/internal.h +++ b/src/internal.h @@ -1,7 +1,7 @@ -#ifndef TERM_INTERNAL_H -#define TERM_INTERNAL_H +#ifndef WSAP_VTCORE_INTERNAL_H +#define WSAP_VTCORE_INTERNAL_H -#include "term.h" +#include "wsap_vtcore.h" #include "cell.h" #include "csi.h" #include "gstore.h" @@ -41,7 +41,7 @@ struct keyboard_mode { /* What DECSC saves, as in xterm: the cursor, the pen, origin mode, the * pending wrap, and the character sets. */ -struct term_saved_cursor { +struct wsap_vtcore_saved_cursor { int x, y; uint32_t fg, bg, ul; char charsets[2]; @@ -89,7 +89,7 @@ struct screen { uint32_t top_seg; }; -struct term_sel_point { +struct wsap_vtcore_sel_point { uint64_t line_id; uint32_t cell_off; }; @@ -107,9 +107,9 @@ struct resize_scratch { }; -struct term { +struct wsap_vtcore { /* The writer section. A waiting thread sleeps on it. */ - term_mutex write_lock; + wsap_vtcore_mutex write_lock; _Atomic uint64_t writer_tid; uint32_t write_depth; int cols; @@ -172,8 +172,8 @@ struct term { struct resize_scratch resize; struct grow_buf ascii_ends; struct grow_buf ascii_tail; - struct term_saved_cursor normal_saved_cursor; - struct term_saved_cursor normal_saved_decsc; + struct wsap_vtcore_saved_cursor normal_saved_cursor; + struct wsap_vtcore_saved_cursor normal_saved_decsc; int normal_cols, normal_rows; bool alt_allocated; bool normal_cursor_visible; @@ -186,13 +186,13 @@ struct term { uint64_t full_gen; int prompt_y; int left_margin, right_margin; - struct term_sel_point sel_start, sel_end; - struct term_sel_point sel_anchor_first, sel_anchor_last; - enum term_select_unit select_unit; + struct wsap_vtcore_sel_point sel_start, sel_end; + struct wsap_vtcore_sel_point sel_anchor_first, sel_anchor_last; + enum wsap_vtcore_select_unit select_unit; int mouse_mode, mouse_encoding; - enum term_cursor_style cursor_style; - enum term_cursor_style default_cursor_style; + enum wsap_vtcore_cursor_style cursor_style; + enum wsap_vtcore_cursor_style default_cursor_style; int charset_active; int osc_len; int dcs_len; @@ -200,7 +200,7 @@ struct term { struct keyboard_mode keyboard[2]; /* The DECSC slot. Cold: it stays out of the hot fields above. */ - struct term_saved_cursor saved; + struct wsap_vtcore_saved_cursor saved; uint8_t *tabs; struct cell *view_row_scratch; @@ -221,7 +221,7 @@ struct term { char *cwd; char *pointer_shape; - struct term_callbacks cb; + struct wsap_vtcore_callbacks cb; struct palette palette; struct gstore *gstore; /* Unique for the life of the process. A snapshot compares it, not the @@ -229,10 +229,10 @@ struct term { uint64_t serial; }; -static inline void reset_sgr(struct term *t) +static inline void reset_sgr(struct wsap_vtcore *t) { - t->cur_fg = TERM_COLOR_FG; - t->cur_bg = TERM_COLOR_BG; + t->cur_fg = WSAP_VTCORE_COLOR_FG; + t->cur_bg = WSAP_VTCORE_COLOR_BG; t->bold = false; t->faint = false; t->italic = false; @@ -244,16 +244,16 @@ static inline void reset_sgr(struct term *t) } /* The DECSC slot before any save: home, the default pen, and ASCII. */ -static inline struct term_saved_cursor term_saved_cursor_initial(void) +static inline struct wsap_vtcore_saved_cursor wsap_vtcore_saved_cursor_initial(void) { - return (struct term_saved_cursor){ - .fg = TERM_COLOR_FG, .bg = TERM_COLOR_BG, .charsets = { 'B', 'B' }, + return (struct wsap_vtcore_saved_cursor){ + .fg = WSAP_VTCORE_COLOR_FG, .bg = WSAP_VTCORE_COLOR_BG, .charsets = { 'B', 'B' }, }; } -static inline struct term_saved_cursor term_cursor_save(const struct term *t) +static inline struct wsap_vtcore_saved_cursor wsap_vtcore_cursor_save(const struct wsap_vtcore *t) { - return (struct term_saved_cursor){ + return (struct wsap_vtcore_saved_cursor){ .x = t->cursor_x, .y = t->cursor_y, .fg = t->cur_fg, .bg = t->cur_bg, .ul = t->cur_ul, .charsets = { t->charsets[0], t->charsets[1] }, @@ -267,7 +267,7 @@ static inline struct term_saved_cursor term_cursor_save(const struct term *t) /* Take the pen, origin mode, and character sets from s. The caller places * the cursor. */ -static inline void term_cursor_apply(struct term *t, const struct term_saved_cursor *s) +static inline void wsap_vtcore_cursor_apply(struct wsap_vtcore *t, const struct wsap_vtcore_saved_cursor *s) { t->cur_fg = s->fg; t->cur_bg = s->bg; @@ -286,12 +286,12 @@ static inline void term_cursor_apply(struct term *t, const struct term_saved_cur t->graphics = t->charsets[t->charset_active] == '0'; } -static inline void send_response(struct term *t, const char *str) +static inline void send_response(struct wsap_vtcore *t, const char *str) { if (t && t->cb.reply) t->cb.reply(t->cb.ud, str, strlen(str)); } -static inline int term_hex_nib(char c) +static inline int wsap_vtcore_hex_nib(char c) { if (c >= '0' && c <= '9') return c - '0'; if (c >= 'a' && c <= 'f') return c - 'a' + 10; @@ -299,7 +299,7 @@ static inline int term_hex_nib(char c) return -1; } -static inline bool term_lnm(const struct term *t) +static inline bool wsap_vtcore_lnm(const struct wsap_vtcore *t) { return t->lnm || t->transport_newline; } @@ -314,53 +314,53 @@ static inline bool mode_is_mouse_enc(int m) return m == 1005 || m == 1006 || m == 1015 || m == 1016; } -static const uint16_t term_ul_flags[] = { +static const uint16_t wsap_vtcore_ul_flags[] = { 0, CELL_UNDERLINE, CELL_DOUBLE_UNDERLINE, CELL_CURLY_UNDERLINE, CELL_DOTTED_UNDERLINE, CELL_DASHED_UNDERLINE, }; -static inline uint16_t term_current_flags(const struct term *t) +static inline uint16_t wsap_vtcore_current_flags(const struct wsap_vtcore *t) { uint16_t f = 0; if (t->bold) f |= CELL_BOLD; if (t->faint) f |= CELL_FAINT; if (t->italic) f |= CELL_ITALIC; - if (t->underline < sizeof(term_ul_flags) / sizeof(term_ul_flags[0])) - f |= term_ul_flags[t->underline]; + if (t->underline < sizeof(wsap_vtcore_ul_flags) / sizeof(wsap_vtcore_ul_flags[0])) + f |= wsap_vtcore_ul_flags[t->underline]; if (t->strike) f |= CELL_STRIKE; if (t->overline) f |= CELL_OVERLINE; if (t->cur_link) f |= CELL_LINK; return f; } -static inline uint32_t term_flags_pad(const struct term *t) +static inline uint32_t wsap_vtcore_flags_pad(const struct wsap_vtcore *t) { - return term_current_flags(t) | ((uint32_t)t->cur_link << 16); + return wsap_vtcore_current_flags(t) | ((uint32_t)t->cur_link << 16); } -static inline struct text_pen term_text_pen(const struct term *t) +static inline struct text_pen wsap_vtcore_text_pen(const struct wsap_vtcore *t) { return (struct text_pen){ - .fg = TERM_EXPECT(t->inverse, 0) ? t->cur_bg : t->cur_fg, - .bg = TERM_EXPECT(t->inverse, 0) ? t->cur_fg : t->cur_bg, - .sl = term_flags_pad(t), + .fg = WSAP_VTCORE_EXPECT(t->inverse, 0) ? t->cur_bg : t->cur_fg, + .bg = WSAP_VTCORE_EXPECT(t->inverse, 0) ? t->cur_fg : t->cur_bg, + .sl = wsap_vtcore_flags_pad(t), }; } -static inline void term_tabs_clear(struct term *t) +static inline void wsap_vtcore_tabs_clear(struct wsap_vtcore *t) { memset(t->tabs, 0, (size_t)t->tabs_cap); t->custom_tabs = true; } -static inline void term_tabs_default(struct term *t) +static inline void wsap_vtcore_tabs_default(struct wsap_vtcore *t) { for (int c = 8; c < t->tabs_cap; c += 8) t->tabs[c] = 1; t->custom_tabs = false; } -static inline bool term_str_was_truncated(struct term *t) +static inline bool wsap_vtcore_str_was_truncated(struct wsap_vtcore *t) { bool truncated = t->str_truncated; t->str_truncated = false; @@ -368,27 +368,27 @@ static inline bool term_str_was_truncated(struct term *t) } /* Every thread has its own anchor, so its address names the thread. */ -extern _Thread_local char term_thread_anchor; +extern _Thread_local char wsap_vtcore_thread_anchor; -static inline void term_write_begin(struct term *t) +static inline void wsap_vtcore_write_begin(struct wsap_vtcore *t) { if (!t) return; - uint64_t self = (uint64_t)(uintptr_t)&term_thread_anchor; + uint64_t self = (uint64_t)(uintptr_t)&wsap_vtcore_thread_anchor; if (atomic_load_explicit(&t->writer_tid, memory_order_relaxed) == self) { t->write_depth++; return; } - term_mutex_lock(&t->write_lock); + wsap_vtcore_mutex_lock(&t->write_lock); atomic_store_explicit(&t->writer_tid, self, memory_order_relaxed); t->write_depth = 1; } -static inline void term_write_end(struct term *t) +static inline void wsap_vtcore_write_end(struct wsap_vtcore *t) { if (!t) return; if (--t->write_depth == 0) { atomic_store_explicit(&t->writer_tid, 0, memory_order_relaxed); - term_mutex_unlock(&t->write_lock); + wsap_vtcore_mutex_unlock(&t->write_lock); } } @@ -3,19 +3,19 @@ * the first terminal exists, so every call in a process uses the same * kernels. */ -#include "term.h" +#include "wsap_vtcore.h" #include "simd.h" #include <stdatomic.h> #include <stdlib.h> #include <string.h> -int term_isa_level; +int wsap_vtcore_isa_level; static atomic_int isa_state; static const char *const level_names[] = { "base", "avx2", "avx512" }; -#if defined(TERM_ISA_RUNTIME) +#if defined(WSAP_VTCORE_ISA_RUNTIME) /* The AVX-512 kernels also need VBMI and VBMI2. Every CPU with VBMI except * Cannon Lake has VBMI2. */ static int cpu_level(void) @@ -23,56 +23,56 @@ static int cpu_level(void) __builtin_cpu_init(); if (__builtin_cpu_supports("x86-64-v4") && __builtin_cpu_supports("avx512vbmi") && __builtin_cpu_supports("avx512vbmi2")) - return TERM_ISA_AVX512; + return WSAP_VTCORE_ISA_AVX512; if (__builtin_cpu_supports("x86-64-v3")) - return TERM_ISA_AVX2; - return TERM_ISA_BASE; + return WSAP_VTCORE_ISA_AVX2; + return WSAP_VTCORE_ISA_BASE; } #else static int cpu_level(void) { - return TERM_ISA_FLOOR; + return WSAP_VTCORE_ISA_FLOOR; } #endif static int pick_level(void) { int level = cpu_level(); - /* TERM_HEADLESS_ISA can only lower the level, never below the floor the + /* WSAP_VTCORE_ISA can only lower the level, never below the floor the * compiler flags fix. */ - const char *want = getenv("TERM_HEADLESS_ISA"); - for (int i = TERM_ISA_FLOOR; want && i < level; i++) + const char *want = getenv("WSAP_VTCORE_ISA"); + for (int i = WSAP_VTCORE_ISA_FLOOR; want && i < level; i++) if (!strcmp(want, level_names[i])) level = i; return level; } /* The first caller picks the level. A second caller waits until it is set. */ -void term_isa_init(void) +void wsap_vtcore_isa_init(void) { if (atomic_load_explicit(&isa_state, memory_order_acquire) == 2) return; int expected = 0; if (atomic_compare_exchange_strong(&isa_state, &expected, 1)) { - term_isa_level = pick_level(); + wsap_vtcore_isa_level = pick_level(); atomic_store_explicit(&isa_state, 2, memory_order_release); return; } while (atomic_load_explicit(&isa_state, memory_order_acquire) != 2) - term_cpu_relax(); + wsap_vtcore_cpu_relax(); } -const char *term_isa(void) +const char *wsap_vtcore_isa(void) { - term_isa_init(); + wsap_vtcore_isa_init(); #if defined(__aarch64__) return "neon"; #else - int level = TERM_ISA_FLOOR; - if (term_use_avx2()) - level = TERM_ISA_AVX2; - if (term_use_avx512()) - level = TERM_ISA_AVX512; + int level = WSAP_VTCORE_ISA_FLOOR; + if (wsap_vtcore_use_avx2()) + level = WSAP_VTCORE_ISA_AVX2; + if (wsap_vtcore_use_avx512()) + level = WSAP_VTCORE_ISA_AVX512; return level_names[level]; #endif } diff --git a/src/kernels.h b/src/kernels.h index 5cf0d93..9112c2e 100644 --- a/src/kernels.h +++ b/src/kernels.h @@ -10,8 +10,8 @@ #include <stdint.h> #include <string.h> -#if defined(TERM_KERNEL_AVX512) -TERM_TARGET_AVX512 +#if defined(WSAP_VTCORE_KERNEL_AVX512) +WSAP_VTCORE_TARGET_AVX512 static inline size_t scan_printable_span_avx512(const char *buf, size_t len, unsigned char hi) { size_t i = 0; @@ -21,21 +21,21 @@ static inline size_t scan_printable_span_avx512(const char *buf, size_t len, uns __m512i v = _mm512_loadu_si512((const void *)(buf + i)); __mmask64 mask = _mm512_cmpge_epu8_mask(_mm512_sub_epi8(v, v20_512), vlim_512); if (mask != 0) - return i + term_ctz64(mask); + return i + wsap_vtcore_ctz64(mask); } if (i < len) { __mmask64 load_mask = ((uint64_t)1 << (len - i)) - 1; __m512i v = _mm512_maskz_loadu_epi8(load_mask, buf + i); __mmask64 mask = _mm512_mask_cmpge_epu8_mask(load_mask, _mm512_sub_epi8(v, v20_512), vlim_512); if (mask != 0) - return i + term_ctz64(mask); + return i + wsap_vtcore_ctz64(mask); } return len; } #endif -#if defined(TERM_KERNEL_AVX2) -TERM_TARGET_AVX2 +#if defined(WSAP_VTCORE_KERNEL_AVX2) +WSAP_VTCORE_TARGET_AVX2 static inline size_t scan_printable_span_avx2(const char *buf, size_t len, unsigned char hi) { size_t i = 0; @@ -48,10 +48,10 @@ static inline size_t scan_printable_span_avx2(const char *buf, size_t len, unsig __m256i sub1 = _mm256_sub_epi8(v1, v_offset); int m0 = _mm256_movemask_epi8(_mm256_cmpgt_epi8(sub0, v_limit)); int m1 = _mm256_movemask_epi8(_mm256_cmpgt_epi8(sub1, v_limit)); - if (TERM_EXPECT((m0 | m1) != 0, 0)) { + if (WSAP_VTCORE_EXPECT((m0 | m1) != 0, 0)) { if (m0 != 0) - return i + term_ctz32(m0); - return i + 32 + term_ctz32(m1); + return i + wsap_vtcore_ctz32(m0); + return i + 32 + wsap_vtcore_ctz32(m1); } } if (i + 32 <= len) { @@ -59,7 +59,7 @@ static inline size_t scan_printable_span_avx2(const char *buf, size_t len, unsig __m256i sub = _mm256_sub_epi8(v, v_offset); int mask = _mm256_movemask_epi8(_mm256_cmpgt_epi8(sub, v_limit)); if (mask != 0) - return i + term_ctz32(mask); + return i + wsap_vtcore_ctz32(mask); i += 32; } if (i + 16 <= len) { @@ -67,7 +67,7 @@ static inline size_t scan_printable_span_avx2(const char *buf, size_t len, unsig __m128i sub = _mm_sub_epi8(v, _mm_set1_epi8((char)(0x20 + 0x80))); int mask = _mm_movemask_epi8(_mm_cmpgt_epi8(sub, _mm_set1_epi8((char)(hi - 0xa1)))) & 0xFFFF; if (mask != 0) - return i + term_ctz32(mask); + return i + wsap_vtcore_ctz32(mask); i += 16; } for (; i < len; i++) { @@ -83,12 +83,12 @@ static inline size_t scan_printable_span(const char *buf, size_t len, unsigned char hi) { /* A short span costs less inline than as a call. */ -#if defined(TERM_KERNEL_AVX512) - if (len >= 64 && term_use_avx512()) +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (len >= 64 && wsap_vtcore_use_avx512()) return scan_printable_span_avx512(buf, len, hi); #endif -#if defined(TERM_KERNEL_AVX2) - if (len >= 32 && term_use_avx2()) +#if defined(WSAP_VTCORE_KERNEL_AVX2) + if (len >= 32 && wsap_vtcore_use_avx2()) return scan_printable_span_avx2(buf, len, hi); #endif size_t i = 0; @@ -108,26 +108,26 @@ static inline size_t scan_printable_span(const char *buf, size_t len, uint8x16_t mor = vorrq_u8(vorrq_u8(m0, m1), vorrq_u8(m2, m3)); uint64x2_t mor64 = vreinterpretq_u64_u8(mor); - if (TERM_EXPECT((vgetq_lane_u64(mor64, 0) | vgetq_lane_u64(mor64, 1)) != 0, 0)) { + if (WSAP_VTCORE_EXPECT((vgetq_lane_u64(mor64, 0) | vgetq_lane_u64(mor64, 1)) != 0, 0)) { uint64x2_t m0_64 = vreinterpretq_u64_u8(m0); uint64_t lo0 = vgetq_lane_u64(m0_64, 0), hi0 = vgetq_lane_u64(m0_64, 1); - if (lo0) return i + (term_ctz64(lo0) >> 3); - if (hi0) return i + 8 + (term_ctz64(hi0) >> 3); + if (lo0) return i + (wsap_vtcore_ctz64(lo0) >> 3); + if (hi0) return i + 8 + (wsap_vtcore_ctz64(hi0) >> 3); uint64x2_t m1_64 = vreinterpretq_u64_u8(m1); uint64_t lo1 = vgetq_lane_u64(m1_64, 0), hi1 = vgetq_lane_u64(m1_64, 1); - if (lo1) return i + 16 + (term_ctz64(lo1) >> 3); - if (hi1) return i + 24 + (term_ctz64(hi1) >> 3); + if (lo1) return i + 16 + (wsap_vtcore_ctz64(lo1) >> 3); + if (hi1) return i + 24 + (wsap_vtcore_ctz64(hi1) >> 3); uint64x2_t m2_64 = vreinterpretq_u64_u8(m2); uint64_t lo2 = vgetq_lane_u64(m2_64, 0), hi2 = vgetq_lane_u64(m2_64, 1); - if (lo2) return i + 32 + (term_ctz64(lo2) >> 3); - if (hi2) return i + 40 + (term_ctz64(hi2) >> 3); + if (lo2) return i + 32 + (wsap_vtcore_ctz64(lo2) >> 3); + if (hi2) return i + 40 + (wsap_vtcore_ctz64(hi2) >> 3); uint64x2_t m3_64 = vreinterpretq_u64_u8(m3); uint64_t lo3 = vgetq_lane_u64(m3_64, 0), hi3 = vgetq_lane_u64(m3_64, 1); - if (lo3) return i + 48 + (term_ctz64(lo3) >> 3); - if (hi3) return i + 56 + (term_ctz64(hi3) >> 3); + if (lo3) return i + 48 + (wsap_vtcore_ctz64(lo3) >> 3); + if (hi3) return i + 56 + (wsap_vtcore_ctz64(hi3) >> 3); } } for (; i + 16 <= len; i += 16) { @@ -136,14 +136,14 @@ static inline size_t scan_printable_span(const char *buf, size_t len, uint64x2_t m64 = vreinterpretq_u64_u8(mask); uint64_t lo = vgetq_lane_u64(m64, 0); uint64_t hi64 = vgetq_lane_u64(m64, 1); - if (lo) return i + (term_ctz64(lo) >> 3); - if (hi64) return i + 8 + (term_ctz64(hi64) >> 3); + if (lo) return i + (wsap_vtcore_ctz64(lo) >> 3); + if (hi64) return i + 8 + (wsap_vtcore_ctz64(hi64) >> 3); } if (i + 8 <= len) { uint8x8_t v8 = vld1_u8((const uint8_t *)buf + i); uint8x8_t mask8 = vcge_u8(vsub_u8(v8, vget_low_u8(v20)), vget_low_u8(vlim)); uint64_t m64 = vget_lane_u64(vreinterpret_u64_u8(mask8), 0); - if (m64) return i + (term_ctz64(m64) >> 3); + if (m64) return i + (wsap_vtcore_ctz64(m64) >> 3); i += 8; } #elif defined(__x86_64__) @@ -154,19 +154,19 @@ static inline size_t scan_printable_span(const char *buf, size_t len, __m128i m1 = _mm_cmpgt_epi8(_mm_sub_epi8(_mm_loadu_si128((const __m128i *)(buf + i + 16)), v_offset), v_limit); __m128i m2 = _mm_cmpgt_epi8(_mm_sub_epi8(_mm_loadu_si128((const __m128i *)(buf + i + 32)), v_offset), v_limit); __m128i m3 = _mm_cmpgt_epi8(_mm_sub_epi8(_mm_loadu_si128((const __m128i *)(buf + i + 48)), v_offset), v_limit); - if (TERM_EXPECT(_mm_movemask_epi8(_mm_or_si128(_mm_or_si128(m0, m1), _mm_or_si128(m2, m3))) != 0, 0)) { + if (WSAP_VTCORE_EXPECT(_mm_movemask_epi8(_mm_or_si128(_mm_or_si128(m0, m1), _mm_or_si128(m2, m3))) != 0, 0)) { uint64_t mask = (uint64_t)(unsigned)_mm_movemask_epi8(m0) | (uint64_t)(unsigned)_mm_movemask_epi8(m1) << 16 | (uint64_t)(unsigned)_mm_movemask_epi8(m2) << 32 | (uint64_t)(unsigned)_mm_movemask_epi8(m3) << 48; - return i + (size_t)term_ctz64(mask); + return i + (size_t)wsap_vtcore_ctz64(mask); } } for (; i + 16 <= len; i += 16) { int mask = _mm_movemask_epi8(_mm_cmpgt_epi8( _mm_sub_epi8(_mm_loadu_si128((const __m128i *)(buf + i)), v_offset), v_limit)); if (mask != 0) - return i + (size_t)term_ctz32((unsigned)mask); + return i + (size_t)wsap_vtcore_ctz32((unsigned)mask); } #endif for (; i < len; i++) { @@ -179,10 +179,10 @@ static inline size_t scan_printable_span(const char *buf, size_t len, /* Copy n bytes with loads that stay inside [src, src + n). Short text runs * are common; a libc call costs more than the copy. */ -static inline TERM_ALWAYS_INLINE void bytes_copy_small(uint8_t *restrict dst, +static inline WSAP_VTCORE_ALWAYS_INLINE void bytes_copy_small(uint8_t *restrict dst, const char *restrict src, int n) { - if (TERM_EXPECT((unsigned)(n - 16) <= 16u, 1)) { + if (WSAP_VTCORE_EXPECT((unsigned)(n - 16) <= 16u, 1)) { /* 16 to 32 bytes: two overlapping 16-byte copies. Both loads stay * inside [src, src + n). This is the usual history line length, and * two copies cost less here than the loop below. */ @@ -217,8 +217,8 @@ static inline size_t scan_crlf_tail(const char *buf, size_t i, size_t len) return i; } -#if defined(TERM_KERNEL_AVX512) -TERM_TARGET_AVX512 +#if defined(WSAP_VTCORE_KERNEL_AVX512) +WSAP_VTCORE_TARGET_AVX512 static inline size_t scan_crlf_pairs_avx512(const char *buf, size_t len) { size_t i = 0; @@ -226,14 +226,14 @@ static inline size_t scan_crlf_pairs_avx512(const char *buf, size_t len) for (; i + 64 <= len; i += 64) { uint64_t eq = _mm512_cmpeq_epi8_mask(_mm512_loadu_si512((const void *)(buf + i)), pair); if (eq != ~0ull) - return i + ((size_t)term_ctz64(~eq) & ~(size_t)1); + return i + ((size_t)wsap_vtcore_ctz64(~eq) & ~(size_t)1); } return scan_crlf_tail(buf, i, len); } #endif -#if defined(TERM_KERNEL_AVX2) -TERM_TARGET_AVX2 +#if defined(WSAP_VTCORE_KERNEL_AVX2) +WSAP_VTCORE_TARGET_AVX2 static inline size_t scan_crlf_pairs_avx2(const char *buf, size_t len) { size_t i = 0; @@ -242,7 +242,7 @@ static inline size_t scan_crlf_pairs_avx2(const char *buf, size_t len) uint32_t eq = (uint32_t)_mm256_movemask_epi8( _mm256_cmpeq_epi8(_mm256_loadu_si256((const __m256i *)(const void *)(buf + i)), pair)); if (eq != ~0u) - return i + ((size_t)term_ctz32(~eq) & ~(size_t)1); + return i + ((size_t)wsap_vtcore_ctz32(~eq) & ~(size_t)1); } return scan_crlf_tail(buf, i, len); } @@ -251,12 +251,12 @@ static inline size_t scan_crlf_pairs_avx2(const char *buf, size_t len) /* The length of the prefix of buf made of "\r\n" pairs; always even. */ static inline size_t scan_crlf_pairs(const char *buf, size_t len) { -#if defined(TERM_KERNEL_AVX512) - if (term_use_avx512()) +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (wsap_vtcore_use_avx512()) return scan_crlf_pairs_avx512(buf, len); #endif -#if defined(TERM_KERNEL_AVX2) - if (term_use_avx2()) +#if defined(WSAP_VTCORE_KERNEL_AVX2) + if (wsap_vtcore_use_avx2()) return scan_crlf_pairs_avx2(buf, len); #endif size_t i = 0; @@ -264,16 +264,16 @@ static inline size_t scan_crlf_pairs(const char *buf, size_t len) const uint8x16_t pair = vreinterpretq_u8_u16(vdupq_n_u16(0x0A0D)); for (; i + 16 <= len; i += 16) { uint8x16_t eq = vceqq_u8(vld1q_u8((const uint8_t *)buf + i), pair); - uint16_t bits = term_lane_bits(eq); + uint16_t bits = wsap_vtcore_lane_bits(eq); if (bits != 0xFFFF) - return i + ((size_t)term_ctz32((unsigned)~bits & 0xFFFFu) & ~(size_t)1); + return i + ((size_t)wsap_vtcore_ctz32((unsigned)~bits & 0xFFFFu) & ~(size_t)1); } #endif return scan_crlf_tail(buf, i, len); } -#if defined(TERM_KERNEL_AVX512) -TERM_TARGET_AVX512 +#if defined(WSAP_VTCORE_KERNEL_AVX512) +WSAP_VTCORE_TARGET_AVX512 static inline size_t scan_byte_run_avx512(const char *buf, size_t len, char byte) { size_t i = 0; @@ -281,7 +281,7 @@ static inline size_t scan_byte_run_avx512(const char *buf, size_t len, char byte for (; i + 64 <= len; i += 64) { uint64_t eq = _mm512_cmpeq_epi8_mask(_mm512_loadu_si512((const void *)(buf + i)), want); if (eq != ~0ull) - return i + (size_t)term_ctz64(~eq); + return i + (size_t)wsap_vtcore_ctz64(~eq); } while (i < len && buf[i] == byte) i++; @@ -289,8 +289,8 @@ static inline size_t scan_byte_run_avx512(const char *buf, size_t len, char byte } #endif -#if defined(TERM_KERNEL_AVX2) -TERM_TARGET_AVX2 +#if defined(WSAP_VTCORE_KERNEL_AVX2) +WSAP_VTCORE_TARGET_AVX2 static inline size_t scan_byte_run_avx2(const char *buf, size_t len, char byte) { size_t i = 0; @@ -299,7 +299,7 @@ static inline size_t scan_byte_run_avx2(const char *buf, size_t len, char byte) uint32_t eq = (uint32_t)_mm256_movemask_epi8( _mm256_cmpeq_epi8(_mm256_loadu_si256((const __m256i *)(const void *)(buf + i)), want)); if (eq != ~0u) - return i + (size_t)term_ctz32(~eq); + return i + (size_t)wsap_vtcore_ctz32(~eq); } while (i < len && buf[i] == byte) i++; @@ -310,21 +310,21 @@ static inline size_t scan_byte_run_avx2(const char *buf, size_t len, char byte) /* The length of the prefix of buf made of byte. */ static inline size_t scan_byte_run(const char *buf, size_t len, char byte) { -#if defined(TERM_KERNEL_AVX512) - if (term_use_avx512()) +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (wsap_vtcore_use_avx512()) return scan_byte_run_avx512(buf, len, byte); #endif -#if defined(TERM_KERNEL_AVX2) - if (term_use_avx2()) +#if defined(WSAP_VTCORE_KERNEL_AVX2) + if (wsap_vtcore_use_avx2()) return scan_byte_run_avx2(buf, len, byte); #endif size_t i = 0; #if defined(__aarch64__) const uint8x16_t want = vdupq_n_u8((uint8_t)byte); for (; i + 16 <= len; i += 16) { - uint16_t bits = term_lane_bits(vceqq_u8(vld1q_u8((const uint8_t *)buf + i), want)); + uint16_t bits = wsap_vtcore_lane_bits(vceqq_u8(vld1q_u8((const uint8_t *)buf + i), want)); if (bits != 0xFFFF) - return i + (size_t)term_ctz32((unsigned)~bits & 0xFFFFu); + return i + (size_t)wsap_vtcore_ctz32((unsigned)~bits & 0xFFFFu); } #elif defined(__x86_64__) const __m128i want = _mm_set1_epi8(byte); @@ -332,7 +332,7 @@ static inline size_t scan_byte_run(const char *buf, size_t len, char byte) unsigned eq = (unsigned)_mm_movemask_epi8( _mm_cmpeq_epi8(_mm_loadu_si128((const __m128i *)(const void *)(buf + i)), want)); if (eq != 0xFFFFu) - return i + (size_t)term_ctz32(~eq & 0xFFFFu); + return i + (size_t)wsap_vtcore_ctz32(~eq & 0xFFFFu); } #endif while (i < len && buf[i] == byte) @@ -355,16 +355,16 @@ static inline int scan_ascii_lf_tail(const char *buf, int i, int len, uint16_t * return count; } -#if defined(TERM_KERNEL_AVX512) -TERM_TARGET_AVX512 +#if defined(WSAP_VTCORE_KERNEL_AVX512) +WSAP_VTCORE_TARGET_AVX512 static inline int store_lf_offsets_avx512(uint16_t *ends, uint64_t nl, __m512i lanes, __m128i block) { - unsigned n = (unsigned)term_popcount64(nl); + unsigned n = (unsigned)wsap_vtcore_popcount64(nl); __m512i packed = _mm512_maskz_compress_epi8(nl, lanes); __m128i offsets = _mm_add_epi16(_mm_cvtepu8_epi16(_mm512_castsi512_si128(packed)), block); _mm_storeu_si128((__m128i *)ends, offsets); - if (TERM_EXPECT(n > 8, 0)) { + if (WSAP_VTCORE_EXPECT(n > 8, 0)) { __m512i base = _mm512_broadcast_i32x4(block); __m512i wide = _mm512_add_epi16(_mm512_cvtepu8_epi16(_mm512_castsi512_si256(packed)), base); _mm512_storeu_si512(ends, wide); @@ -376,7 +376,7 @@ static inline int store_lf_offsets_avx512(uint16_t *ends, uint64_t nl, return (int)n; } -TERM_TARGET_AVX512 TERM_MAYBE_UNUSED +WSAP_VTCORE_TARGET_AVX512 WSAP_VTCORE_MAYBE_UNUSED static int scan_ascii_lf_avx512(const char *buf, int len, uint16_t *ends) { int i = 0, count = 0; @@ -416,8 +416,8 @@ static int scan_ascii_lf_avx512(const char *buf, int len, uint16_t *ends) } #endif -#if defined(TERM_KERNEL_AVX2) -TERM_TARGET_AVX2 TERM_MAYBE_UNUSED +#if defined(WSAP_VTCORE_KERNEL_AVX2) +WSAP_VTCORE_TARGET_AVX2 WSAP_VTCORE_MAYBE_UNUSED static int scan_ascii_lf_avx2(const char *buf, int len, uint16_t *ends) { int i = 0, count = 0; @@ -430,7 +430,7 @@ static int scan_ascii_lf_avx2(const char *buf, int len, uint16_t *ends) _mm256_cmpgt_epi8(d, _mm256_set1_epi8((char)0xde))) & ~nl; if (bad) break; while (nl) { - ends[++count] = (uint16_t)(i + term_ctz32(nl) + 1); + ends[++count] = (uint16_t)(i + wsap_vtcore_ctz32(nl) + 1); nl &= nl - 1; } } @@ -440,14 +440,14 @@ static int scan_ascii_lf_avx2(const char *buf, int len, uint16_t *ends) /* Find complete ASCII lines. Stop at the first byte other than text or LF. * The caller supplies len + 65 entries. len must fit in uint16_t. */ -static TERM_NOINLINE TERM_MAYBE_UNUSED int scan_ascii_lf(const char *buf, int len, uint16_t *ends) +static WSAP_VTCORE_NOINLINE WSAP_VTCORE_MAYBE_UNUSED int scan_ascii_lf(const char *buf, int len, uint16_t *ends) { -#if defined(TERM_KERNEL_AVX512) - if (term_use_avx512()) +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (wsap_vtcore_use_avx512()) return scan_ascii_lf_avx512(buf, len, ends); #endif -#if defined(TERM_KERNEL_AVX2) - if (term_use_avx2()) +#if defined(WSAP_VTCORE_KERNEL_AVX2) + if (wsap_vtcore_use_avx2()) return scan_ascii_lf_avx2(buf, len, ends); #endif int i = 0, count = 0; @@ -457,14 +457,14 @@ static TERM_NOINLINE TERM_MAYBE_UNUSED int scan_ascii_lf(const char *buf, int le uint32_t nl = 0, bad = 0; for (int q = 0; q < 2; q++) { uint8x16_t v = vld1q_u8((const uint8_t *)buf + i + q * 16); - nl |= (uint32_t)term_lane_bits(vceqq_u8(v, vdupq_n_u8('\n'))) << (q * 16); - bad |= (uint32_t)term_lane_bits(vcgeq_u8(vsubq_u8(v, vdupq_n_u8(0x20)), + nl |= (uint32_t)wsap_vtcore_lane_bits(vceqq_u8(v, vdupq_n_u8('\n'))) << (q * 16); + bad |= (uint32_t)wsap_vtcore_lane_bits(vcgeq_u8(vsubq_u8(v, vdupq_n_u8(0x20)), vdupq_n_u8(0x5f))) << (q * 16); } bad &= ~nl; if (bad) break; while (nl) { - ends[++count] = (uint16_t)(i + term_ctz32(nl) + 1); + ends[++count] = (uint16_t)(i + wsap_vtcore_ctz32(nl) + 1); nl &= nl - 1; } } @@ -472,8 +472,8 @@ static TERM_NOINLINE TERM_MAYBE_UNUSED int scan_ascii_lf(const char *buf, int le return scan_ascii_lf_tail(buf, i, len, ends, count); } -#if defined(TERM_KERNEL_AVX512) -TERM_TARGET_AVX512 +#if defined(WSAP_VTCORE_KERNEL_AVX512) +WSAP_VTCORE_TARGET_AVX512 static inline void fill_cells_avx512(struct cell * restrict row, int cols, uint32_t fg, uint32_t bg) { __m128i cell = _mm_setr_epi32(' ', (int)fg, (int)bg, 0); @@ -496,8 +496,8 @@ static inline void fill_cells_avx512(struct cell * restrict row, int cols, uint3 } #endif -#if defined(TERM_KERNEL_AVX2) -TERM_TARGET_AVX2 +#if defined(WSAP_VTCORE_KERNEL_AVX2) +WSAP_VTCORE_TARGET_AVX2 static inline void fill_cells_avx2(struct cell * restrict row, int cols, uint32_t fg, uint32_t bg) { struct cell fill = { .c = ' ', .fg = fg, .bg = bg, .flags = 0, .pad = 0 }; @@ -519,21 +519,21 @@ static inline void fill_cells_avx2(struct cell * restrict row, int cols, uint32_ static inline void fill_cells(struct cell * restrict row, int cols, uint32_t fg, uint32_t bg) { struct cell fill = { .c = ' ', .fg = fg, .bg = bg, .flags = 0, .pad = 0 }; -#if defined(TERM_KERNEL_AVX512) - if (term_use_avx512()) { - if (TERM_EXPECT(cols > 0, 1)) +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (wsap_vtcore_use_avx512()) { + if (WSAP_VTCORE_EXPECT(cols > 0, 1)) fill_cells_avx512(row, cols, fg, bg); return; } #endif -#if defined(TERM_KERNEL_AVX2) - if (term_use_avx2() && TERM_EXPECT(cols >= 8, 1)) { +#if defined(WSAP_VTCORE_KERNEL_AVX2) + if (wsap_vtcore_use_avx2() && WSAP_VTCORE_EXPECT(cols >= 8, 1)) { fill_cells_avx2(row, cols, fg, bg); return; } #endif #if defined(__aarch64__) - if (TERM_EXPECT(cols > 0, 1)) { + if (WSAP_VTCORE_EXPECT(cols > 0, 1)) { uint32x4_t blank = { ' ', fg, bg, 0 }; uint32x4x4_t b4 = {{ blank, blank, blank, blank }}; int c = 0; @@ -571,11 +571,11 @@ static inline void fill_cells(struct cell * restrict row, int cols, uint32_t fg, static inline void clear_cells_default(struct cell *row, int cols) { - fill_cells(row, cols, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(row, cols, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); } -#if defined(TERM_KERNEL_AVX512) -TERM_TARGET_AVX512 +#if defined(WSAP_VTCORE_KERNEL_AVX512) +WSAP_VTCORE_TARGET_AVX512 static inline void put_ascii_chunk_avx512(struct cell * restrict dst, const char * restrict src, int n, uint32_t fg, uint32_t bg, uint32_t flags) { @@ -622,8 +622,8 @@ static inline void put_ascii_chunk_avx512(struct cell * restrict dst, const char } #endif -#if defined(TERM_KERNEL_AVX2) -TERM_TARGET_AVX2 +#if defined(WSAP_VTCORE_KERNEL_AVX2) +WSAP_VTCORE_TARGET_AVX2 static inline void put_ascii_chunk_avx2(struct cell * restrict dst, const char * restrict src, int n, uint32_t fg, uint32_t bg, uint32_t flags) { @@ -683,19 +683,19 @@ static inline void put_ascii_quad_neon(struct cell *dst, const char *src, } #endif -TERM_ALWAYS_INLINE +WSAP_VTCORE_ALWAYS_INLINE static inline void put_ascii_chunk(struct cell * restrict dst, const char * restrict src, int n, uint32_t fg, uint32_t bg, uint32_t flags) { /* A short chunk costs less inline than as a call. */ -#if defined(TERM_KERNEL_AVX512) - if (n >= 16 && term_use_avx512()) { +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (n >= 16 && wsap_vtcore_use_avx512()) { put_ascii_chunk_avx512(dst, src, n, fg, bg, flags); return; } #endif -#if defined(TERM_KERNEL_AVX2) - if (n >= 16 && term_use_avx2()) { +#if defined(WSAP_VTCORE_KERNEL_AVX2) + if (n >= 16 && wsap_vtcore_use_avx2()) { put_ascii_chunk_avx2(dst, src, n, fg, bg, flags); return; } diff --git a/src/meson.build b/src/meson.build index 7684275..ce91573 100644 --- a/src/meson.build +++ b/src/meson.build @@ -2,11 +2,11 @@ subdir('osc') # The SONAME carries the major version. An ABI break bumps it, so an old # binary keeps the old library. -term_soversion = meson.project_version().split('.')[0] +wsap_vtcore_soversion = meson.project_version().split('.')[0] # The x86-64 SIMD kernels pick their level at run time (see simd.h), so the # library needs no ISA flags. -march in c_args sets the lowest level. -term_lib = both_libraries('term', +wsap_vtcore_lib = both_libraries('wsap_vtcore', 'core.c', 'escape.c', 'fastcsi.c', @@ -23,12 +23,12 @@ term_lib = both_libraries('term', 'term.c', 'text.c', 'text_run.c', - term_osc_src, - include_directories: term_private_inc, + wsap_vtcore_osc_src, + include_directories: wsap_vtcore_private_inc, dependencies: [m_dep, thread_dep], gnu_symbol_visibility: 'hidden', version: meson.project_version(), - soversion: term_soversion, + soversion: wsap_vtcore_soversion, install: true ) diff --git a/src/osc/clipboard.c b/src/osc/clipboard.c index 4f550ba..b330ab8 100644 --- a/src/osc/clipboard.c +++ b/src/osc/clipboard.c @@ -65,7 +65,7 @@ static bool b64_decode(const char *s, size_t n, char *out, size_t *out_len) return true; } -void term_osc52(struct term *t, const char *params) +void wsap_vtcore_osc52(struct wsap_vtcore *t, const char *params) { const char *sep = strchr(params, ';'); if (!sep || sep == params) diff --git a/src/osc/dispatch.c b/src/osc/dispatch.c index 400adbf..442c2e8 100644 --- a/src/osc/dispatch.c +++ b/src/osc/dispatch.c @@ -9,18 +9,18 @@ #define OSC_HEAP_INIT 4096 #define OSC_HEAP_KEEP (1u << 20) -size_t term_osc_room(const struct term *t) +size_t wsap_vtcore_osc_room(const struct wsap_vtcore *t) { size_t cap = t->osc_heap ? t->osc_heap_cap : sizeof(t->osc_buf); return cap - 1 - (size_t)t->osc_len; } -char *term_osc_tail(struct term *t) +char *wsap_vtcore_osc_tail(struct wsap_vtcore *t) { return (t->osc_heap ? t->osc_heap : t->osc_buf) + t->osc_len; } -bool term_osc_grow(struct term *t) +bool wsap_vtcore_osc_grow(struct wsap_vtcore *t) { if (!t->osc_heap) { char *p = malloc(OSC_HEAP_INIT); @@ -30,9 +30,9 @@ bool term_osc_grow(struct term *t) t->osc_heap_cap = OSC_HEAP_INIT; return true; } - if (t->osc_heap_cap >= TERM_OSC_MAX) return false; + if (t->osc_heap_cap >= WSAP_VTCORE_OSC_MAX) return false; size_t cap = t->osc_heap_cap * 2; - if (cap > TERM_OSC_MAX) cap = TERM_OSC_MAX; + if (cap > WSAP_VTCORE_OSC_MAX) cap = WSAP_VTCORE_OSC_MAX; char *p = realloc(t->osc_heap, cap); if (!p) return false; t->osc_heap = p; @@ -40,7 +40,7 @@ bool term_osc_grow(struct term *t) return true; } -void term_osc_cleanup(struct term *t) +void wsap_vtcore_osc_cleanup(struct wsap_vtcore *t) { free(t->osc_heap); t->osc_heap = NULL; @@ -48,7 +48,7 @@ void term_osc_cleanup(struct term *t) free(t->dcs_buf); t->dcs_buf = NULL; t->dcs_cap = 0; - term_osc8_cleanup(t); + wsap_vtcore_osc8_cleanup(t); free(t->cwd); t->cwd = NULL; free(t->pointer_shape); @@ -57,7 +57,7 @@ void term_osc_cleanup(struct term *t) /* Reply to a color query. An OSC 4 reply names the index it answers for; * index is negative for OSC 10, 11, and 12. */ -static void send_color_query_reply(struct term *t, int code, int index, uint32_t argb) +static void send_color_query_reply(struct wsap_vtcore *t, int code, int index, uint32_t argb) { char resp[64], prefix[16] = ""; uint8_t r = (argb >> 16) & 0xff, g = (argb >> 8) & 0xff, b = argb & 0xff; @@ -69,15 +69,15 @@ static void send_color_query_reply(struct term *t, int code, int index, uint32_t send_response(t, resp); } -static void osc_color_set_or_query(struct term *t, int code, const char *params, int slot) +static void osc_color_set_or_query(struct wsap_vtcore *t, int code, const char *params, int slot) { if (!strcmp(params, "?")) { send_color_query_reply(t, code, -1, t->palette.colors[slot]); return; } uint32_t argb; - if (term_color_parse(params, &argb)) - term_palette_set(&t->palette, slot, argb); + if (wsap_vtcore_color_parse(params, &argb)) + wsap_vtcore_palette_set(&t->palette, slot, argb); } static long osc_next_index(const char **pp) @@ -91,7 +91,7 @@ static long osc_next_index(const char **pp) return idx; } -static void osc4_handle(struct term *t, const char *params) +static void osc4_handle(struct wsap_vtcore *t, const char *params) { const char *p = params; while (*p) { @@ -113,8 +113,8 @@ static void osc4_handle(struct term *t, const char *params) memcpy(buf, spec, spec_len); buf[spec_len] = '\0'; uint32_t argb; - if (term_color_parse(buf, &argb)) - term_palette_set(&t->palette, (int)idx, argb); + if (wsap_vtcore_color_parse(buf, &argb)) + wsap_vtcore_palette_set(&t->palette, (int)idx, argb); } } p = spec_end; @@ -122,10 +122,10 @@ static void osc4_handle(struct term *t, const char *params) } } -static void osc104_handle(struct term *t, const char *params) +static void osc104_handle(struct wsap_vtcore *t, const char *params) { if (!*params) { - term_palette_reset_all(&t->palette); + wsap_vtcore_palette_reset_all(&t->palette); return; } const char *p = params; @@ -134,13 +134,13 @@ static void osc104_handle(struct term *t, const char *params) if (idx < 0) return; if (idx <= 255) - term_palette_reset(&t->palette, (int)idx); + wsap_vtcore_palette_reset(&t->palette, (int)idx); } } -void term_osc_finish(struct term *t) +void wsap_vtcore_osc_finish(struct wsap_vtcore *t) { - if (!term_str_was_truncated(t)) { + if (!wsap_vtcore_str_was_truncated(t)) { char *buf = t->osc_heap ? t->osc_heap : t->osc_buf; buf[t->osc_len] = '\0'; @@ -175,34 +175,34 @@ void term_osc_finish(struct term *t) osc4_handle(t, params); break; case 8: - term_osc8(t, params); + wsap_vtcore_osc8(t, params); break; case 10: - osc_color_set_or_query(t, 10, params, TERM_PALETTE_FG); + osc_color_set_or_query(t, 10, params, WSAP_VTCORE_PALETTE_FG); break; case 11: - osc_color_set_or_query(t, 11, params, TERM_PALETTE_BG); + osc_color_set_or_query(t, 11, params, WSAP_VTCORE_PALETTE_BG); break; case 12: - osc_color_set_or_query(t, 12, params, TERM_PALETTE_CURSOR); + osc_color_set_or_query(t, 12, params, WSAP_VTCORE_PALETTE_CURSOR); break; case 52: - term_osc52(t, params); + wsap_vtcore_osc52(t, params); break; case 104: osc104_handle(t, params); break; case 110: - term_palette_reset(&t->palette, TERM_PALETTE_FG); + wsap_vtcore_palette_reset(&t->palette, WSAP_VTCORE_PALETTE_FG); break; case 111: - term_palette_reset(&t->palette, TERM_PALETTE_BG); + wsap_vtcore_palette_reset(&t->palette, WSAP_VTCORE_PALETTE_BG); break; case 112: - term_palette_reset(&t->palette, TERM_PALETTE_CURSOR); + wsap_vtcore_palette_reset(&t->palette, WSAP_VTCORE_PALETTE_CURSOR); break; default: - term_osc_misc_dispatch(t, code, params); + wsap_vtcore_osc_misc_dispatch(t, code, params); break; } } diff --git a/src/osc/link.c b/src/osc/link.c index f31a750..363a568 100644 --- a/src/osc/link.c +++ b/src/osc/link.c @@ -4,15 +4,15 @@ #include <stdlib.h> #include <string.h> -#define TERM_LINK_MAX 8192 -#define TERM_LINK_URI_MAX 4096 +#define WSAP_VTCORE_LINK_MAX 8192 +#define WSAP_VTCORE_LINK_URI_MAX 4096 struct link_hash_slot { uint64_t hash; uint16_t id; }; -struct term_links { +struct wsap_vtcore_links { char **uri; uint16_t *free_ids; struct link_hash_slot *hash_table; @@ -31,7 +31,7 @@ static inline uint64_t hash_uri(const char *s) return h ? h : 1; } -static void links_insert_hash(struct term_links *l, uint64_t h, uint16_t id) +static void links_insert_hash(struct wsap_vtcore_links *l, uint64_t h, uint16_t id) { if (!l->hash_table || !l->hash_cap) return; @@ -48,9 +48,9 @@ static void links_insert_hash(struct term_links *l, uint64_t h, uint16_t id) } } -static bool links_grow(struct term_links *l) +static bool links_grow(struct wsap_vtcore_links *l) { - uint16_t new_cap = l->capacity == 0 ? 64 : l->capacity < 4096 ? l->capacity * 2 : TERM_LINK_MAX; + uint16_t new_cap = l->capacity == 0 ? 64 : l->capacity < 4096 ? l->capacity * 2 : WSAP_VTCORE_LINK_MAX; if (new_cap <= l->capacity) return false; char **new_uri = realloc(l->uri, sizeof(char *) * new_cap); @@ -89,7 +89,7 @@ static bool links_grow(struct term_links *l) static void links_mark_row(const struct cell *row, int len, uint64_t *mark, uint16_t cap) { - if (len > TERM_MAX_COLS) len = TERM_MAX_COLS; + if (len > WSAP_VTCORE_MAX_COLS) len = WSAP_VTCORE_MAX_COLS; for (int i = 0; i < len; i++) { uint16_t id = row[i].pad; if (id && id <= cap) @@ -123,19 +123,19 @@ static void links_mark_screen(const struct screen *s, struct links_mark *m) if (row->kind == ROW_CELLS) links_mark_row(row->cells, row->len, m->mark, m->cap); else - term_hist_text_mark_links(&row->text, links_mark_hist, m); + wsap_vtcore_hist_text_mark_links(&row->text, links_mark_hist, m); } } -static void links_gc(struct term *t, struct term_links *l) +static void links_gc(struct wsap_vtcore *t, struct wsap_vtcore_links *l) { - uint64_t mark[TERM_LINK_MAX / 64] = { 0 }; + uint64_t mark[WSAP_VTCORE_LINK_MAX / 64] = { 0 }; struct links_mark m = { mark, l->capacity }; links_mark_id(t->cur_link, mark, l->capacity); links_mark_screen(&t->scr, &m); if (t->alternate && t->alt_allocated) links_mark_screen(&t->alt_scr, &m); - term_hist_mark_links(&t->hist, links_mark_hist, &m); + wsap_vtcore_hist_mark_links(&t->hist, links_mark_hist, &m); l->free_count = 0; for (int i = 0; i + 1 < l->next; i++) { if (l->uri[i] && !(mark[i >> 6] & (1ull << (i & 63)))) { @@ -154,7 +154,7 @@ static void links_gc(struct term *t, struct term_links *l) } } -static uint16_t links_find(const struct term_links *l, const char *uri, uint64_t h) +static uint16_t links_find(const struct wsap_vtcore_links *l, const char *uri, uint64_t h) { if (!l->hash_table || !l->hash_cap) return 0; @@ -174,7 +174,7 @@ static uint16_t links_find(const struct term_links *l, const char *uri, uint64_t return 0; } -static uint16_t links_alloc(struct term *t, struct term_links *l) +static uint16_t links_alloc(struct wsap_vtcore *t, struct wsap_vtcore_links *l) { if (l->free_count) return l->free_ids[--l->free_count]; @@ -186,7 +186,7 @@ static uint16_t links_alloc(struct term *t, struct term_links *l) return 0; } -void term_osc8(struct term *t, const char *params) +void wsap_vtcore_osc8(struct wsap_vtcore *t, const char *params) { const char *sep = strchr(params, ';'); if (!sep) @@ -196,11 +196,11 @@ void term_osc8(struct term *t, const char *params) t->cur_link = 0; return; } - if (strlen(uri) > TERM_LINK_URI_MAX) { + if (strlen(uri) > WSAP_VTCORE_LINK_URI_MAX) { t->cur_link = 0; return; } - struct term_links *l = t->links; + struct wsap_vtcore_links *l = t->links; if (!l) { l = calloc(1, sizeof(*l)); if (!l) { @@ -218,7 +218,7 @@ void term_osc8(struct term *t, const char *params) t->cur_link = 0; return; } - l->uri[id - 1] = term_strdup(uri); + l->uri[id - 1] = wsap_vtcore_strdup(uri); if (!l->uri[id - 1]) { l->free_ids[l->free_count++] = id; t->cur_link = 0; @@ -229,12 +229,12 @@ void term_osc8(struct term *t, const char *params) t->cur_link = id; } -const char *term_osc8_url_at(const struct term *t, int col, int row) +const char *wsap_vtcore_osc8_url_at(const struct wsap_vtcore *t, int col, int row) { - const struct term_links *l = t->links; + const struct wsap_vtcore_links *l = t->links; if (!l || col < 0 || col >= t->cols) return NULL; - const struct cell *cells = term_screen_view_row(t, row); + const struct cell *cells = wsap_vtcore_screen_view_row(t, row); if (!cells) return NULL; uint16_t id = cells[col].pad; @@ -244,9 +244,9 @@ const char *term_osc8_url_at(const struct term *t, int col, int row) return l->uri[id - 1]; } -void term_osc8_cleanup(struct term *t) +void wsap_vtcore_osc8_cleanup(struct wsap_vtcore *t) { - struct term_links *l = t->links; + struct wsap_vtcore_links *l = t->links; if (!l) return; for (uint16_t i = 0; i < l->capacity; i++) diff --git a/src/osc/meson.build b/src/osc/meson.build index a3b9efa..efe79c2 100644 --- a/src/osc/meson.build +++ b/src/osc/meson.build @@ -1,4 +1,4 @@ -term_osc_src = files( +wsap_vtcore_osc_src = files( 'clipboard.c', 'dispatch.c', 'link.c', diff --git a/src/osc/misc.c b/src/osc/misc.c index 74b35cf..243c2ec 100644 --- a/src/osc/misc.c +++ b/src/osc/misc.c @@ -3,9 +3,9 @@ #include <stdlib.h> #include <string.h> -static void osc7_cwd(struct term *t, const char *uri) +static void osc7_cwd(struct wsap_vtcore *t, const char *uri) { - if (!term_has_prefix_ci(uri, "file://")) + if (!wsap_vtcore_has_prefix_ci(uri, "file://")) return; const char *p = uri + 7; const char *slash = strchr(p, '/'); @@ -16,8 +16,8 @@ static void osc7_cwd(struct term *t, const char *uri) char *d = cwd; while (*path) { int hi, lo; - if (*path == '%' && (hi = term_hex_nib(path[1])) >= 0 && - (lo = term_hex_nib(path[2])) >= 0) { + if (*path == '%' && (hi = wsap_vtcore_hex_nib(path[1])) >= 0 && + (lo = wsap_vtcore_hex_nib(path[2])) >= 0) { *d++ = (char)(hi * 16 + lo); path += 3; } else { @@ -29,7 +29,7 @@ static void osc7_cwd(struct term *t, const char *uri) t->cwd = cwd; } -static void osc777_notify(struct term *t, const char *params) +static void osc777_notify(struct wsap_vtcore *t, const char *params) { if (strncmp(params, "notify;", 7)) return; @@ -43,7 +43,7 @@ static void osc777_notify(struct term *t, const char *params) *wsep = ';'; } -void term_osc_misc_dispatch(struct term *t, long code, const char *params) +void wsap_vtcore_osc_misc_dispatch(struct wsap_vtcore *t, long code, const char *params) { if (!params) return; @@ -57,7 +57,7 @@ void term_osc_misc_dispatch(struct term *t, long code, const char *params) break; case 22: free(t->pointer_shape); - t->pointer_shape = *params ? term_strdup(params) : NULL; + t->pointer_shape = *params ? wsap_vtcore_strdup(params) : NULL; break; case 777: if (t->cb.notify) diff --git a/src/osc/osc.h b/src/osc/osc.h index 1d6680e..735e483 100644 --- a/src/osc/osc.h +++ b/src/osc/osc.h @@ -1,27 +1,27 @@ -#ifndef TERM_OSC_H -#define TERM_OSC_H +#ifndef WSAP_VTCORE_OSC_H +#define WSAP_VTCORE_OSC_H #include <stdbool.h> #include <stddef.h> #include <stdint.h> -struct term; +struct wsap_vtcore; -#define TERM_OSC_MAX (16u << 20) +#define WSAP_VTCORE_OSC_MAX (16u << 20) -size_t term_osc_room(const struct term *t); -char *term_osc_tail(struct term *t); -bool term_osc_grow(struct term *t); +size_t wsap_vtcore_osc_room(const struct wsap_vtcore *t); +char *wsap_vtcore_osc_tail(struct wsap_vtcore *t); +bool wsap_vtcore_osc_grow(struct wsap_vtcore *t); -void term_osc_finish(struct term *t); +void wsap_vtcore_osc_finish(struct wsap_vtcore *t); -void term_osc_cleanup(struct term *t); +void wsap_vtcore_osc_cleanup(struct wsap_vtcore *t); -void term_osc8(struct term *t, const char *params); -void term_osc52(struct term *t, const char *params); -void term_osc_misc_dispatch(struct term *t, long code, const char *params); +void wsap_vtcore_osc8(struct wsap_vtcore *t, const char *params); +void wsap_vtcore_osc52(struct wsap_vtcore *t, const char *params); +void wsap_vtcore_osc_misc_dispatch(struct wsap_vtcore *t, long code, const char *params); -const char *term_osc8_url_at(const struct term *t, int col, int row); -void term_osc8_cleanup(struct term *t); +const char *wsap_vtcore_osc8_url_at(const struct wsap_vtcore *t, int col, int row); +void wsap_vtcore_osc8_cleanup(struct wsap_vtcore *t); #endif diff --git a/src/palette.c b/src/palette.c index 610fe52..ab7d7a6 100644 --- a/src/palette.c +++ b/src/palette.c @@ -81,7 +81,7 @@ static inline float linf_to_srgbf(float c) : 12.92f * c; } -static const struct term_theme builtin_theme = { +static const struct wsap_vtcore_theme builtin_theme = { .fg = 0xFFFFFFFFu, .bg = 0xFF1E1E2Eu, .cursor = 0xFF89B4FAu, @@ -93,12 +93,12 @@ static const struct term_theme builtin_theme = { }, }; -void term_theme_default(struct term_theme *theme) +void wsap_vtcore_theme_default(struct wsap_vtcore_theme *theme) { *theme = builtin_theme; } -static const struct term_theme high_contrast_theme = { +static const struct wsap_vtcore_theme high_contrast_theme = { .fg = 0xFFFFFFFFu, .bg = 0xFF000000u, .cursor = 0xFF00FFFFu, @@ -110,14 +110,14 @@ static const struct term_theme high_contrast_theme = { }, }; -void term_theme_high_contrast(struct term_theme *theme) +void wsap_vtcore_theme_high_contrast(struct wsap_vtcore_theme *theme) { *theme = high_contrast_theme; } /* Finds the slot for key and the default it resets to. Keys are * foreground, background, and color0 to color15. */ -static uint32_t *palette_slot(struct term_theme *p, const char *key, +static uint32_t *palette_slot(struct wsap_vtcore_theme *p, const char *key, uint32_t *fallback) { if (!strcmp(key, "foreground")) { @@ -145,7 +145,7 @@ static uint32_t *palette_slot(struct term_theme *p, const char *key, return &p->ansi[i]; } -bool term_theme_set_key(struct term_theme *p, const char *key, const char *val) +bool wsap_vtcore_theme_set_key(struct wsap_vtcore_theme *p, const char *key, const char *val) { if (!p || !key || !val) return false; @@ -158,7 +158,7 @@ bool term_theme_set_key(struct term_theme *p, const char *key, const char *val) return true; } uint32_t v; - if (!term_color_parse(val, &v)) + if (!wsap_vtcore_color_parse(val, &v)) return false; *slot = v; return true; @@ -167,7 +167,7 @@ bool term_theme_set_key(struct term_theme *p, const char *key, const char *val) static bool parse_hex_channel(const char *s, size_t len, uint8_t *out) { if (len == 2) { - int d0 = term_hex_nib(s[0]), d1 = term_hex_nib(s[1]); + int d0 = wsap_vtcore_hex_nib(s[0]), d1 = wsap_vtcore_hex_nib(s[1]); if ((d0 | d1) < 0) return false; *out = (uint8_t)((d0 << 4) | d1); @@ -177,7 +177,7 @@ static bool parse_hex_channel(const char *s, size_t len, uint8_t *out) return false; unsigned value = 0; for (size_t i = 0; i < len; i++) { - int d = term_hex_nib(s[i]); + int d = wsap_vtcore_hex_nib(s[i]); if (d < 0) return false; value = (value << 4) | (unsigned)d; @@ -234,11 +234,11 @@ static bool parse_hex_rgb(const char *s, size_t cw, uint32_t *out) !parse_hex_channel(s + cw, cw, &g) || !parse_hex_channel(s + 2 * cw, cw, &b)) return false; - *out = term_rgb(r, g, b); + *out = wsap_vtcore_rgb(r, g, b); return true; } -bool term_color_parse(const char *input, uint32_t *out) +bool wsap_vtcore_color_parse(const char *input, uint32_t *out) { if (!input || !out) return false; @@ -294,7 +294,7 @@ bool term_color_parse(const char *input, uint32_t *out) parse_hex_channel(channels[j], chlens[j], &c[j]); if (!ok) return false; } - *out = term_rgb(c[0], c[1], c[2]); + *out = wsap_vtcore_rgb(c[0], c[1], c[2]); return true; } @@ -357,7 +357,7 @@ static uint32_t lab_to_rgb(struct lab lab) float g = linf_to_srgbf(-xf * 0.9692660f + yf * 1.8760108f + zf * 0.0415560f); float b = linf_to_srgbf(xf * 0.0556434f - yf * 0.2040259f + zf * 1.0572252f); - return term_rgb(quantize_channel(r), quantize_channel(g), quantize_channel(b)); + return wsap_vtcore_rgb(quantize_channel(r), quantize_channel(g), quantize_channel(b)); } static struct lab lab_lerp(float t, struct lab a, struct lab b) @@ -375,7 +375,7 @@ static struct lab lab_lerp(float t, struct lab a, struct lab b) * between the background, the ANSI colors, and the foreground, so they match * the theme instead of the fixed xterm values. */ -static void derive_palette(uint32_t *p, const struct term_theme *theme) +static void derive_palette(uint32_t *p, const struct wsap_vtcore_theme *theme) { struct lab base8[8]; base8[0] = lab_from_rgb(theme->bg); @@ -385,9 +385,9 @@ static void derive_palette(uint32_t *p, const struct term_theme *theme) for (int i = 0; i < 16; i++) p[i] = theme->ansi[i]; - p[TERM_PALETTE_FG] = theme->fg; - p[TERM_PALETTE_BG] = theme->bg; - p[TERM_PALETTE_CURSOR] = theme->cursor; + p[WSAP_VTCORE_PALETTE_FG] = theme->fg; + p[WSAP_VTCORE_PALETTE_BG] = theme->bg; + p[WSAP_VTCORE_PALETTE_CURSOR] = theme->cursor; bool is_light_theme = base8[7].l < base8[0].l; if (is_light_theme) { @@ -427,9 +427,9 @@ static void derive_palette(uint32_t *p, const struct term_theme *theme) } } -void term_palette_init(struct palette *p, const struct term_theme *theme) +void wsap_vtcore_palette_init(struct palette *p, const struct wsap_vtcore_theme *theme) { - static const struct term_theme zero; + static const struct wsap_vtcore_theme zero; p->theme = theme && memcmp(theme, &zero, sizeof(zero)) ? *theme : builtin_theme; if (!p->theme.cursor) p->theme.cursor = builtin_theme.cursor; @@ -438,21 +438,21 @@ void term_palette_init(struct palette *p, const struct term_theme *theme) p->version++; } -void term_palette_set(struct palette *p, int slot, uint32_t argb) +void wsap_vtcore_palette_set(struct palette *p, int slot, uint32_t argb) { - if ((unsigned)slot >= TERM_PALETTE_SIZE || p->colors[slot] == argb) + if ((unsigned)slot >= WSAP_VTCORE_PALETTE_SIZE || p->colors[slot] == argb) return; p->colors[slot] = argb; p->version++; } -void term_palette_reset(struct palette *p, int slot) +void wsap_vtcore_palette_reset(struct palette *p, int slot) { - if ((unsigned)slot < TERM_PALETTE_SIZE) - term_palette_set(p, slot, p->base[slot]); + if ((unsigned)slot < WSAP_VTCORE_PALETTE_SIZE) + wsap_vtcore_palette_set(p, slot, p->base[slot]); } -void term_palette_reset_all(struct palette *p) +void wsap_vtcore_palette_reset_all(struct palette *p) { if (memcmp(p->colors, p->base, sizeof(p->colors))) { memcpy(p->colors, p->base, sizeof(p->colors)); diff --git a/src/palette.h b/src/palette.h index 083ad8d..b5ac284 100644 --- a/src/palette.h +++ b/src/palette.h @@ -1,10 +1,10 @@ -#ifndef TERM_PALETTE_H -#define TERM_PALETTE_H +#ifndef WSAP_VTCORE_PALETTE_H +#define WSAP_VTCORE_PALETTE_H #include <stdbool.h> #include <stdint.h> -#include "term.h" +#include "wsap_vtcore.h" /* * The colors of one terminal. base holds the colors that the theme gives; @@ -12,18 +12,18 @@ * 10, 11, or 12. version changes whenever colors changes. */ struct palette { - uint32_t colors[TERM_PALETTE_SIZE]; - uint32_t base[TERM_PALETTE_SIZE]; - struct term_theme theme; + uint32_t colors[WSAP_VTCORE_PALETTE_SIZE]; + uint32_t base[WSAP_VTCORE_PALETTE_SIZE]; + struct wsap_vtcore_theme theme; uint64_t version; }; /* Set every entry from theme. An all-zero theme selects the built-in theme. */ -void term_palette_init(struct palette *p, const struct term_theme *theme); -/* Change one entry (0-255, TERM_PALETTE_FG, _BG, or _CURSOR). */ -void term_palette_set(struct palette *p, int slot, uint32_t argb); +void wsap_vtcore_palette_init(struct palette *p, const struct wsap_vtcore_theme *theme); +/* Change one entry (0-255, WSAP_VTCORE_PALETTE_FG, _BG, or _CURSOR). */ +void wsap_vtcore_palette_set(struct palette *p, int slot, uint32_t argb); /* Restore one entry, or all entries, to the theme color. */ -void term_palette_reset(struct palette *p, int slot); -void term_palette_reset_all(struct palette *p); +void wsap_vtcore_palette_reset(struct palette *p, int slot); +void wsap_vtcore_palette_reset_all(struct palette *p); #endif @@ -2,12 +2,12 @@ #define WSAP_TERM_PEN_H #include "compat.h" -#include "term.h" +#include "wsap_vtcore.h" #include <stdbool.h> #include <stdint.h> #include <string.h> -struct term_pen { +struct wsap_vtcore_pen { uint32_t fg; uint32_t bg; uint32_t ul; @@ -71,12 +71,12 @@ static inline void pen_set_text(struct pen_attr *p, struct text_pen pen) static inline struct pen_attr pen_attr_default(void) { - return (struct pen_attr){ .fg = TERM_COLOR_FG, .bg = TERM_COLOR_BG }; + return (struct pen_attr){ .fg = WSAP_VTCORE_COLOR_FG, .bg = WSAP_VTCORE_COLOR_BG }; } static inline bool pen_attr_is_default(const struct pen_attr *a) { - return a->fg == TERM_COLOR_FG && a->bg == TERM_COLOR_BG && a->flags == 0 && a->link == 0; + return a->fg == WSAP_VTCORE_COLOR_FG && a->bg == WSAP_VTCORE_COLOR_BG && a->flags == 0 && a->link == 0; } static inline bool pen_attr_equal(const struct pen_attr *a, const struct pen_attr *b) @@ -84,15 +84,15 @@ static inline bool pen_attr_equal(const struct pen_attr *a, const struct pen_att return a->fg == b->fg && a->bg == b->bg && a->flags == b->flags && a->link == b->link; } -static inline uint32_t term_rgb(int r, int g, int b) +static inline uint32_t wsap_vtcore_rgb(int r, int g, int b) { - return term_color_rgb((uint8_t)r, (uint8_t)g, (uint8_t)b); + return wsap_vtcore_color_rgb((uint8_t)r, (uint8_t)g, (uint8_t)b); } -static inline void pen_reset(struct term_pen *p) +static inline void pen_reset(struct wsap_vtcore_pen *p) { - p->fg = TERM_COLOR_FG; - p->bg = TERM_COLOR_BG; + p->fg = WSAP_VTCORE_COLOR_FG; + p->bg = WSAP_VTCORE_COLOR_BG; p->ul = 0; p->underline = 0; p->bold = false; @@ -112,7 +112,7 @@ static inline int sgr_extended_color(const int *params, int nparams, uint16_t su if (i + 2 < nparams && params[i + 1] == 5) { int index = params[i + 2]; if (index >= 0 && index <= 255) { - *color = term_color_index(index); + *color = wsap_vtcore_color_index(index); *assigned = true; } return 2; @@ -123,7 +123,7 @@ static inline int sgr_extended_color(const int *params, int nparams, uint16_t su int k = i + 2; if (k < 16 && k < nparams) { uint32_t shifted = (~(uint32_t)subparams) >> k; - colon = term_ctz32(shifted); + colon = wsap_vtcore_ctz32(shifted); int max_colon = (nparams < 16 ? nparams : 16) - k; if (colon > max_colon) colon = max_colon; @@ -131,27 +131,27 @@ static inline int sgr_extended_color(const int *params, int nparams, uint16_t su int skip = colon >= 4 ? 1 : 0; if (i + 4 + skip >= nparams) return 0; - *color = term_rgb(params[i + 2 + skip], params[i + 3 + skip], params[i + 4 + skip]); + *color = wsap_vtcore_rgb(params[i + 2 + skip], params[i + 3 + skip], params[i + 4 + skip]); *assigned = true; return 4 + skip; } -static inline bool pen_set_standard_color(struct term_pen *p, int code) +static inline bool pen_set_standard_color(struct wsap_vtcore_pen *p, int code) { if ((unsigned)(code - 30) < 8) - p->fg = term_color_index(code - 30); + p->fg = wsap_vtcore_color_index(code - 30); else if ((unsigned)(code - 40) < 8) - p->bg = term_color_index(code - 40); + p->bg = wsap_vtcore_color_index(code - 40); else if ((unsigned)(code - 90) < 8) - p->fg = term_color_index(code - 90 + 8); + p->fg = wsap_vtcore_color_index(code - 90 + 8); else if ((unsigned)(code - 100) < 8) - p->bg = term_color_index(code - 100 + 8); + p->bg = wsap_vtcore_color_index(code - 100 + 8); else return false; return true; } -static inline void sgr_apply(struct term_pen *pen, const int *params, int nparams, uint16_t subparams) +static inline void sgr_apply(struct wsap_vtcore_pen *pen, const int *params, int nparams, uint16_t subparams) { if (nparams == 0) { pen_reset(pen); @@ -185,14 +185,14 @@ static inline void sgr_apply(struct term_pen *pen, const int *params, int nparam if (ok) pen->fg = c; break; } - case 39: pen->fg = TERM_COLOR_FG; break; + case 39: pen->fg = WSAP_VTCORE_COLOR_FG; break; case 48: { uint32_t c; bool ok; i += sgr_extended_color(params, nparams, subparams, i, &c, &ok); if (ok) pen->bg = c; break; } - case 49: pen->bg = TERM_COLOR_BG; break; + case 49: pen->bg = WSAP_VTCORE_COLOR_BG; break; case 53: pen->overline = true; break; case 55: pen->overline = false; break; case 58: { @@ -1,11 +1,11 @@ #include "compat.h" #include "kernels.h" -#include "term.h" +#include "wsap_vtcore.h" -TERM_HOT -size_t term_scan_printable_span(const char *buf, size_t len, unsigned char hi) +WSAP_VTCORE_HOT +size_t wsap_vtcore_scan_printable_span(const char *buf, size_t len, unsigned char hi) { /* The only entry point that can run before the first terminal. */ - term_isa_init(); + wsap_vtcore_isa_init(); return scan_printable_span(buf, len, hi); } diff --git a/src/screen.c b/src/screen.c index ab6989a..8b1b5ce 100644 --- a/src/screen.c +++ b/src/screen.c @@ -10,7 +10,7 @@ static void *grow(struct grow_buf *b, size_t bytes) { if (bytes > b->cap) { - size_t cap = term_grow_cap(b->cap ? b->cap : 256, bytes); + size_t cap = wsap_vtcore_grow_cap(b->cap ? b->cap : 256, bytes); void *data = realloc(b->data, cap); if (!data) return NULL; @@ -52,7 +52,7 @@ static bool screen_setup(struct screen *s, int cols, int rows, uint64_t *next_ui s->text_slab = text_slab; s->text_cap = bytes; } - fill_cells(s->cells_slab, (int)cells, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(s->cells_slab, (int)cells, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); s->rows = rows; s->cols = cols; s->top = 0; @@ -79,7 +79,7 @@ static bool screen_setup(struct screen *s, int cols, int rows, uint64_t *next_ui return true; } -static void screen_push_row_inner(struct term *t, struct srow *row) +static void screen_push_row_inner(struct wsap_vtcore *t, struct srow *row) { srow_materialize_text(row); bool wrapped = (row->flags & RF_WRAPPED) != 0; @@ -93,27 +93,27 @@ static void screen_push_row_inner(struct term *t, struct srow *row) memset(tr->text + tr->text_len, ' ', (size_t)fill); text_commit(row, fill, fill, fill, HLINE_NARROW, (struct text_pen){ tr->fill.fg, tr->fill.bg, 0 }); } - term_hist_push_text(&t->hist, tr, wrapped); + wsap_vtcore_hist_push_text(&t->hist, tr, wrapped); return; } /* The rest of a wrapped row is part of the line: blanks up to the edge. */ - if (TERM_EXPECT(wrapped && row->len < cols, 0)) { + if (WSAP_VTCORE_EXPECT(wrapped && row->len < cols, 0)) { srow_settle(row, cols); if (!(row->flags & RF_TAIL_PADDED)) - fill_cells(row->cells + row->len, cols - row->len, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(row->cells + row->len, cols - row->len, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); row->flags |= RF_TAIL_PADDED; row->len = (uint16_t)cols; } - term_hist_push_row(&t->hist, row->cells, row->len, wrapped, t->gstore); + wsap_vtcore_hist_push_row(&t->hist, row->cells, row->len, wrapped, t->gstore); } -void term_screen_push_row(struct term *t, struct srow *row) +void wsap_vtcore_screen_push_row(struct wsap_vtcore *t, struct srow *row) { screen_push_row_inner(t, row); /* The push can drop more rows than it adds, so the view learns the new * history size here and not before. */ - if (TERM_EXPECT(t->view.anchor.active, 0)) - term_hist_view_note_push(&t->view, &t->hist, t->cols); + if (WSAP_VTCORE_EXPECT(t->view.anchor.active, 0)) + wsap_vtcore_hist_view_note_push(&t->view, &t->hist, t->cols); } static void screen_free(struct screen *s) @@ -127,35 +127,35 @@ static void screen_free(struct screen *s) } /* Read the history count without changing its rows. */ -int term_screen_history_rows(const struct term *t) +int wsap_vtcore_screen_history_rows(const struct wsap_vtcore *t) { if (!t || !screen_has_history(t)) return 0; - uint64_t rows = term_hist_view_rows(&t->view, &t->hist, t->cols); + uint64_t rows = wsap_vtcore_hist_view_rows(&t->view, &t->hist, t->cols); return rows > INT_MAX ? INT_MAX : (int)rows; } -int term_history_rows(const struct term *t) +int wsap_vtcore_history_rows(const struct wsap_vtcore *t) { if (!t) return 0; - term_write_begin((struct term *)t); - int rows = term_screen_history_rows(t); - term_write_end((struct term *)t); + wsap_vtcore_write_begin((struct wsap_vtcore *)t); + int rows = wsap_vtcore_screen_history_rows(t); + wsap_vtcore_write_end((struct wsap_vtcore *)t); return rows; } -const struct cell *term_screen_view_row(const struct term *t, int y) +const struct cell *wsap_vtcore_screen_view_row(const struct wsap_vtcore *t, int y) { if (!t || y < 0 || y >= t->rows) return NULL; struct hist_view_pos pos; - if (term_hist_view_row_pos(&t->view, &t->hist, t->cols, t->rows, screen_top_line(t), y, &pos)) { + if (wsap_vtcore_hist_view_row_pos(&t->view, &t->hist, t->cols, t->rows, screen_top_line(t), y, &pos)) { struct cell *out = t->view_row_scratch; - int got = term_hist_decode_segment(&t->hist, pos.id, pos.seg, t->cols, out, t->gstore); + int got = wsap_vtcore_hist_decode_segment(&t->hist, pos.id, pos.seg, t->cols, out, t->gstore); if (got < t->cols) { - fill_cells(out + got, t->cols - got, TERM_COLOR_FG, TERM_COLOR_BG); - int line_rows = term_hist_line_rows(&t->hist, pos.id, t->cols); + fill_cells(out + got, t->cols - got, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); + int line_rows = wsap_vtcore_hist_line_rows(&t->hist, pos.id, t->cols); if (pos.seg + 1 < line_rows || (pos.id + 1 == hist_end_id(&t->hist) && hist_is_open(&t->hist))) set_cells_wrap_pad(out + got, t->cols - got); } @@ -170,7 +170,7 @@ const struct cell *term_screen_view_row(const struct term *t, int y) return srow->cells; if (srow->len > 0) memcpy(out, srow->cells, (size_t)srow->len * sizeof(struct cell)); - fill_cells(out + srow->len, t->cols - srow->len, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(out + srow->len, t->cols - srow->len, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); return out; } text_row_cells(srow, out, t->cols); @@ -186,14 +186,14 @@ static inline uint64_t mix64(uint64_t x) return x ^ (x >> 33); } -uint64_t term_screen_view_row_key(const struct term *t, int y) +uint64_t wsap_vtcore_screen_view_row_key(const struct wsap_vtcore *t, int y) { if (!t || y < 0 || y >= t->rows) return 0; struct hist_view_pos pos; - if (term_hist_view_row_pos(&t->view, &t->hist, t->cols, t->rows, screen_top_line(t), y, &pos)) { + if (wsap_vtcore_hist_view_row_pos(&t->view, &t->hist, t->cols, t->rows, screen_top_line(t), y, &pos)) { uint64_t line_ver = (pos.id + 1 == hist_end_id(&t->hist) && hist_is_open(&t->hist)) - ? (term_hist_line_cells(&t->hist, pos.id) << 32) : 0; + ? (wsap_vtcore_hist_line_cells(&t->hist, pos.id) << 32) : 0; if (pos.id == t->hist.base_cell_id) line_ver ^= mix64(t->hist.base_cell); return mix64(((uint64_t)pos.id << 16) ^ (uint64_t)pos.seg ^ line_ver ^ 0x517cc1b727220a95ull); @@ -204,62 +204,62 @@ uint64_t term_screen_view_row_key(const struct term *t, int y) return mix64(row->uid ^ ((uint64_t)row->version << 32)); } -int term_view_offset(const struct term *t) +int wsap_vtcore_view_offset(const struct wsap_vtcore *t) { if (!t) return 0; - return term_hist_view_scroll_offset(&t->view, &t->hist, t->cols); + return wsap_vtcore_hist_view_scroll_offset(&t->view, &t->hist, t->cols); } -void term_scroll_to(struct term *t, int offset) +void wsap_vtcore_scroll_to(struct wsap_vtcore *t, int offset) { if (!t) return; - term_write_begin(t); + wsap_vtcore_write_begin(t); if (t->alternate || offset < 0) offset = 0; struct view_anchor old = t->view.anchor; - term_hist_view_scroll_to(&t->view, &t->hist, t->cols, screen_top_line(t), offset); + wsap_vtcore_hist_view_scroll_to(&t->view, &t->hist, t->cols, screen_top_line(t), offset); if (old.active != t->view.anchor.active || old.line_id != t->view.anchor.line_id || old.seg != t->view.anchor.seg) t->full_gen++; - term_write_end(t); + wsap_vtcore_write_end(t); } -void term_scroll(struct term *t, int lines) +void wsap_vtcore_scroll(struct wsap_vtcore *t, int lines) { if (!t) return; /* Read the alternate flag inside the writer section. A read before - * term_write_begin races with a feed on another thread. */ - term_write_begin(t); + * wsap_vtcore_write_begin races with a feed on another thread. */ + wsap_vtcore_write_begin(t); if (t->alternate) { - term_write_end(t); + wsap_vtcore_write_end(t); return; } struct view_anchor old = t->view.anchor; - term_hist_view_scroll(&t->view, &t->hist, t->cols, screen_top_line(t), lines); + wsap_vtcore_hist_view_scroll(&t->view, &t->hist, t->cols, screen_top_line(t), lines); if (old.active != t->view.anchor.active || old.line_id != t->view.anchor.line_id || old.seg != t->view.anchor.seg) t->full_gen++; - term_write_end(t); + wsap_vtcore_write_end(t); } -struct term_scrollback term_scrollback(const struct term *t) +struct wsap_vtcore_scrollback wsap_vtcore_scrollback(const struct wsap_vtcore *t) { if (!t) - return (struct term_scrollback){ 0 }; - term_write_begin((struct term *)t); - struct term_scrollback sb = { 0 }; + return (struct wsap_vtcore_scrollback){ 0 }; + wsap_vtcore_write_begin((struct wsap_vtcore *)t); + struct wsap_vtcore_scrollback sb = { 0 }; if (!t->alternate) { - sb.offset = term_view_offset(t); - sb.total = term_screen_history_rows(t); + sb.offset = wsap_vtcore_view_offset(t); + sb.total = wsap_vtcore_screen_history_rows(t); } - term_write_end((struct term *)t); + wsap_vtcore_write_end((struct wsap_vtcore *)t); return sb; } -void term_screen_erase_line(struct term *t, int mode) +void wsap_vtcore_screen_erase_line(struct wsap_vtcore *t, int mode) { t->pending_wrap = false; int p = phys_row(t, t->cursor_y); @@ -272,7 +272,7 @@ void term_screen_erase_line(struct term *t, int mode) } } -void term_screen_delete_chars(struct term *t, int n) +void wsap_vtcore_screen_delete_chars(struct wsap_vtcore *t, int n) { t->pending_wrap = false; if (t->cursor_x >= t->cols) @@ -283,7 +283,7 @@ void term_screen_delete_chars(struct term *t, int n) n = cols - x; int p = phys_row(t, t->cursor_y); struct cell *row = row_cells(t, p); - struct srow *srow = term_row(t, t->cursor_y); + struct srow *srow = wsap_vtcore_row(t, t->cursor_y); int len = srow->len; clear_wide_edges(row, x, x + n, len); if (len > cols) { @@ -304,7 +304,7 @@ void term_screen_delete_chars(struct term *t, int n) int from = cols - n; if (from < x) from = x; - term_row_fill_gap(srow, from); + wsap_vtcore_row_fill_gap(srow, from); fill_cells(&row[from], cols - from, t->cur_fg, t->cur_bg); srow->len = (uint16_t)cols; } @@ -313,7 +313,7 @@ void term_screen_delete_chars(struct term *t, int n) srow->version++; } -void term_screen_insert_chars(struct term *t, int n) +void wsap_vtcore_screen_insert_chars(struct wsap_vtcore *t, int n) { t->pending_wrap = false; if (t->cursor_x >= t->cols) @@ -324,8 +324,8 @@ void term_screen_insert_chars(struct term *t, int n) n = cols - x; int p = phys_row(t, t->cursor_y); struct cell *row = row_cells(t, p); - struct srow *srow = term_row(t, t->cursor_y); - term_row_fill_gap(srow, x); + struct srow *srow = wsap_vtcore_row(t, t->cursor_y); + wsap_vtcore_row_fill_gap(srow, x); int len = srow->len; if (x > 0 && x < len && (row[x].flags & CELL_TRAIL)) { fill_cells(row + x - 1, 2, t->cur_fg, t->cur_bg); @@ -355,7 +355,7 @@ void term_screen_insert_chars(struct term *t, int n) srow->version++; } -void term_screen_erase_all(struct term *t) +void wsap_vtcore_screen_erase_all(struct wsap_vtcore *t) { t->pending_wrap = false; struct screen *s = &t->scr; @@ -369,9 +369,9 @@ void term_screen_erase_all(struct term *t) t->full_gen++; } -#if defined(TERM_KERNEL_AVX2) +#if defined(WSAP_VTCORE_KERNEL_AVX2) /* The inner columns [1, len - 1): the callers probed both ends. */ -TERM_TARGET_AVX2 +WSAP_VTCORE_TARGET_AVX2 static bool text_has_text_avx2(const uint8_t *text, int len) { int x = 1; @@ -388,7 +388,7 @@ static bool text_has_text_avx2(const uint8_t *text, int len) return false; } -TERM_TARGET_AVX2 +WSAP_VTCORE_TARGET_AVX2 static bool cells_has_text_avx2(const struct cell *cells, int len) { int x = 1; @@ -433,8 +433,8 @@ static inline bool text_has_text(const uint8_t *text, int len) return true; } #elif defined(__x86_64__) -#if defined(TERM_KERNEL_AVX2) - if (term_use_avx2()) +#if defined(WSAP_VTCORE_KERNEL_AVX2) + if (wsap_vtcore_use_avx2()) return text_has_text_avx2(text, len); #endif const __m128i vspace = _mm_set1_epi8(' '); @@ -473,8 +473,8 @@ static inline bool cells_has_text(const struct cell *cells, int len) if (vmaxvq_u32(cmp) != 0) return true; } -#elif defined(TERM_KERNEL_AVX2) - if (term_use_avx2()) +#elif defined(WSAP_VTCORE_KERNEL_AVX2) + if (wsap_vtcore_use_avx2()) return cells_has_text_avx2(cells, len); #endif for (; x < len - 1; x++) @@ -493,14 +493,14 @@ static inline bool srow_has_text(const struct srow *r, int cols) return cells_has_text(r->cells, len); } -void term_screen_erase(struct term *t, int mode) +void wsap_vtcore_screen_erase(struct wsap_vtcore *t, int mode) { t->pending_wrap = false; if (mode == 3) { - term_hist_clear(&t->hist); + wsap_vtcore_hist_clear(&t->hist); t->view.anchor = (struct view_anchor){0}; t->view.index_cols = 0; - term_select_clear(t); + wsap_vtcore_select_clear(t); t->full_gen++; return; } @@ -514,8 +514,8 @@ void term_screen_erase(struct term *t, int mode) for (int y = rows - 1; y >= 0; y--) { const struct srow *r = &slots[p]; p = (p == 0) ? rows - 1 : p - 1; - if (TERM_EXPECT(r->len == 0, 1)) { - if (TERM_EXPECT((r->flags & RF_WRAPPED) != 0, 0)) + if (WSAP_VTCORE_EXPECT(r->len == 0, 1)) { + if (WSAP_VTCORE_EXPECT((r->flags & RF_WRAPPED) != 0, 0)) tail_clean = false; continue; } @@ -526,13 +526,13 @@ void term_screen_erase(struct term *t, int mode) tail_clean = false; } if (last_active >= 0 && !t->alternate) { - term_screen_scroll_region(t, 0, rows - 1, last_active + 1, false, true); + wsap_vtcore_screen_scroll_region(t, 0, rows - 1, last_active + 1, false, true); if (tail_clean) { t->view.anchor = (struct view_anchor){0}; return; } } - term_screen_erase_all(t); + wsap_vtcore_screen_erase_all(t); t->view.anchor = (struct view_anchor){0}; t->full_gen++; } else if (mode == 0) { @@ -561,7 +561,7 @@ void term_screen_erase(struct term *t, int mode) } /* Reset a recycled row's contents and identity; callers choose its version. */ -static inline void reset_scrolled_row(struct term *t, struct srow *row, bool def) +static inline void reset_scrolled_row(struct wsap_vtcore *t, struct srow *row, bool def) { row->kind = ROW_CELLS; row->uid = ++t->next_row_uid; @@ -575,7 +575,7 @@ static inline void reset_scrolled_row(struct term *t, struct srow *row, bool def } } -static void rotate_and_clear_srows(struct term *t, struct srow *base, int height, +static void rotate_and_clear_srows(struct wsap_vtcore *t, struct srow *base, int height, int count, bool down, bool def) { struct srow tmp[64]; @@ -600,7 +600,7 @@ static void rotate_and_clear_srows(struct term *t, struct srow *base, int height free(saved); } -void term_screen_scroll_region(struct term *t, int top, int bottom, int count, +void wsap_vtcore_screen_scroll_region(struct wsap_vtcore *t, int top, int bottom, int count, bool down, bool history) { t->pending_wrap = false; @@ -619,7 +619,7 @@ void term_screen_scroll_region(struct term *t, int top, int bottom, int count, if (!down) { bool has_hist = history && screen_has_history(t); - if (TERM_EXPECT(t->prompt_y >= 0, 0) && !t->alternate) { + if (WSAP_VTCORE_EXPECT(t->prompt_y >= 0, 0) && !t->alternate) { if (history) { if (t->prompt_y > 0) t->prompt_y = t->prompt_y > count ? t->prompt_y - count : 0; @@ -635,8 +635,8 @@ void term_screen_scroll_region(struct term *t, int top, int bottom, int count, int p = orig_top + i; if (p >= rows) p -= rows; struct srow *row = &s->slot[p]; - if (TERM_EXPECT(has_hist, 1)) - term_screen_push_row(t, row); + if (WSAP_VTCORE_EXPECT(has_hist, 1)) + wsap_vtcore_screen_push_row(t, row); else screen_drop_top(s, row); if (history) { @@ -683,9 +683,9 @@ void term_screen_scroll_region(struct term *t, int top, int bottom, int count, if (!down && history && top == 0 && !t->alternate) { for (int i = 0; i < count; i++) { - term_screen_scroll_up(t); + wsap_vtcore_screen_scroll_up(t); if (bottom + 1 < t->rows) - term_screen_scroll_region(t, bottom, t->rows - 1, 1, true, false); + wsap_vtcore_screen_scroll_region(t, bottom, t->rows - 1, 1, true, false); } return; } @@ -734,9 +734,9 @@ void term_screen_scroll_region(struct term *t, int top, int bottom, int count, t->full_gen++; } -static bool term_resize_internal(struct term *t, int cols, int rows); +static bool wsap_vtcore_resize_internal(struct wsap_vtcore *t, int cols, int rows); -void term_screen_set_alternate(struct term *t, bool enabled) +void wsap_vtcore_screen_set_alternate(struct wsap_vtcore *t, bool enabled) { if (t->alternate == enabled) return; @@ -759,7 +759,7 @@ void term_screen_set_alternate(struct term *t, bool enabled) struct screen tmp_scr = t->scr; t->scr = t->alt_scr; t->alt_scr = tmp_scr; - t->normal_saved_cursor = term_cursor_save(t); + t->normal_saved_cursor = wsap_vtcore_cursor_save(t); t->normal_saved_decsc = t->saved; t->normal_cursor_visible = t->cursor_visible; t->normal_cursor_style = (uint8_t)t->cursor_style; @@ -776,7 +776,7 @@ void term_screen_set_alternate(struct term *t, bool enabled) t->right_margin = t->cols - 1; /* The alternate screen has no history to show. */ t->view.anchor = (struct view_anchor){0}; - term_select_clear(t); + wsap_vtcore_select_clear(t); t->full_gen++; } else { int cols = t->cols; @@ -789,29 +789,29 @@ void term_screen_set_alternate(struct term *t, bool enabled) t->alternate = false; t->saved = t->normal_saved_decsc; t->cursor_visible = t->normal_cursor_visible; - t->cursor_style = (enum term_cursor_style)t->normal_cursor_style; + t->cursor_style = (enum wsap_vtcore_cursor_style)t->normal_cursor_style; t->cursor_blink = t->normal_cursor_blink; - term_cursor_apply(t, &t->normal_saved_cursor); + wsap_vtcore_cursor_apply(t, &t->normal_saved_cursor); t->cursor_x = t->normal_saved_cursor.x; t->cursor_y = t->normal_saved_cursor.y; t->pending_wrap = t->normal_saved_cursor.pending_wrap; if (cols != t->cols || rows != t->rows) - term_resize_internal(t, cols, rows); + wsap_vtcore_resize_internal(t, cols, rows); t->scroll_top = 0; t->scroll_bottom = t->rows - 1; t->left_margin = 0; t->right_margin = t->cols - 1; /* The alternate screen has no history to show. */ t->view.anchor = (struct view_anchor){0}; - term_select_clear(t); + wsap_vtcore_select_clear(t); t->full_gen++; } } -/* The caller has checked that requested is in [0, TERM_SCROLLBACK_MAX]. */ +/* The caller has checked that requested is in [0, WSAP_VTCORE_SCROLLBACK_MAX]. */ static int scrollback_lines(int requested) { - return requested == 0 ? TERM_SCROLLBACK_DEFAULT : requested; + return requested == 0 ? WSAP_VTCORE_SCROLLBACK_DEFAULT : requested; } static atomic_int tables_state; @@ -824,16 +824,16 @@ static void tables_init(void) return; int expected = 0; if (atomic_compare_exchange_strong(&tables_state, &expected, 1)) { - term_isa_init(); - term_text_tables_init(); + wsap_vtcore_isa_init(); + wsap_vtcore_text_tables_init(); atomic_store_explicit(&tables_state, 2, memory_order_release); return; } while (atomic_load_explicit(&tables_state, memory_order_acquire) != 2) - term_cpu_relax(); + wsap_vtcore_cpu_relax(); } -bool term_tables_ready(void) +bool wsap_vtcore_tables_ready(void) { return atomic_load_explicit(&tables_state, memory_order_relaxed) == 2; } @@ -849,31 +849,31 @@ static bool name_valid(const char *s) return true; } -struct term *term_new(const struct term_options *opt) +struct wsap_vtcore *wsap_vtcore_new(const struct wsap_vtcore_options *opt) { tables_init(); - static const struct term_options defaults; + static const struct wsap_vtcore_options defaults; if (!opt) opt = &defaults; for (size_t i = 0; i < sizeof(opt->reserved) / sizeof(opt->reserved[0]); i++) if (opt->reserved[i]) return NULL; - if (opt->size.x < 0 || opt->size.y < 0 || opt->size.x > TERM_MAX_COLS) + if (opt->size.x < 0 || opt->size.y < 0 || opt->size.x > WSAP_VTCORE_MAX_COLS) return NULL; - if (opt->scrollback < 0 || opt->scrollback > TERM_SCROLLBACK_MAX || - (unsigned)opt->cursor_style > TERM_CURSOR_BAR) + if (opt->scrollback < 0 || opt->scrollback > WSAP_VTCORE_SCROLLBACK_MAX || + (unsigned)opt->cursor_style > WSAP_VTCORE_CURSOR_BAR) return NULL; - const char *name = opt->name && *opt->name ? opt->name : "term"; + const char *name = opt->name && *opt->name ? opt->name : "wsap_vtcore"; if (!name_valid(name)) return NULL; int cols = opt->size.x == 0 ? 80 : opt->size.x; int rows = opt->size.y == 0 ? 24 : opt->size.y; static _Atomic uint64_t next_serial = 1; - struct term *t = calloc(1, sizeof(*t)); + struct wsap_vtcore *t = calloc(1, sizeof(*t)); if (!t) return NULL; - if (!term_mutex_init(&t->write_lock)) { + if (!wsap_vtcore_mutex_init(&t->write_lock)) { free(t); return NULL; } @@ -888,35 +888,35 @@ struct term *term_new(const struct term_options *opt) t->prompt_y = -1; t->sb_capacity = scrollback_lines(opt->scrollback); t->cb = opt->callbacks; - term_palette_init(&t->palette, &opt->theme); + wsap_vtcore_palette_init(&t->palette, &opt->theme); t->next_row_uid = 1; if (!screen_setup(&t->scr, cols, rows, &t->next_row_uid)) { - term_mutex_destroy(&t->write_lock); + wsap_vtcore_mutex_destroy(&t->write_lock); free(t); return NULL; } - if (!term_hist_init(&t->hist, t->sb_capacity, 0)) { + if (!wsap_vtcore_hist_init(&t->hist, t->sb_capacity, 0)) { screen_free(&t->scr); - term_mutex_destroy(&t->write_lock); + wsap_vtcore_mutex_destroy(&t->write_lock); free(t); return NULL; } t->hist.wrap_cols = (uint16_t)cols; - t->gstore = term_gstore_new(t); + t->gstore = wsap_vtcore_gstore_new(t); t->view_scratch_cap = cols > 256 ? cols : 256; t->view_row_scratch = calloc((size_t)t->view_scratch_cap, sizeof(struct cell)); t->tabs_cap = cols > 256 ? cols : 256; t->tabs = calloc((size_t)t->tabs_cap, 1); if (!t->gstore || !t->view_row_scratch || !t->tabs) { - term_free(t); + wsap_vtcore_free(t); return NULL; } - t->cur_fg = TERM_COLOR_FG; - t->cur_bg = TERM_COLOR_BG; + t->cur_fg = WSAP_VTCORE_COLOR_FG; + t->cur_bg = WSAP_VTCORE_COLOR_BG; t->cursor_visible = true; t->default_cursor_style = opt->cursor_style; t->default_cursor_blink = !opt->cursor_steady; @@ -924,16 +924,16 @@ struct term *term_new(const struct term_options *opt) t->cursor_blink = t->default_cursor_blink; t->autowrap = true; t->charsets[0] = t->charsets[1] = 'B'; - t->saved = term_saved_cursor_initial(); + t->saved = wsap_vtcore_saved_cursor_initial(); memcpy(t->tcap_name, t->name, sizeof(t->name)); - term_tabs_default(t); + wsap_vtcore_tabs_default(t); t->full_gen = 1; memset(t->text_width.lo, 0xFF, sizeof(t->text_width.lo)); return t; } -void term_free(struct term *t) +void wsap_vtcore_free(struct wsap_vtcore *t) { if (!t) return; @@ -949,13 +949,13 @@ void term_free(struct term *t) free(t->resize.lens.data); free(t->ascii_ends.data); free(t->ascii_tail.data); - term_hist_free(&t->hist); - term_hist_view_free(&t->view); + wsap_vtcore_hist_free(&t->hist); + wsap_vtcore_hist_view_free(&t->view); free(t->view_row_scratch); free(t->tabs); - term_osc_cleanup(t); - term_gstore_free(t->gstore); - term_mutex_destroy(&t->write_lock); + wsap_vtcore_osc_cleanup(t); + wsap_vtcore_gstore_free(t->gstore); + wsap_vtcore_mutex_destroy(&t->write_lock); free(t); } @@ -1005,7 +1005,7 @@ static bool reflow_target_end_row(struct reflow_target *r, bool wrapped) int len = r->x > r->cols ? r->cols : r->x; memcpy(dst_cells, r->cells, (size_t)len * sizeof(struct cell)); if (len < r->cols) - fill_cells(dst_cells + len, r->cols - len, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(dst_cells + len, r->cols - len, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); dst->len = len; dst->wrapped = wrapped; r->x = 0; @@ -1025,7 +1025,7 @@ static bool reflow_append_span(struct reflow_target *r, const struct cell *cells int take = len - i < room ? len - i : room; if (i + take < len && (cells[i + take].flags & CELL_TRAIL)) { if (--take == 0) { - r->cells[r->x] = (struct cell){' ', TERM_COLOR_FG, TERM_COLOR_BG, CELL_WRAP_PAD, 0}; + r->cells[r->x] = (struct cell){' ', WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG, CELL_WRAP_PAD, 0}; r->x++; if (!reflow_target_end_row(r, true)) return false; @@ -1075,7 +1075,7 @@ static bool reflow_append_wide(struct reflow_target *r, const struct cell *cells int n = (cells[i].flags & CELL_WIDE) && r->cols > 1 ? 2 : 1; if (r->x + n > r->cols) { if (r->x < r->cols) { - r->cells[r->x] = (struct cell){' ', TERM_COLOR_FG, TERM_COLOR_BG, CELL_WRAP_PAD, 0}; + r->cells[r->x] = (struct cell){' ', WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG, CELL_WRAP_PAD, 0}; r->x++; } if (!reflow_target_end_row(r, true)) @@ -1140,26 +1140,26 @@ static bool reflow_append(struct reflow_target *r, const struct cell *cells, int /* Move up to max_pull rows from the end of history to the top of dst. A line * that does not fit whole leaves its first rows in history, still open. */ -static int pull_history_rows(struct term *t, struct screen *dst_scr, int cols, int max_pull) +static int pull_history_rows(struct wsap_vtcore *t, struct screen *dst_scr, int cols, int max_pull) { struct hist *h = &t->hist; int pull = 0; for (uint64_t id = hist_end_id(h); pull < max_pull && id > hist_first_id(h); id--) - pull += term_hist_line_rows(h, id - 1, cols); + pull += wsap_vtcore_hist_line_rows(h, id - 1, cols); if (pull > max_pull) pull = max_pull; int slot = pull; while (slot > 0) { uint64_t id = hist_end_id(h) - 1; - int line_rows = term_hist_line_rows(h, id, cols); + int line_rows = wsap_vtcore_hist_line_rows(h, id, cols); bool open = hist_is_open(h); int take = slot < line_rows ? slot : line_rows; int first = line_rows - take; struct cell *pull_buf = grow(&t->resize.pull, (size_t)take * (size_t)cols * sizeof(*pull_buf)); int *pull_lens = grow(&t->resize.lens, (size_t)take * sizeof(*pull_lens)); if (pull_buf && pull_lens) - term_hist_decode_segments(h, id, first, take, cols, pull_buf, pull_lens, t->gstore); + wsap_vtcore_hist_decode_segments(h, id, first, take, cols, pull_buf, pull_lens, t->gstore); for (int seg = line_rows - 1; seg >= first; seg--) { struct srow *dst = &dst_scr->slot[--slot]; int idx = seg - first; @@ -1168,7 +1168,7 @@ static int pull_history_rows(struct term *t, struct screen *dst_scr, int cols, i memcpy(dst->cells, pull_buf + (size_t)idx * cols, (size_t)cols * sizeof(struct cell)); bool wrapped = seg + 1 < line_rows || open; if (got < cols) { - fill_cells(dst->cells + got, cols - got, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(dst->cells + got, cols - got, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); if (wrapped) { set_cells_wrap_pad(dst->cells + got, cols - got); got = cols; @@ -1181,20 +1181,20 @@ static int pull_history_rows(struct term *t, struct screen *dst_scr, int cols, i dst->uid = ++t->next_row_uid; } if (first == 0) { - term_hist_pop_line(h, NULL, 0, t->gstore); + wsap_vtcore_hist_pop_line(h, NULL, 0, t->gstore); continue; } struct cell *rest = grow(&t->resize.rest, (size_t)first * (size_t)cols * sizeof(*rest)); int *lens = grow(&t->resize.lens, (size_t)first * sizeof(*lens)); if (rest && lens) - term_hist_decode_segments(h, id, 0, first, cols, rest, lens, t->gstore); - term_hist_pop_line(h, NULL, 0, t->gstore); + wsap_vtcore_hist_decode_segments(h, id, 0, first, cols, rest, lens, t->gstore); + wsap_vtcore_hist_pop_line(h, NULL, 0, t->gstore); if (rest && lens) { for (int seg = 0; seg < first; seg++) { struct cell *row = rest + (size_t)seg * cols; if (lens[seg] < cols) - fill_cells(row + lens[seg], cols - lens[seg], TERM_COLOR_FG, TERM_COLOR_BG); - term_hist_push_row(h, row, cols, true, t->gstore); + fill_cells(row + lens[seg], cols - lens[seg], WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); + wsap_vtcore_hist_push_row(h, row, cols, true, t->gstore); } } } @@ -1202,7 +1202,7 @@ static int pull_history_rows(struct term *t, struct screen *dst_scr, int cols, i } /* The spare screen, set up as cols x rows, for a resize to build into. */ -static bool resize_target(struct term *t, struct screen *out, int cols, int rows, +static bool resize_target(struct wsap_vtcore *t, struct screen *out, int cols, int rows, const struct screen *from) { *out = t->spare; @@ -1250,9 +1250,9 @@ static void copy_srow_resized(struct srow *dst, struct srow *src, int old_cols, dst->version = src->version + 1; } -static bool term_resize_internal(struct term *t, int cols, int rows) +static bool wsap_vtcore_resize_internal(struct wsap_vtcore *t, int cols, int rows) { - term_gstore_pin(t->gstore); + wsap_vtcore_gstore_pin(t->gstore); if (t->alternate || cols == t->scr.cols) { struct screen *active_scr = &t->scr; @@ -1261,7 +1261,7 @@ static bool term_resize_internal(struct term *t, int cols, int rows) struct screen new_scr; if (!resize_target(t, &new_scr, cols, rows, active_scr)) { - term_gstore_unpin(t->gstore); + wsap_vtcore_gstore_unpin(t->gstore); return false; } @@ -1270,7 +1270,7 @@ static bool term_resize_internal(struct term *t, int cols, int rows) if (rows < old_rows && t->cursor_y >= rows) { int shift = t->cursor_y - rows + 1; for (int i = 0; i < shift; i++) - term_screen_scroll_up(t); + wsap_vtcore_screen_scroll_up(t); t->cursor_y -= shift; t->saved.y = t->saved.y >= shift ? t->saved.y - shift : 0; } @@ -1322,9 +1322,9 @@ static bool term_resize_internal(struct term *t, int cols, int rows) t->scroll_bottom = rows - 1; t->left_margin = 0; t->right_margin = cols - 1; - term_hist_view_rewrap(&t->view, &t->hist, cols); + wsap_vtcore_hist_view_rewrap(&t->view, &t->hist, cols); t->full_gen++; - term_gstore_unpin(t->gstore); + wsap_vtcore_gstore_unpin(t->gstore); return true; } @@ -1333,7 +1333,7 @@ static bool term_resize_internal(struct term *t, int cols, int rows) struct screen new_scr; if (!resize_target(t, &new_scr, cols, rows, &t->scr)) { - term_gstore_unpin(t->gstore); + wsap_vtcore_gstore_unpin(t->gstore); return false; } @@ -1357,17 +1357,17 @@ static bool term_resize_internal(struct term *t, int cols, int rows) }; if (!r.cells) { t->spare = new_scr; - term_gstore_unpin(t->gstore); + wsap_vtcore_gstore_unpin(t->gstore); return false; } /* The open history line reflows with the screen. It is read here and * removed only after the reflow succeeds. The prompt line never rewraps. */ if (hist_is_open(&t->hist) && t->prompt_y != 0) { - uint64_t n = term_hist_line_cells(&t->hist, hist_end_id(&t->hist) - 1); + uint64_t n = wsap_vtcore_hist_line_cells(&t->hist, hist_end_id(&t->hist) - 1); struct cell *pulled = n ? grow(&t->resize.pull, n * sizeof(*pulled)) : NULL; if (n && !pulled) goto reflow_failed; - int got = term_hist_peek_last_line(&t->hist, pulled, pulled ? (int)n : 0, t->gstore); + int got = wsap_vtcore_hist_peek_last_line(&t->hist, pulled, pulled ? (int)n : 0, t->gstore); if (pulled && got > 0 && !reflow_append(&r, pulled, got, -1, -1)) goto reflow_failed; } @@ -1425,14 +1425,14 @@ static bool term_resize_internal(struct term *t, int cols, int rows) if (len > src->len && src->len < old_cols && !(src->flags & RF_TAIL_PADDED)) { fill_cells(src->cells + src->len, old_cols - src->len, - TERM_COLOR_FG, TERM_COLOR_BG); + WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); src->flags |= RF_TAIL_PADDED; } const struct cell *in_cells = cells; if (len > old_cols && line_buf && (size_t)len <= line_cap) { memcpy(line_buf, cells, (size_t)old_cols * sizeof(struct cell)); - fill_cells(line_buf + old_cols, len - old_cols, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(line_buf + old_cols, len - old_cols, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); in_cells = line_buf; } else if (len > old_cols) { len = old_cols; @@ -1453,11 +1453,11 @@ static bool term_resize_internal(struct term *t, int cols, int rows) * nothing below can fail. */ if (hist_is_open(&t->hist)) { if (t->prompt_y == 0) - term_hist_close_open_line(&t->hist); + wsap_vtcore_hist_close_open_line(&t->hist); else - term_hist_pop_line(&t->hist, NULL, 0, t->gstore); + wsap_vtcore_hist_pop_line(&t->hist, NULL, 0, t->gstore); } - term_hist_set_width(&t->hist, cols); + wsap_vtcore_hist_set_width(&t->hist, cols); int visible = rows - (cols > old_cols ? old_rows - active : 0); if (visible < 1) @@ -1471,7 +1471,7 @@ static bool term_resize_internal(struct term *t, int cols, int rows) screen_start = r.cursor_y; for (int i = 0; i < screen_start; i++) { int push_len = (r.out[i].wrapped && r.out[i].len < cols) ? cols : r.out[i].len; - term_hist_push_row(&t->hist, reflow_out_row_cells(&r, i), push_len, + wsap_vtcore_hist_push_row(&t->hist, reflow_out_row_cells(&r, i), push_len, r.out[i].wrapped, t->gstore); } } else if (r.count < visible && t->hist.lines > 0) { @@ -1487,7 +1487,7 @@ static bool term_resize_internal(struct term *t, int cols, int rows) int len = r.out[i].len; memcpy(dst->cells, reflow_out_row_cells(&r, i), (size_t)len * sizeof(struct cell)); if (len < cols) - fill_cells(dst->cells + len, cols - len, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(dst->cells + len, cols - len, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); dst->kind = ROW_CELLS; dst->len = (uint16_t)len; dst->flags = (r.out[i].wrapped ? RF_WRAPPED : 0) | RF_TAIL_PADDED; @@ -1530,28 +1530,28 @@ static bool term_resize_internal(struct term *t, int cols, int rows) t->scroll_bottom = rows - 1; t->left_margin = 0; t->right_margin = cols - 1; - term_hist_view_rewrap(&t->view, &t->hist, cols); + wsap_vtcore_hist_view_rewrap(&t->view, &t->hist, cols); t->full_gen++; - term_gstore_unpin(t->gstore); + wsap_vtcore_gstore_unpin(t->gstore); return true; reflow_failed: t->spare = new_scr; - term_gstore_unpin(t->gstore); + wsap_vtcore_gstore_unpin(t->gstore); return false; } -bool term_resize(struct term *t, struct term_vector2i size) +bool wsap_vtcore_resize(struct wsap_vtcore *t, struct wsap_vtcore_vector2i size) { if (!t) return false; int cols = size.x; int rows = size.y; - if (cols < 1 || rows < 1 || cols > TERM_MAX_COLS) + if (cols < 1 || rows < 1 || cols > WSAP_VTCORE_MAX_COLS) return false; - term_write_begin(t); + wsap_vtcore_write_begin(t); if (cols == t->cols && rows == t->rows) { - term_write_end(t); + wsap_vtcore_write_end(t); return true; } @@ -1559,7 +1559,7 @@ bool term_resize(struct term *t, struct term_vector2i size) int new_cap = cols + 64; uint8_t *new_tabs = realloc(t->tabs, (size_t)new_cap); if (!new_tabs) { - term_write_end(t); + wsap_vtcore_write_end(t); return false; } memset(new_tabs + t->tabs_cap, 0, (size_t)(new_cap - t->tabs_cap)); @@ -1579,7 +1579,7 @@ bool term_resize(struct term *t, struct term_vector2i size) int new_cap = cols + 64; struct cell *new_scratch = realloc(t->view_row_scratch, (size_t)new_cap * sizeof(struct cell)); if (!new_scratch) { - term_write_end(t); + wsap_vtcore_write_end(t); return false; } memset(new_scratch + t->view_scratch_cap, 0, (size_t)(new_cap - t->view_scratch_cap) * sizeof(struct cell)); @@ -1587,7 +1587,7 @@ bool term_resize(struct term *t, struct term_vector2i size) t->view_scratch_cap = new_cap; } - bool ok = term_resize_internal(t, cols, rows); - term_write_end(t); + bool ok = wsap_vtcore_resize_internal(t, cols, rows); + wsap_vtcore_write_end(t); return ok; } diff --git a/src/screen.h b/src/screen.h index df464a7..1b5d8eb 100644 --- a/src/screen.h +++ b/src/screen.h @@ -1,5 +1,5 @@ -#ifndef TERM_SCREEN_H -#define TERM_SCREEN_H +#ifndef WSAP_VTCORE_SCREEN_H +#define WSAP_VTCORE_SCREEN_H #include <assert.h> #include "compat.h" @@ -7,38 +7,38 @@ #include "kernels.h" #include "simd.h" -void term_screen_scroll_region(struct term *t, int top, int bottom, int count, bool down, bool history); -void term_screen_set_alternate(struct term *t, bool enabled); -void term_screen_erase(struct term *t, int mode); -void term_screen_erase_all(struct term *t); -void term_screen_erase_line(struct term *t, int mode); -void term_screen_delete_chars(struct term *t, int count); -void term_screen_insert_chars(struct term *t, int count); +void wsap_vtcore_screen_scroll_region(struct wsap_vtcore *t, int top, int bottom, int count, bool down, bool history); +void wsap_vtcore_screen_set_alternate(struct wsap_vtcore *t, bool enabled); +void wsap_vtcore_screen_erase(struct wsap_vtcore *t, int mode); +void wsap_vtcore_screen_erase_all(struct wsap_vtcore *t); +void wsap_vtcore_screen_erase_line(struct wsap_vtcore *t, int mode); +void wsap_vtcore_screen_delete_chars(struct wsap_vtcore *t, int count); +void wsap_vtcore_screen_insert_chars(struct wsap_vtcore *t, int count); -const struct cell *term_screen_view_row(const struct term *t, int y); -uint64_t term_screen_view_row_key(const struct term *t, int y); +const struct cell *wsap_vtcore_screen_view_row(const struct wsap_vtcore *t, int y); +uint64_t wsap_vtcore_screen_view_row_key(const struct wsap_vtcore *t, int y); /* The selected columns [c0, c1] of each view row; c1 < c0 when none. */ /* False when memory runs out; c0 and c1 are then not complete. */ -bool term_selection_view_spans(const struct term *t, int *c0, int *c1); +bool wsap_vtcore_selection_view_spans(const struct wsap_vtcore *t, int *c0, int *c1); -int term_screen_history_rows(const struct term *t); +int wsap_vtcore_screen_history_rows(const struct wsap_vtcore *t); /* Rows of history above the live screen. The view owns the offset. */ -int term_view_offset(const struct term *t); +int wsap_vtcore_view_offset(const struct wsap_vtcore *t); -static inline bool screen_has_history(const struct term *t) +static inline bool screen_has_history(const struct wsap_vtcore *t) { return !t->alternate && t->hist.line_limit > 0; } -static inline int phys_row(const struct term *t, int y) +static inline int phys_row(const struct wsap_vtcore *t, int y) { int p = t->scr.top + y; return p >= t->scr.rows ? p - t->scr.rows : p; } -#if defined(TERM_KERNEL_AVX2) -TERM_TARGET_AVX2 +#if defined(WSAP_VTCORE_KERNEL_AVX2) +WSAP_VTCORE_TARGET_AVX2 static inline void set_cells_wrap_pad_avx2(struct cell *cells, int count) { const __m256i mask = _mm256_setr_epi32(0, 0, 0, (int)CELL_WRAP_PAD, @@ -61,8 +61,8 @@ static inline void set_cells_wrap_pad(struct cell *cells, int count) { if (count <= 0) return; -#if defined(TERM_KERNEL_AVX2) - if (term_use_avx2() && count >= 4) { +#if defined(WSAP_VTCORE_KERNEL_AVX2) + if (wsap_vtcore_use_avx2() && count >= 4) { set_cells_wrap_pad_avx2(cells, count); return; } @@ -115,12 +115,12 @@ static inline void init_ascii_text_row(struct text_row *tr, uint8_t *text, uint1 #endif /* The extra lanes cover unused fill data and run padding. */ #if defined(__x86_64__) || defined(_M_X64) - __m128i pen = _mm_setr_epi32(TERM_COLOR_FG, TERM_COLOR_BG, 0, TERM_COLOR_FG); + __m128i pen = _mm_setr_epi32(WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG, 0, WSAP_VTCORE_COLOR_FG); _mm_storeu_si128((__m128i *)&tr->start, pen); _mm_storeu_si128((__m128i *)&tr->runs.base, pen); _mm_storeu_si128((__m128i *)&tr->runs.pen, pen); #elif defined(__aarch64__) - uint32x4_t pen = { TERM_COLOR_FG, TERM_COLOR_BG, 0, TERM_COLOR_FG }; + uint32x4_t pen = { WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG, 0, WSAP_VTCORE_COLOR_FG }; vst1q_u32((uint32_t *)&tr->start, pen); vst1q_u32((uint32_t *)&tr->runs.base, pen); vst1q_u32((uint32_t *)&tr->runs.pen, pen); @@ -154,7 +154,7 @@ static inline struct srow *screen_row_at(const struct screen *s, int y) return screen_get_row(s, y); } -static inline struct srow *term_row(const struct term *t, int y) +static inline struct srow *wsap_vtcore_row(const struct wsap_vtcore *t, int y) { return screen_get_row(&t->scr, y); } @@ -165,7 +165,7 @@ static inline int text_row_decode(const struct srow *row, struct cell *out, int { srow_materialize_text((struct srow *)row); const struct text_row *tr = &row->text; - int n = term_hist_text_decode(tr, out, cols, NULL); + int n = wsap_vtcore_hist_text_decode(tr, out, cols, NULL); int fill = tr->fill_to < cols ? tr->fill_to : cols; if (n < fill) { fill_cells(out + n, fill - n, tr->fill.fg, tr->fill.bg); @@ -179,7 +179,7 @@ static inline void text_row_cells(const struct srow *row, struct cell *out, int { int n = text_row_decode(row, out, cols); if (n < cols) - fill_cells(out + n, cols - n, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(out + n, cols - n, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); } /* Turn a text row into a cells row. Only the write core does this. Its @@ -190,7 +190,7 @@ static inline void srow_settle(struct srow *row, int cols) if (row->kind == ROW_TEXT) { int n = text_row_decode(row, row->cells, cols); if (n < cols && !(row->flags & RF_TAIL_PADDED)) - fill_cells(row->cells + n, cols - n, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(row->cells + n, cols - n, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); row->flags |= RF_TAIL_PADDED; row->kind = ROW_CELLS; } @@ -203,9 +203,9 @@ static inline void srow_settle(struct srow *row, int cols) * history, so they keep the history format. NULL when neither holds. The * caller has handled a pending wrap, insert mode, and margins. */ -static inline struct srow *text_append_row(struct term *t) +static inline struct srow *text_append_row(struct wsap_vtcore *t) { - struct srow *row = term_row(t, t->cursor_y); + struct srow *row = wsap_vtcore_row(t, t->cursor_y); if (row->kind == ROW_TEXT) { text_row_unshare(&row->text); if (t->cursor_x != row->text.cells) @@ -220,7 +220,7 @@ static inline struct srow *text_append_row(struct term *t) * history can copy its runs. */ struct pen_attr start = pen_attr_default(); if (t->cursor_y > 0) { - const struct srow *prev = term_row(t, t->cursor_y - 1); + const struct srow *prev = wsap_vtcore_row(t, t->cursor_y - 1); if (prev->kind == ROW_TEXT && (prev->flags & RF_WRAPPED)) start = prev->text.runs.pen; } @@ -263,7 +263,7 @@ static inline void text_append(struct srow *row, const uint8_t *bytes, int nbyte text_commit(row, nbytes, chars, cells, hflags, pen); } -static inline struct cell *row_cells(const struct term *t, int p) +static inline struct cell *row_cells(const struct wsap_vtcore *t, int p) { struct srow *row = &t->scr.slot[p]; if (row->kind != ROW_CELLS) @@ -276,14 +276,14 @@ static inline struct cell *row_cells(const struct term *t, int p) * or a resize can never leave a stale id behind. */ /* The logical line of screen row 0, and the row's segment in it. */ -static inline struct line_pos screen_top_line(const struct term *t) +static inline struct line_pos screen_top_line(const struct wsap_vtcore *t) { if (!screen_has_history(t)) return (struct line_pos){ t->scr.top_id, t->scr.top_seg }; uint64_t end = hist_end_id(&t->hist); if (!hist_is_open(&t->hist)) return (struct line_pos){ end, 0 }; - return (struct line_pos){ end - 1, (uint32_t)term_hist_line_rows(&t->hist, end - 1, t->cols) }; + return (struct line_pos){ end - 1, (uint32_t)wsap_vtcore_hist_line_rows(&t->hist, end - 1, t->cols) }; } static inline struct line_pos line_pos_next(struct line_pos p, const struct srow *row) @@ -293,7 +293,7 @@ static inline struct line_pos line_pos_next(struct line_pos p, const struct srow } /* The oldest line that history or the screen still holds. */ -static inline uint64_t first_retained_line(const struct term *t) +static inline uint64_t first_retained_line(const struct wsap_vtcore *t) { if (screen_has_history(t) && t->hist.lines) return hist_first_id(&t->hist); @@ -329,12 +329,12 @@ static inline void repair_wide_row(struct cell *row, int from, int to, int cols, } } -static inline bool using_default_colors(const struct term *t) +static inline bool using_default_colors(const struct wsap_vtcore *t) { - return t->cur_fg == TERM_COLOR_FG && t->cur_bg == TERM_COLOR_BG; + return t->cur_fg == WSAP_VTCORE_COLOR_FG && t->cur_bg == WSAP_VTCORE_COLOR_BG; } -static inline void mark_row_blank(struct term *t, int p) +static inline void mark_row_blank(struct wsap_vtcore *t, int p) { struct srow *row = &t->scr.slot[p]; uint8_t tail_padded = ((row->kind == ROW_CELLS && row->len == 0) || row->kind == ROW_TEXT) @@ -345,11 +345,11 @@ static inline void mark_row_blank(struct term *t, int p) row->version++; } -static inline void term_row_fill_gap(struct srow *row, int x) +static inline void wsap_vtcore_row_fill_gap(struct srow *row, int x) { if (x > row->len) { if (!(row->flags & RF_TAIL_PADDED)) - fill_cells(row->cells + row->len, x - row->len, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(row->cells + row->len, x - row->len, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); row->len = (uint16_t)x; } } @@ -365,12 +365,12 @@ static inline void write_cell_span(struct cell *row, int x, } } -static inline void erase_span(struct term *t, int p, int from, int to) +static inline void erase_span(struct wsap_vtcore *t, int p, int from, int to) { bool pristine = using_default_colors(t); struct srow *row = &t->scr.slot[p]; int len = row->len; - if (to > TERM_MAX_COLS) to = TERM_MAX_COLS; + if (to > WSAP_VTCORE_MAX_COLS) to = WSAP_VTCORE_MAX_COLS; if (pristine && to > len) to = len; if (from >= to) return; @@ -385,7 +385,7 @@ static inline void erase_span(struct term *t, int p, int from, int to) row_set_wrapped(row, false); if (!pristine) { - term_row_fill_gap(row, from); + wsap_vtcore_row_fill_gap(row, from); fill_cells(cells + from, to - from, t->cur_fg, t->cur_bg); if (to > len) { row->len = (uint16_t)to; @@ -409,19 +409,19 @@ static inline void erase_span(struct term *t, int p, int from, int to) } } -static inline int erase_width(const struct term *t, int p) +static inline int erase_width(const struct wsap_vtcore *t, int p) { return t->scr.slot[p].len > t->cols ? t->scr.slot[p].len : t->cols; } -static inline void erase_row(struct term *t, int p) +static inline void erase_row(struct wsap_vtcore *t, int p) { erase_span(t, p, 0, erase_width(t, p)); } -static inline void clamp_selection_after_scroll(struct term *t) +static inline void clamp_selection_after_scroll(struct wsap_vtcore *t) { - if (TERM_EXPECT(!t->selection, 1)) + if (WSAP_VTCORE_EXPECT(!t->selection, 1)) return; uint64_t first_id = first_retained_line(t); if (t->sel_end.line_id < first_id) { @@ -433,7 +433,7 @@ static inline void clamp_selection_after_scroll(struct term *t) } /* Move a row that leaves the top of the normal screen into history. */ -void term_screen_push_row(struct term *t, struct srow *row); +void wsap_vtcore_screen_push_row(struct wsap_vtcore *t, struct srow *row); /* Count a row that leaves the top of a screen without history. */ static inline void screen_drop_top(struct screen *s, const struct srow *row) @@ -445,33 +445,33 @@ static inline void screen_drop_top(struct screen *s, const struct srow *row) /* Clear a row that enters at the bottom. With a colored pen it is a text row * that is all fill: blanks in the pen colors, which text can append over. */ -static inline void screen_new_row(struct term *t, struct srow *row) +static inline void screen_new_row(struct wsap_vtcore *t, struct srow *row) { row->uid = ++t->next_row_uid; row->version++; row->flags = ((row->kind == ROW_CELLS && row->len == 0) || row->kind == ROW_TEXT) ? (row->flags & RF_TAIL_PADDED) : 0; - if (TERM_EXPECT(using_default_colors(t), 1)) { + if (WSAP_VTCORE_EXPECT(using_default_colors(t), 1)) { row->kind = ROW_CELLS; row->len = 0; } else { row->kind = ROW_TEXT; - text_row_start(&row->text, &(struct pen_attr){ .fg = TERM_COLOR_FG, .bg = TERM_COLOR_BG }); + text_row_start(&row->text, &(struct pen_attr){ .fg = WSAP_VTCORE_COLOR_FG, .bg = WSAP_VTCORE_COLOR_BG }); row->text.fill_to = (uint16_t)t->scr.cols; row->text.fill = (struct pen_attr){ .fg = t->cur_fg, .bg = t->cur_bg }; row->len = (uint16_t)t->scr.cols; } } -static inline void term_screen_scroll_up(struct term *t) +static inline void wsap_vtcore_screen_scroll_up(struct wsap_vtcore *t) { struct screen *s = &t->scr; struct srow *row = &s->slot[s->top]; - if (TERM_EXPECT(screen_has_history(t), 1)) - term_screen_push_row(t, row); + if (WSAP_VTCORE_EXPECT(screen_has_history(t), 1)) + wsap_vtcore_screen_push_row(t, row); else screen_drop_top(s, row); - if (TERM_EXPECT(t->prompt_y > 0, 0) && !t->alternate) + if (WSAP_VTCORE_EXPECT(t->prompt_y > 0, 0) && !t->alternate) t->prompt_y--; s->top = s->top + 1 == s->rows ? 0 : s->top + 1; clamp_selection_after_scroll(t); diff --git a/src/selection.c b/src/selection.c index 1d931c9..f2dbd1a 100644 --- a/src/selection.c +++ b/src/selection.c @@ -5,13 +5,13 @@ #include <stdlib.h> #include <string.h> -static char *link_at_text(const struct term *t, struct term_vector2i cell) +static char *link_at_text(const struct wsap_vtcore *t, struct wsap_vtcore_vector2i cell) { int col = cell.x, row = cell.y; if (!t || col < 0 || col >= t->cols || row < 0 || row >= t->rows) return NULL; - const char *link = term_osc8_url_at(t, col, row); - if (link) return term_strdup(link); - const struct cell *cells = term_screen_view_row(t, row); + const char *link = wsap_vtcore_osc8_url_at(t, col, row); + if (link) return wsap_vtcore_strdup(link); + const struct cell *cells = wsap_vtcore_screen_view_row(t, row); if (!cells) return NULL; int start = col, end = col; while (start > 0 && cells[start - 1].c > ' ' && cells[start - 1].c < 127) start--; @@ -48,27 +48,27 @@ static char *link_at_text(const struct term *t, struct term_vector2i cell) while (n && (mask[(unsigned char)url[n - 1] >> 6] & (1ULL << ((unsigned char)url[n - 1] & 63)))) url[--n] = 0; if (col < start + (int)(url - text) + (int)n && n > scheme) - out = term_strdup(url); + out = wsap_vtcore_strdup(url); } free(text); return out; } -char *term_link_at(const struct term *t, struct term_vector2i cell) +char *wsap_vtcore_link_at(const struct wsap_vtcore *t, struct wsap_vtcore_vector2i cell) { if (!t) return NULL; - term_write_begin((struct term *)t); + wsap_vtcore_write_begin((struct wsap_vtcore *)t); char *text = link_at_text(t, cell); - term_write_end((struct term *)t); + wsap_vtcore_write_end((struct wsap_vtcore *)t); return text; } -void term_select_clear(struct term *t) +void wsap_vtcore_select_clear(struct wsap_vtcore *t) { if (t) { - term_write_begin(t); + wsap_vtcore_write_begin(t); t->selection = false; - term_write_end(t); + wsap_vtcore_write_end(t); } } @@ -85,7 +85,7 @@ static inline int word_class(uint32_t c) return 1; } -static inline int sel_point_cmp(struct term_sel_point a, struct term_sel_point b) +static inline int sel_point_cmp(struct wsap_vtcore_sel_point a, struct wsap_vtcore_sel_point b) { if (a.line_id < b.line_id) return -1; if (a.line_id > b.line_id) return 1; @@ -100,7 +100,7 @@ static inline int sel_point_cmp(struct term_sel_point a, struct term_sel_point b * gives the line and segment of each screen row. */ struct lines { - const struct term *t; + const struct wsap_vtcore *t; int cols; bool hist; uint64_t hist_end; @@ -111,7 +111,7 @@ struct lines { /* False when a screen taller than the stack array needs memory and none is * left. L can still be passed to lines_free(). */ -static bool lines_init(struct lines *L, const struct term *t) +static bool lines_init(struct lines *L, const struct wsap_vtcore *t) { L->t = t; L->cols = t->cols; @@ -154,7 +154,7 @@ static inline bool is_open_line(const struct lines *L, uint64_t id) static inline int hist_segs(const struct lines *L, uint64_t id) { - return in_hist(L, id) ? term_hist_line_rows(&L->t->hist, id, L->cols) : 0; + return in_hist(L, id) ? wsap_vtcore_hist_line_rows(&L->t->hist, id, L->cols) : 0; } static int screen_row_of(const struct lines *L, uint64_t id, int seg) @@ -181,14 +181,14 @@ static int line_total_segs(const struct lines *L, uint64_t id) static const struct cell *line_seg_cells(const struct lines *L, uint64_t id, int seg, struct cell *scratch, bool *out_wrapped) { - const struct term *t = L->t; + const struct wsap_vtcore *t = L->t; struct cell *buf = scratch ? scratch : t->view_row_scratch; int hrows = hist_segs(L, id); if (seg < hrows) { - int got = term_hist_decode_segment(&t->hist, id, seg, L->cols, buf, t->gstore); + int got = wsap_vtcore_hist_decode_segment(&t->hist, id, seg, L->cols, buf, t->gstore); bool wrapped = seg + 1 < hrows || is_open_line(L, id); if (got < L->cols) { - fill_cells(buf + got, L->cols - got, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(buf + got, L->cols - got, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); if (wrapped) set_cells_wrap_pad(buf + got, L->cols - got); } @@ -207,7 +207,7 @@ static const struct cell *line_seg_cells(const struct lines *L, uint64_t id, int return srow->cells; if (srow->len > 0) memcpy(buf, srow->cells, (size_t)srow->len * sizeof(struct cell)); - fill_cells(buf + srow->len, L->cols - srow->len, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(buf + srow->len, L->cols - srow->len, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); return buf; } text_row_cells(srow, buf, L->cols); @@ -217,12 +217,12 @@ static const struct cell *line_seg_cells(const struct lines *L, uint64_t id, int /* A line whose segments may not hold exactly cols cells each. */ static bool line_has_wide(const struct lines *L, uint64_t id) { - const struct term *t = L->t; + const struct wsap_vtcore *t = L->t; if (in_hist(L, id)) { - if (term_hist_line_flags(&t->hist, id) & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER)) + if (wsap_vtcore_hist_line_flags(&t->hist, id) & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER)) return true; if (is_open_line(L, id) && - term_hist_line_cells(&t->hist, id) != (uint64_t)hist_segs(L, id) * (uint64_t)L->cols) + wsap_vtcore_hist_line_cells(&t->hist, id) != (uint64_t)hist_segs(L, id) * (uint64_t)L->cols) return true; } int rows = lines_rows(L); @@ -254,19 +254,19 @@ static uint32_t line_seg_start_off(const struct lines *L, uint64_t id, int seg) if (!line_has_wide(L, id)) return (uint32_t)seg * (uint32_t)L->cols; - const struct term *t = L->t; + const struct wsap_vtcore *t = L->t; int hrows = hist_segs(L, id); if (in_hist(L, id)) { if (seg <= hrows) { uint64_t base = id == t->hist.base_cell_id ? t->hist.base_cell : 0; - return (uint32_t)(term_hist_segment_cell(&t->hist, id, seg, L->cols) - base); + return (uint32_t)(wsap_vtcore_hist_segment_cell(&t->hist, id, seg, L->cols) - base); } } uint32_t off = 0; if (in_hist(L, id) && hrows > 0) { uint64_t base = id == t->hist.base_cell_id ? t->hist.base_cell : 0; - off = (uint32_t)(term_hist_segment_cell(&t->hist, id, hrows, L->cols) - base); + off = (uint32_t)(wsap_vtcore_hist_segment_cell(&t->hist, id, hrows, L->cols) - base); } struct cell stack_buf[512]; struct cell *scratch = L->cols <= 512 ? stack_buf : malloc((size_t)L->cols * sizeof(*scratch)); @@ -283,9 +283,9 @@ static uint32_t line_seg_start_off(const struct lines *L, uint64_t id, int seg) /* The line and segment of view row y. */ static bool view_row_line(const struct lines *L, int y, uint64_t *id, int *seg) { - const struct term *t = L->t; + const struct wsap_vtcore *t = L->t; struct hist_view_pos pos; - if (term_hist_view_row_pos(&t->view, &t->hist, L->cols, t->rows, screen_top_line(t), y, &pos)) { + if (wsap_vtcore_hist_view_row_pos(&t->view, &t->hist, L->cols, t->rows, screen_top_line(t), y, &pos)) { *id = pos.id; *seg = pos.seg; return true; @@ -297,9 +297,9 @@ static bool view_row_line(const struct lines *L, int y, uint64_t *id, int *seg) return true; } -static struct term_sel_point view_to_sel_point(const struct lines *L, int x, int y) +static struct wsap_vtcore_sel_point view_to_sel_point(const struct lines *L, int x, int y) { - const struct term *t = L->t; + const struct wsap_vtcore *t = L->t; if (x < 0) x = 0; if (x >= L->cols) x = L->cols - 1; if (y < 0) y = 0; @@ -308,11 +308,11 @@ static struct term_sel_point view_to_sel_point(const struct lines *L, int x, int uint64_t id; int seg; if (!view_row_line(L, y, &id, &seg)) - return (struct term_sel_point){ .line_id = L->first }; + return (struct wsap_vtcore_sel_point){ .line_id = L->first }; const struct cell *cells = line_seg_cells(L, id, seg, NULL, NULL); if (cells && x > 0 && (cells[x].flags & CELL_WRAP_PAD)) x--; - return (struct term_sel_point){ + return (struct wsap_vtcore_sel_point){ .line_id = id, .cell_off = line_seg_start_off(L, id, seg) + (uint32_t)x, }; @@ -328,7 +328,7 @@ static uint32_t line_total_display_cols(const struct lines *L, uint64_t id, int return start + (uint32_t)seg_display_cols(L->cols, cells, wrapped); } -static struct term_sel_point sel_point_next(const struct lines *L, struct term_sel_point pt) +static struct wsap_vtcore_sel_point sel_point_next(const struct lines *L, struct wsap_vtcore_sel_point pt) { int nsegs = line_total_segs(L, pt.line_id); if (nsegs <= 0) @@ -341,12 +341,12 @@ static struct term_sel_point sel_point_next(const struct lines *L, struct term_s uint64_t max_id = L->pos[lines_rows(L) - 1].id; for (uint64_t next = pt.line_id + 1; next <= max_id; next++) if (line_total_segs(L, next) > 0) - return (struct term_sel_point){ .line_id = next }; + return (struct wsap_vtcore_sel_point){ .line_id = next }; pt.cell_off++; return pt; } -static struct term_sel_point sel_point_prev(const struct lines *L, struct term_sel_point pt) +static struct wsap_vtcore_sel_point sel_point_prev(const struct lines *L, struct wsap_vtcore_sel_point pt) { if (pt.cell_off > 0) { pt.cell_off--; @@ -357,36 +357,36 @@ static struct term_sel_point sel_point_prev(const struct lines *L, struct term_s if (nsegs <= 0) continue; uint32_t cols = line_total_display_cols(L, prev, nsegs); - return (struct term_sel_point){ .line_id = prev, .cell_off = cols > 0 ? cols - 1 : 0 }; + return (struct wsap_vtcore_sel_point){ .line_id = prev, .cell_off = cols > 0 ? cols - 1 : 0 }; } return pt; } static void unit_span(const struct lines *L, int x, int y, bool right_half, - enum term_select_unit unit, - struct term_sel_point *first, struct term_sel_point *last) + enum wsap_vtcore_select_unit unit, + struct wsap_vtcore_sel_point *first, struct wsap_vtcore_sel_point *last) { - const struct term *t = L->t; + const struct wsap_vtcore *t = L->t; int cols = L->cols; if (x < 0) x = 0; if (x >= cols) x = cols - 1; if (y < 0) y = 0; if (y >= t->rows) y = t->rows - 1; - if (unit == TERM_SELECT_CELL) { - struct term_sel_point pt = view_to_sel_point(L, x, y); + if (unit == WSAP_VTCORE_SELECT_CELL) { + struct wsap_vtcore_sel_point pt = view_to_sel_point(L, x, y); if (right_half) pt = sel_point_next(L, pt); *first = *last = pt; return; } - if (unit == TERM_SELECT_LINE) { + if (unit == WSAP_VTCORE_SELECT_LINE) { *first = view_to_sel_point(L, 0, y); *last = sel_point_next(L, view_to_sel_point(L, cols - 1, y)); return; } - const struct cell *row = term_screen_view_row(t, y); + const struct cell *row = wsap_vtcore_screen_view_row(t, y); if (row && x > 0 && (row[x].flags & CELL_WRAP_PAD)) x--; int left = x, right = x; @@ -401,16 +401,16 @@ static void unit_span(const struct lines *L, int x, int y, bool right_half, } /* Clamp the selection to the retained lines. A read does not change it. */ -static bool selection_bounds(const struct lines *L, struct term_sel_point *start, - struct term_sel_point *end) +static bool selection_bounds(const struct lines *L, struct wsap_vtcore_sel_point *start, + struct wsap_vtcore_sel_point *end) { - const struct term *t = L->t; + const struct wsap_vtcore *t = L->t; if (!t->selection || t->sel_end.line_id < L->first) return false; *start = t->sel_start; *end = t->sel_end; if (start->line_id < L->first) - *start = (struct term_sel_point){ .line_id = L->first }; + *start = (struct wsap_vtcore_sel_point){ .line_id = L->first }; return sel_point_cmp(*start, *end) <= 0; } @@ -447,7 +447,7 @@ static bool line_locate_cell(const struct lines *L, uint64_t id, uint32_t cell_o } } else { uint64_t base = id == L->t->hist.base_cell_id ? L->t->hist.base_cell : 0; - int seg = term_hist_cell_segment(&L->t->hist, id, base + (uint64_t)cell_off, L->cols); + int seg = wsap_vtcore_hist_cell_segment(&L->t->hist, id, base + (uint64_t)cell_off, L->cols); if (seg < hrows) { uint32_t seg_start = line_seg_start_off(L, id, seg); if (cell_off >= seg_start) { @@ -479,8 +479,8 @@ static bool line_locate_cell(const struct lines *L, uint64_t id, uint32_t cell_o return false; } -static void select_range(struct term *t, const struct lines *L, - struct term_sel_point start, struct term_sel_point end) +static void select_range(struct wsap_vtcore *t, const struct lines *L, + struct wsap_vtcore_sel_point start, struct wsap_vtcore_sel_point end) { if (sel_point_cmp(start, end) > 0) { t->selection = false; @@ -502,49 +502,49 @@ static void select_range(struct term *t, const struct lines *L, t->selection = true; } -bool term_select_start(struct term *t, struct term_vector2i cell, bool right_half, - enum term_select_unit unit) +bool wsap_vtcore_select_start(struct wsap_vtcore *t, struct wsap_vtcore_vector2i cell, bool right_half, + enum wsap_vtcore_select_unit unit) { if (!t) return false; - term_write_begin(t); + wsap_vtcore_write_begin(t); struct lines L; if (!lines_init(&L, t)) { lines_free(&L); - term_write_end(t); + wsap_vtcore_write_end(t); return false; } - struct term_sel_point first, last; + struct wsap_vtcore_sel_point first, last; unit_span(&L, cell.x, cell.y, right_half, unit, &first, &last); lines_free(&L); - enum term_select_unit old_unit = t->select_unit; - struct term_sel_point old_first = t->sel_anchor_first, old_last = t->sel_anchor_last; + enum wsap_vtcore_select_unit old_unit = t->select_unit; + struct wsap_vtcore_sel_point old_first = t->sel_anchor_first, old_last = t->sel_anchor_last; bool old_selection = t->selection; t->select_unit = unit; t->sel_anchor_first = first; t->sel_anchor_last = last; t->selection = false; - bool ok = term_select_extend(t, cell, right_half); + bool ok = wsap_vtcore_select_extend(t, cell, right_half); if (!ok) { t->select_unit = old_unit; t->sel_anchor_first = old_first; t->sel_anchor_last = old_last; t->selection = old_selection; } - term_write_end(t); + wsap_vtcore_write_end(t); return ok; } -bool term_select_extend(struct term *t, struct term_vector2i cell, bool right_half) +bool wsap_vtcore_select_extend(struct wsap_vtcore *t, struct wsap_vtcore_vector2i cell, bool right_half) { if (!t) return false; - term_write_begin(t); + wsap_vtcore_write_begin(t); struct lines L; if (!lines_init(&L, t)) { lines_free(&L); - term_write_end(t); + wsap_vtcore_write_end(t); return false; } - struct term_sel_point first, last; + struct wsap_vtcore_sel_point first, last; unit_span(&L, cell.x, cell.y, right_half, t->select_unit, &first, &last); if (sel_point_cmp(first, t->sel_anchor_first) > 0) first = t->sel_anchor_first; if (sel_point_cmp(last, t->sel_anchor_last) < 0) last = t->sel_anchor_last; @@ -553,21 +553,21 @@ bool term_select_extend(struct term *t, struct term_vector2i cell, bool right_ha else select_range(t, &L, first, sel_point_prev(&L, last)); lines_free(&L); - term_write_end(t); + wsap_vtcore_write_end(t); return true; } -bool term_has_selection(const struct term *t) +bool wsap_vtcore_has_selection(const struct wsap_vtcore *t) { if (!t) return false; - term_write_begin((struct term *)t); + wsap_vtcore_write_begin((struct wsap_vtcore *)t); bool has = t->selection && t->sel_end.line_id >= first_retained_line(t); - term_write_end((struct term *)t); + wsap_vtcore_write_end((struct wsap_vtcore *)t); return has; } -bool term_selection_view_spans(const struct term *t, int *c0, int *c1) +bool wsap_vtcore_selection_view_spans(const struct wsap_vtcore *t, int *c0, int *c1) { int rows = t->rows, cols = t->cols; for (int y = 0; y < rows; y++) { @@ -581,7 +581,7 @@ bool term_selection_view_spans(const struct term *t, int *c0, int *c1) lines_free(&L); return false; } - struct term_sel_point start, end; + struct wsap_vtcore_sel_point start, end; if (!selection_bounds(&L, &start, &end)) { lines_free(&L); return true; @@ -644,8 +644,8 @@ static bool text_reserve(char **text, size_t *cap, size_t need) return true; } -static char *range_text_inner(const struct term *t, - const struct term_sel_point *bounds) +static char *range_text_inner(const struct wsap_vtcore *t, + const struct wsap_vtcore_sel_point *bounds) { if (!t || (!bounds && !t->selection)) return NULL; struct lines L; @@ -653,7 +653,7 @@ static char *range_text_inner(const struct term *t, lines_free(&L); return NULL; } - struct term_sel_point start, end; + struct wsap_vtcore_sel_point start, end; if (bounds) { start = bounds[0]; end = bounds[1]; @@ -697,7 +697,7 @@ static char *range_text_inner(const struct term *t, take = end_seg - seg + 1; if (!batch_cells) batch_cells = malloc((size_t)BATCH_SEGS * (size_t)t->cols * sizeof(struct cell)); - batch_len = batch_cells ? term_hist_decode_segments(&t->hist, id, batch_start, take, + batch_len = batch_cells ? wsap_vtcore_hist_decode_segments(&t->hist, id, batch_start, take, t->cols, batch_cells, batch_lens, t->gstore) : 0; } @@ -707,7 +707,7 @@ static char *range_text_inner(const struct term *t, int got = batch_lens[idx]; row_wrapped = seg + 1 < hrows || is_open_line(&L, id); if (got < t->cols) { - fill_cells(row_buf + got, t->cols - got, TERM_COLOR_FG, TERM_COLOR_BG); + fill_cells(row_buf + got, t->cols - got, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG); if (row_wrapped) set_cells_wrap_pad(row_buf + got, t->cols - got); } @@ -775,17 +775,17 @@ static char *range_text_inner(const struct term *t, uint32_t cp = cells[c].c; if (cells[c].flags & (CELL_TRAIL | CELL_WRAP_PAD)) continue; - /* One cell expands to TERM_GRAPHEME_MAX_LEN code points of up + /* One cell expands to WSAP_VTCORE_GRAPHEME_MAX_LEN code points of up * to 4 bytes each. Leave room for all of them. */ - if (!text_reserve(&text, &cap, n + (size_t)TERM_GRAPHEME_MAX_LEN * 4 + 1)) + if (!text_reserve(&text, &cap, n + (size_t)WSAP_VTCORE_GRAPHEME_MAX_LEN * 4 + 1)) break; if (cp > 0 && cp < 128) { text[n++] = (char)cp; } else { - uint32_t cps[TERM_GRAPHEME_MAX_LEN]; - int len = term_gstore_expand(t->gstore, cp ? cp : ' ', cps, TERM_GRAPHEME_MAX_LEN); + uint32_t cps[WSAP_VTCORE_GRAPHEME_MAX_LEN]; + int len = wsap_vtcore_gstore_expand(t->gstore, cp ? cp : ' ', cps, WSAP_VTCORE_GRAPHEME_MAX_LEN); for (int k = 0; k < len; k++) - n += (size_t)term_utf8_encode(cps[k], text + n); + n += (size_t)wsap_vtcore_utf8_encode(cps[k], text + n); } } if (text && !is_last && !wrapped && text_reserve(&text, &cap, n + 2)) @@ -799,34 +799,34 @@ static char *range_text_inner(const struct term *t, return text; } -char *term_history_text(struct term *t, int max_rows) +char *wsap_vtcore_history_text(struct wsap_vtcore *t, int max_rows) { if (!t) return NULL; - term_write_begin(t); - term_hist_prepare_rows(&t->hist, t->cols); - if (!term_hist_view_sync(&t->view, &t->hist, t->cols)) { - term_write_end(t); + wsap_vtcore_write_begin(t); + wsap_vtcore_hist_prepare_rows(&t->hist, t->cols); + if (!wsap_vtcore_hist_view_sync(&t->view, &t->hist, t->cols)) { + wsap_vtcore_write_end(t); return NULL; } - int end_row = term_screen_history_rows(t) - term_view_offset(t); + int end_row = wsap_vtcore_screen_history_rows(t) - wsap_vtcore_view_offset(t); if (max_rows <= 0 || end_row <= 0) { - term_write_end(t); - return term_strdup(""); + wsap_vtcore_write_end(t); + return wsap_vtcore_strdup(""); } int begin_row = end_row > max_rows ? end_row - max_rows : 0; struct lines L; if (!lines_init(&L, t)) { lines_free(&L); - term_write_end(t); + wsap_vtcore_write_end(t); return NULL; } - struct term_sel_point bounds[2] = {0}; + struct wsap_vtcore_sel_point bounds[2] = {0}; int first_seg, last_seg; char *text = NULL; - if (term_hist_view_find_row(&t->view, &t->hist, begin_row, t->cols, + if (wsap_vtcore_hist_view_find_row(&t->view, &t->hist, begin_row, t->cols, &bounds[0].line_id, &first_seg) && - term_hist_view_find_row(&t->view, &t->hist, end_row - 1, t->cols, + wsap_vtcore_hist_view_find_row(&t->view, &t->hist, end_row - 1, t->cols, &bounds[1].line_id, &last_seg)) { bounds[0].cell_off = line_seg_start_off(&L, bounds[0].line_id, first_seg); uint32_t last_start = line_seg_start_off(&L, bounds[1].line_id, last_seg); @@ -846,15 +846,15 @@ char *term_history_text(struct term *t, int max_rows) } } lines_free(&L); - term_write_end(t); + wsap_vtcore_write_end(t); return text; } -char *term_selection_text(const struct term *t) +char *wsap_vtcore_selection_text(const struct wsap_vtcore *t) { if (!t) return NULL; - term_write_begin((struct term *)t); + wsap_vtcore_write_begin((struct wsap_vtcore *)t); char *text = range_text_inner(t, NULL); - term_write_end((struct term *)t); + wsap_vtcore_write_end((struct wsap_vtcore *)t); return text; } @@ -1,5 +1,5 @@ -#ifndef TERM_SIMD_H -#define TERM_SIMD_H +#ifndef WSAP_VTCORE_SIMD_H +#define WSAP_VTCORE_SIMD_H #include "compat.h" @@ -18,91 +18,91 @@ /* * x86-64 kernels come in three levels: base (SSE2), AVX2 (x86-64-v3), and * AVX-512 (x86-64-v4 with VBMI and VBMI2). GCC and Clang compile every - * level with target attributes, and term_isa_init() picks one at run time. + * level with target attributes, and wsap_vtcore_isa_init() picks one at run time. * Other compilers compile the levels that their flags enable. * - * A kernel at a level is a function marked TERM_TARGET_AVX2 or - * TERM_TARGET_AVX512. It exists when TERM_KERNEL_AVX2 or TERM_KERNEL_AVX512 - * is defined. Call it only when term_use_avx2() or term_use_avx512() is + * A kernel at a level is a function marked WSAP_VTCORE_TARGET_AVX2 or + * WSAP_VTCORE_TARGET_AVX512. It exists when WSAP_VTCORE_KERNEL_AVX2 or WSAP_VTCORE_KERNEL_AVX512 + * is defined. Call it only when wsap_vtcore_use_avx2() or wsap_vtcore_use_avx512() is * true. When the compiler flags already enable a level, these checks are * constants and the kernels inline into their callers. */ #if defined(__AVX512F__) && defined(__AVX512BW__) && defined(__AVX512CD__) && \ defined(__AVX512DQ__) && defined(__AVX512VL__) && defined(__AVX512VBMI__) && \ defined(__AVX512VBMI2__) && defined(__AVX2__) && defined(__BMI2__) -#define TERM_ISA_FLOOR 2 +#define WSAP_VTCORE_ISA_FLOOR 2 #elif defined(__AVX2__) && defined(__BMI__) && defined(__BMI2__) && defined(__FMA__) && \ defined(__LZCNT__) -#define TERM_ISA_FLOOR 1 +#define WSAP_VTCORE_ISA_FLOOR 1 #else -#define TERM_ISA_FLOOR 0 +#define WSAP_VTCORE_ISA_FLOOR 0 #endif /* Clang 18 to 21 also need evex512 for 512-bit vectors. GCC and Clang 22 * reject the name. Apple Clang 17 is LLVM 19. */ #if defined(__clang__) && ((defined(__apple_build_version__) && __clang_major__ >= 17) || \ (!defined(__apple_build_version__) && __clang_major__ >= 18 && __clang_major__ <= 21)) -#define TERM_EVEX512 ",evex512" +#define WSAP_VTCORE_EVEX512 ",evex512" #else -#define TERM_EVEX512 "" +#define WSAP_VTCORE_EVEX512 "" #endif -#if (defined(__x86_64__) || defined(_M_X64)) && defined(TERM_COMPILER_GNU) -#define TERM_TARGET_AVX2 \ +#if (defined(__x86_64__) || defined(_M_X64)) && defined(WSAP_VTCORE_COMPILER_GNU) +#define WSAP_VTCORE_TARGET_AVX2 \ __attribute__((target("avx2,bmi,bmi2,fma,lzcnt,popcnt,movbe,f16c"))) -#define TERM_TARGET_AVX512 \ +#define WSAP_VTCORE_TARGET_AVX512 \ __attribute__((target("avx2,bmi,bmi2,fma,lzcnt,popcnt,movbe,f16c,avx512f,avx512bw," \ - "avx512cd,avx512dq,avx512vl,avx512vbmi,avx512vbmi2" TERM_EVEX512))) -#define TERM_KERNEL_AVX2 1 -#define TERM_KERNEL_AVX512 1 -#define TERM_ISA_RUNTIME 1 + "avx512cd,avx512dq,avx512vl,avx512vbmi,avx512vbmi2" WSAP_VTCORE_EVEX512))) +#define WSAP_VTCORE_KERNEL_AVX2 1 +#define WSAP_VTCORE_KERNEL_AVX512 1 +#define WSAP_VTCORE_ISA_RUNTIME 1 #else -#define TERM_TARGET_AVX2 -#define TERM_TARGET_AVX512 -#if TERM_ISA_FLOOR >= 1 -#define TERM_KERNEL_AVX2 1 +#define WSAP_VTCORE_TARGET_AVX2 +#define WSAP_VTCORE_TARGET_AVX512 +#if WSAP_VTCORE_ISA_FLOOR >= 1 +#define WSAP_VTCORE_KERNEL_AVX2 1 #endif -#if TERM_ISA_FLOOR >= 2 -#define TERM_KERNEL_AVX512 1 +#if WSAP_VTCORE_ISA_FLOOR >= 2 +#define WSAP_VTCORE_KERNEL_AVX512 1 #endif #endif -enum { TERM_ISA_BASE, TERM_ISA_AVX2, TERM_ISA_AVX512 }; +enum { WSAP_VTCORE_ISA_BASE, WSAP_VTCORE_ISA_AVX2, WSAP_VTCORE_ISA_AVX512 }; -/* The level in use. Zero, the base level, until term_isa_init() runs. It +/* The level in use. Zero, the base level, until wsap_vtcore_isa_init() runs. It * is a plain int, so the compiler can hoist the checks out of loops: it is * written once, before the release that publishes it, and read only after * that. */ -extern int term_isa_level; +extern int wsap_vtcore_isa_level; -/* Pick the level once. Any thread can call it. term_new() calls it before +/* Pick the level once. Any thread can call it. wsap_vtcore_new() calls it before * the first terminal exists. */ -void term_isa_init(void); +void wsap_vtcore_isa_init(void); -static inline bool term_use_avx2(void) +static inline bool wsap_vtcore_use_avx2(void) { -#if TERM_ISA_FLOOR >= 1 +#if WSAP_VTCORE_ISA_FLOOR >= 1 return true; -#elif defined(TERM_ISA_RUNTIME) - return term_isa_level >= TERM_ISA_AVX2; +#elif defined(WSAP_VTCORE_ISA_RUNTIME) + return wsap_vtcore_isa_level >= WSAP_VTCORE_ISA_AVX2; #else return false; #endif } -static inline bool term_use_avx512(void) +static inline bool wsap_vtcore_use_avx512(void) { -#if TERM_ISA_FLOOR >= 2 +#if WSAP_VTCORE_ISA_FLOOR >= 2 return true; -#elif defined(TERM_ISA_RUNTIME) - return term_isa_level >= TERM_ISA_AVX512; +#elif defined(WSAP_VTCORE_ISA_RUNTIME) + return wsap_vtcore_isa_level >= WSAP_VTCORE_ISA_AVX512; #else return false; #endif } #if defined(__aarch64__) -static inline uint16_t term_lane_bits(uint8x16_t m) +static inline uint16_t wsap_vtcore_lane_bits(uint8x16_t m) { const uint8x16_t idx = {1, 2, 4, 8, 16, 32, 64, 128, 1, 2, 4, 8, 16, 32, 64, 128}; diff --git a/src/snapshot.c b/src/snapshot.c index 6f396e2..f7e906c 100644 --- a/src/snapshot.c +++ b/src/snapshot.c @@ -10,16 +10,16 @@ * Cluster cells refer to an arena of [length, code points...] records that * the snapshot owns, so a renderer never reads the terminal's cluster table. */ -struct term_snapshot { - struct term_view view; - uint32_t palette[TERM_PALETTE_SIZE]; +struct wsap_vtcore_snapshot { + struct wsap_vtcore_view view; + uint32_t palette[WSAP_VTCORE_PALETTE_SIZE]; uint64_t source; /* serial of the terminal it copied */ - struct term_cell *cells; /* rows * cols */ - struct term_cell *stage; /* rows * cols: changed rows, before apply() */ + struct wsap_vtcore_cell *cells; /* rows * cols */ + struct wsap_vtcore_cell *stage; /* rows * cols: changed rows, before apply() */ uint64_t *keys; /* per row */ uint32_t *row_clusters; /* arena records each row holds */ - struct term_span *selection; /* per row */ + struct wsap_vtcore_span *selection; /* per row */ size_t cell_cap; int row_cap; @@ -30,15 +30,15 @@ struct term_snapshot { uint32_t spare_cap; }; -struct term_snapshot *term_snapshot_new(void) +struct wsap_vtcore_snapshot *wsap_vtcore_snapshot_new(void) { - struct term_snapshot *s = calloc(1, sizeof(*s)); + struct wsap_vtcore_snapshot *s = calloc(1, sizeof(*s)); if (s) s->view.palette = s->palette; return s; } -void term_snapshot_free(struct term_snapshot *s) +void wsap_vtcore_snapshot_free(struct wsap_vtcore_snapshot *s) { if (!s) return; @@ -54,15 +54,15 @@ void term_snapshot_free(struct term_snapshot *s) /* Make room for cols x rows. A failed call keeps the old contents, so the * snapshot stays readable. */ -static bool reserve(struct term_snapshot *s, int cols, int rows) +static bool reserve(struct wsap_vtcore_snapshot *s, int cols, int rows) { size_t cells = (size_t)cols * (size_t)rows; if (cells > s->cell_cap) { - struct term_cell *c = realloc(s->cells, cells * sizeof(*c)); + struct wsap_vtcore_cell *c = realloc(s->cells, cells * sizeof(*c)); if (!c) return false; s->cells = c; - struct term_cell *st = realloc(s->stage, cells * sizeof(*st)); + struct wsap_vtcore_cell *st = realloc(s->stage, cells * sizeof(*st)); if (!st) return false; s->stage = st; @@ -75,7 +75,7 @@ static bool reserve(struct term_snapshot *s, int cols, int rows) uint32_t *rc = realloc(s->row_clusters, (size_t)rows * sizeof(*rc)); if (rc) s->row_clusters = rc; - struct term_span *sel = realloc(s->selection, (size_t)rows * sizeof(*sel)); + struct wsap_vtcore_span *sel = realloc(s->selection, (size_t)rows * sizeof(*sel)); if (sel) s->selection = sel; if (!k || !rc || !sel) @@ -95,14 +95,14 @@ struct arena_out { }; /* Make room for need words. False when memory runs out or an offset would not - * fit below TERM_TEXT_CLUSTER. */ + * fit below WSAP_VTCORE_TEXT_CLUSTER. */ static bool arena_reserve(struct arena_out *a, uint64_t need) { - if (need > TERM_TEXT_CLUSTER) + if (need > WSAP_VTCORE_TEXT_CLUSTER) return false; if (need <= *a->cap) return true; - uint32_t cap = term_grow_cap32(*a->cap ? *a->cap * 2 : 256, (uint32_t)need); + uint32_t cap = wsap_vtcore_grow_cap32(*a->cap ? *a->cap * 2 : 256, (uint32_t)need); uint32_t *grown = realloc(*a->buf, cap * sizeof(*grown)); if (!grown) return false; @@ -116,8 +116,8 @@ static bool arena_reserve(struct arena_out *a, uint64_t need) static bool arena_add(struct arena_out *a, const struct gstore *g, uint32_t handle, uint32_t *text) { - uint32_t cps[TERM_GRAPHEME_MAX_LEN]; - int n = term_gstore_expand(g, handle, cps, TERM_GRAPHEME_MAX_LEN); + uint32_t cps[WSAP_VTCORE_GRAPHEME_MAX_LEN]; + int n = wsap_vtcore_gstore_expand(g, handle, cps, WSAP_VTCORE_GRAPHEME_MAX_LEN); if (n <= 0) { *text = ' '; return true; @@ -129,24 +129,24 @@ static bool arena_add(struct arena_out *a, const struct gstore *g, uint32_t hand (*a->buf)[off] = (uint32_t)n; memcpy(&(*a->buf)[off + 1], cps, (size_t)n * sizeof(*cps)); a->len = (uint32_t)need; - *text = TERM_TEXT_CLUSTER | off; + *text = WSAP_VTCORE_TEXT_CLUSTER | off; return true; } /* Convert one stored row into dst. False when a cluster record does not fit. */ static bool convert_row(struct arena_out *a, const struct gstore *g, - struct term_cell *dst, const struct cell *src, int cols) + struct wsap_vtcore_cell *dst, const struct cell *src, int cols) { for (int x = 0; x < cols; x++) { const struct cell *c = &src[x]; uint16_t f = c->flags; uint32_t text = c->c; - if (TERM_EXPECT(text < 0x20, 0)) + if (WSAP_VTCORE_EXPECT(text < 0x20, 0)) text = text ? ' ' : 0; - else if (TERM_EXPECT(term_grapheme_is_handle(text), 0) && + else if (WSAP_VTCORE_EXPECT(wsap_vtcore_grapheme_is_handle(text), 0) && !arena_add(a, g, text, &text)) return false; - dst[x] = (struct term_cell){ + dst[x] = (struct wsap_vtcore_cell){ .text = text, .fg = c->fg, .bg = c->bg, @@ -175,7 +175,7 @@ struct plan { }; /* Phase 2: write the plan into the snapshot. Nothing here can fail. */ -static void apply(struct term_snapshot *s, const struct term *t, const struct plan *p) +static void apply(struct wsap_vtcore_snapshot *s, const struct wsap_vtcore *t, const struct plan *p) { int cols = t->cols, rows = t->rows; int k = p->scrolled; @@ -190,7 +190,7 @@ static void apply(struct term_snapshot *s, const struct term *t, const struct pl s->arena_len = p->arena_len; bool changed = p->all; - size_t row_bytes = (size_t)cols * sizeof(struct term_cell); + size_t row_bytes = (size_t)cols * sizeof(struct wsap_vtcore_cell); /* Staged rows: copy the smaller part. Either the kept rows go into the * stage, which then becomes the cells, or the staged rows go into the * cells. A scroll moves every kept row anyway, so it swaps. */ @@ -201,7 +201,7 @@ static void apply(struct term_snapshot *s, const struct term *t, const struct pl for (int y = 0; y < rows; y++) if (p->words[y] == ROW_KEPT) memcpy(s->stage + (size_t)y * cols, s->cells + (size_t)(y + k) * cols, row_bytes); - struct term_cell *cells = s->cells; + struct wsap_vtcore_cell *cells = s->cells; s->cells = s->stage; s->stage = cells; } @@ -225,7 +225,7 @@ static void apply(struct term_snapshot *s, const struct term *t, const struct pl /* Phase 1 reserved room for the worst case, so this cannot fail. */ struct arena_out a = { &s->arena, &s->arena_cap, s->arena_len }; (void)convert_row(&a, t->gstore, s->cells + (size_t)y * cols, - term_screen_view_row(t, y), cols); + wsap_vtcore_screen_view_row(t, y), cols); s->row_clusters[y] = a.len - s->arena_len; s->arena_len = a.len; } else { @@ -238,19 +238,19 @@ static void apply(struct term_snapshot *s, const struct term *t, const struct pl } for (int y = 0; y < rows; y++) { - struct term_span span = p->c1[y] >= p->c0[y] ? (struct term_span){ p->c0[y], p->c1[y] + 1 } - : (struct term_span){ 0 }; + struct wsap_vtcore_span span = p->c1[y] >= p->c0[y] ? (struct wsap_vtcore_span){ p->c0[y], p->c1[y] + 1 } + : (struct wsap_vtcore_span){ 0 }; if (p->all || span.begin != s->selection[y].begin || span.end != s->selection[y].end) changed = true; s->selection[y] = span; } - struct term_cursor cursor = term_cursor(t); - int view_offset = term_view_offset(t); + struct wsap_vtcore_cursor cursor = wsap_vtcore_cursor(t); + int view_offset = wsap_vtcore_view_offset(t); cursor.pos.y += view_offset; if (cursor.pos.y >= rows) cursor.visible = false; - const struct term_cursor *old = &s->view.cursor; + const struct wsap_vtcore_cursor *old = &s->view.cursor; if (cursor.pos.x != old->pos.x || cursor.pos.y != old->pos.y || cursor.style != old->style || cursor.visible != old->visible || cursor.blink != old->blink || @@ -264,7 +264,7 @@ static void apply(struct term_snapshot *s, const struct term *t, const struct pl } s->source = t->serial; - s->view.size = (struct term_vector2i){ .x = cols, .y = rows }; + s->view.size = (struct wsap_vtcore_vector2i){ .x = cols, .y = rows }; s->view.cursor = cursor; s->view.scroll_offset = view_offset; s->view.scrolled = k; @@ -275,7 +275,7 @@ static void apply(struct term_snapshot *s, const struct term *t, const struct pl /* Phase 1 for one update. Allocates and checks everything that can fail, * then hands the plan to apply(). A false return leaves the content as it was. */ -static bool term_snapshot_update_inner(struct term_snapshot *s, struct term *t) +static bool wsap_vtcore_snapshot_update_inner(struct wsap_vtcore_snapshot *s, struct wsap_vtcore *t) { if (!s || !t) return false; @@ -311,12 +311,12 @@ static bool term_snapshot_update_inner(struct term_snapshot *s, struct term *t) if (s->arena_dead > 4096 && s->arena_dead * 2 > s->arena_len) all = true; - term_hist_prepare_rows(&t->hist, cols); - if (!term_hist_view_sync(&t->view, &t->hist, cols)) + wsap_vtcore_hist_prepare_rows(&t->hist, cols); + if (!wsap_vtcore_hist_view_sync(&t->view, &t->hist, cols)) goto done; - term_hist_view_refine(&t->view, &t->hist, cols, rows); + wsap_vtcore_hist_view_refine(&t->view, &t->hist, cols, rows); for (int y = 0; y < rows; y++) - new_keys[y] = term_screen_view_row_key(t, y); + new_keys[y] = wsap_vtcore_screen_view_row_key(t, y); if (!all && rows > 1) { int cand_k = 0; @@ -377,7 +377,7 @@ static bool term_snapshot_update_inner(struct term_snapshot *s, struct term *t) * records after the live ones, or in the spare arena for a rebuild. */ struct arena_out a = all ? (struct arena_out){ &s->spare, &s->spare_cap, 0 } : (struct arena_out){ &s->arena, &s->arena_cap, s->arena_len }; - uint64_t worst = (uint64_t)p.staged * (uint64_t)cols * (1 + TERM_GRAPHEME_MAX_LEN); + uint64_t worst = (uint64_t)p.staged * (uint64_t)cols * (1 + WSAP_VTCORE_GRAPHEME_MAX_LEN); if (!all && worst <= DIRECT_MAX_WORDS) { if (!arena_reserve(&a, a.len + worst)) goto done; @@ -388,13 +388,13 @@ static bool term_snapshot_update_inner(struct term_snapshot *s, struct term *t) continue; uint32_t before = a.len; if (!convert_row(&a, t->gstore, s->stage + (size_t)y * cols, - term_screen_view_row(t, y), cols)) + wsap_vtcore_screen_view_row(t, y), cols)) goto done; words[y] = a.len - before; } } - if (!term_selection_view_spans(t, c0, c1)) + if (!wsap_vtcore_selection_view_spans(t, c0, c1)) goto done; p.all = all; p.scrolled = scrolled; @@ -407,52 +407,52 @@ done: return ok; } -bool term_snapshot_update(struct term_snapshot *s, struct term *t) +bool wsap_vtcore_snapshot_update(struct wsap_vtcore_snapshot *s, struct wsap_vtcore *t) { if (!s || !t) return false; - term_write_begin(t); - bool ok = term_snapshot_update_inner(s, t); - term_write_end(t); + wsap_vtcore_write_begin(t); + bool ok = wsap_vtcore_snapshot_update_inner(s, t); + wsap_vtcore_write_end(t); return ok; } -const struct term_view *term_snapshot_view(const struct term_snapshot *s) +const struct wsap_vtcore_view *wsap_vtcore_snapshot_view(const struct wsap_vtcore_snapshot *s) { return s ? &s->view : NULL; } -const struct term_cell *term_snapshot_row(const struct term_snapshot *s, int y) +const struct wsap_vtcore_cell *wsap_vtcore_snapshot_row(const struct wsap_vtcore_snapshot *s, int y) { if (!s || y < 0 || y >= s->view.size.y) return NULL; return s->cells + (size_t)y * s->view.size.x; } -uint64_t term_snapshot_row_key(const struct term_snapshot *s, int y) +uint64_t wsap_vtcore_snapshot_row_key(const struct wsap_vtcore_snapshot *s, int y) { if (!s || y < 0 || y >= s->view.size.y) return 0; return s->keys[y]; } -struct term_span term_snapshot_row_selection(const struct term_snapshot *s, int y) +struct wsap_vtcore_span wsap_vtcore_snapshot_row_selection(const struct wsap_vtcore_snapshot *s, int y) { if (!s || y < 0 || y >= s->view.size.y) - return (struct term_span){ 0 }; + return (struct wsap_vtcore_span){ 0 }; return s->selection[y]; } -int term_snapshot_cluster(const struct term_snapshot *s, uint32_t text, uint32_t *cps, int cap) +int wsap_vtcore_snapshot_cluster(const struct wsap_vtcore_snapshot *s, uint32_t text, uint32_t *cps, int cap) { if (!s) return 0; - if (!(text & TERM_TEXT_CLUSTER)) { + if (!(text & WSAP_VTCORE_TEXT_CLUSTER)) { if (cps && cap > 0) cps[0] = text; return 1; } - uint32_t off = text & ~TERM_TEXT_CLUSTER; + uint32_t off = text & ~WSAP_VTCORE_TEXT_CLUSTER; if (off >= s->arena_len) return 0; int n = (int)s->arena[off]; @@ -1,47 +1,47 @@ #include "internal.h" #include "screen.h" -_Thread_local char term_thread_anchor; +_Thread_local char wsap_vtcore_thread_anchor; -const char *term_unicode_version(void) +const char *wsap_vtcore_unicode_version(void) { - return TERM_UNICODE_DATA_VERSION; + return WSAP_VTCORE_UNICODE_DATA_VERSION; } -unsigned term_version(void) +unsigned wsap_vtcore_version(void) { - return TERM_VERSION_CODE; + return WSAP_VTCORE_VERSION_CODE; } -void term_lock(struct term *t) +void wsap_vtcore_lock(struct wsap_vtcore *t) { - term_write_begin(t); + wsap_vtcore_write_begin(t); } -void term_unlock(struct term *t) +void wsap_vtcore_unlock(struct wsap_vtcore *t) { - term_write_end(t); + wsap_vtcore_write_end(t); } -struct term_vector2i term_size(const struct term *t) +struct wsap_vtcore_vector2i wsap_vtcore_size(const struct wsap_vtcore *t) { if (!t) - return (struct term_vector2i){ 0 }; - term_write_begin((struct term *)t); - struct term_vector2i size = { .x = t->cols, .y = t->rows }; - term_write_end((struct term *)t); + return (struct wsap_vtcore_vector2i){ 0 }; + wsap_vtcore_write_begin((struct wsap_vtcore *)t); + struct wsap_vtcore_vector2i size = { .x = t->cols, .y = t->rows }; + wsap_vtcore_write_end((struct wsap_vtcore *)t); return size; } -struct term_modes term_modes(const struct term *t) +struct wsap_vtcore_modes wsap_vtcore_modes(const struct wsap_vtcore *t) { if (!t) - return (struct term_modes){ 0 }; - term_write_begin((struct term *)t); - struct term_modes m = { + return (struct wsap_vtcore_modes){ 0 }; + wsap_vtcore_write_begin((struct wsap_vtcore *)t); + struct wsap_vtcore_modes m = { .keyboard = t->keyboard[t->alternate].flags, - .mouse = (enum term_mouse)t->mouse_mode, - .mouse_encoding = (enum term_mouse_encoding)t->mouse_encoding, + .mouse = (enum wsap_vtcore_mouse)t->mouse_mode, + .mouse_encoding = (enum wsap_vtcore_mouse_encoding)t->mouse_encoding, .grid = { .x = t->cols, .y = t->rows }, .app_cursor = t->application_cursor, .app_keypad = t->application_keypad, @@ -52,82 +52,82 @@ struct term_modes term_modes(const struct term *t) .reverse_video = t->reverse_video, .synchronized = t->synchronized_output, }; - term_write_end((struct term *)t); + wsap_vtcore_write_end((struct wsap_vtcore *)t); return m; } -struct term_cursor term_cursor(const struct term *t) +struct wsap_vtcore_cursor wsap_vtcore_cursor(const struct wsap_vtcore *t) { if (!t) - return (struct term_cursor){ .visible = true }; - term_write_begin((struct term *)t); - struct term_cursor c = { + return (struct wsap_vtcore_cursor){ .visible = true }; + wsap_vtcore_write_begin((struct wsap_vtcore *)t); + struct wsap_vtcore_cursor c = { .pos = { .x = t->cursor_x, .y = t->cursor_y }, .style = t->cursor_style, .visible = t->cursor_visible, .blink = t->cursor_blink, }; - term_write_end((struct term *)t); + wsap_vtcore_write_end((struct wsap_vtcore *)t); return c; } -void term_set_cursor_default(struct term *t, enum term_cursor_style style, bool steady) +void wsap_vtcore_set_cursor_default(struct wsap_vtcore *t, enum wsap_vtcore_cursor_style style, bool steady) { if (!t) return; - term_write_begin(t); - if (style > TERM_CURSOR_BAR) - style = TERM_CURSOR_BLOCK; + wsap_vtcore_write_begin(t); + if (style > WSAP_VTCORE_CURSOR_BAR) + style = WSAP_VTCORE_CURSOR_BLOCK; if (t->cursor_style != style || t->cursor_blink == steady) { - struct srow *cur = term_row(t, t->cursor_y); + struct srow *cur = wsap_vtcore_row(t, t->cursor_y); if (cur) cur->version++; } t->default_cursor_style = t->cursor_style = style; t->default_cursor_blink = t->cursor_blink = !steady; - term_write_end(t); + wsap_vtcore_write_end(t); } -void term_set_theme(struct term *t, const struct term_theme *theme) +void wsap_vtcore_set_theme(struct wsap_vtcore *t, const struct wsap_vtcore_theme *theme) { if (!t) return; - term_write_begin(t); + wsap_vtcore_write_begin(t); struct palette next = { .version = t->palette.version }; - term_palette_init(&next, theme); + wsap_vtcore_palette_init(&next, theme); if (memcmp(&next.theme, &t->palette.theme, sizeof(next.theme))) t->palette = next; - term_write_end(t); + wsap_vtcore_write_end(t); } -void term_focus(struct term *t, bool focused) +void wsap_vtcore_focus(struct wsap_vtcore *t, bool focused) { if (!t) return; - term_write_begin(t); + wsap_vtcore_write_begin(t); if (t->focus_events) send_response(t, focused ? "\033[I" : "\033[O"); - term_write_end(t); + wsap_vtcore_write_end(t); } -char *term_cwd(const struct term *t) +char *wsap_vtcore_cwd(const struct wsap_vtcore *t) { if (!t) return NULL; - term_write_begin((struct term *)t); - char *text = t->cwd ? term_strdup(t->cwd) : NULL; - term_write_end((struct term *)t); + wsap_vtcore_write_begin((struct wsap_vtcore *)t); + char *text = t->cwd ? wsap_vtcore_strdup(t->cwd) : NULL; + wsap_vtcore_write_end((struct wsap_vtcore *)t); return text; } -char *term_pointer_shape(const struct term *t) +char *wsap_vtcore_pointer_shape(const struct wsap_vtcore *t) { if (!t) return NULL; - term_write_begin((struct term *)t); - char *text = t->pointer_shape ? term_strdup(t->pointer_shape) : NULL; - term_write_end((struct term *)t); + wsap_vtcore_write_begin((struct wsap_vtcore *)t); + char *text = t->pointer_shape ? wsap_vtcore_strdup(t->pointer_shape) : NULL; + wsap_vtcore_write_end((struct wsap_vtcore *)t); return text; } -void term_text_free(char *text) +void wsap_vtcore_text_free(char *text) { free(text); } @@ -12,7 +12,7 @@ #include <stdio.h> #include <string.h> -static inline void emit_codepoint(struct term *t, uint32_t cp, int klass, uint16_t flags) +static inline void emit_codepoint(struct wsap_vtcore *t, uint32_t cp, int klass, uint16_t flags) { static const uint32_t dec_graphics[] = { 0x00a0, @@ -28,7 +28,7 @@ static inline void emit_codepoint(struct term *t, uint32_t cp, int klass, uint16 char ch = c1_map[cp - 0x80]; if (ch) { t->state = ST_ESC; - term_escape_byte(t, (unsigned char)ch); + wsap_vtcore_escape_byte(t, (unsigned char)ch); } return; } @@ -39,38 +39,38 @@ static inline void emit_codepoint(struct term *t, uint32_t cp, int klass, uint16 sc_print_cell(t, cp, klass, flags); } -static inline void emit_decoded(struct term *t, uint32_t cp, uint16_t flags) +static inline void emit_decoded(struct wsap_vtcore *t, uint32_t cp, uint16_t flags) { - int klass = term_text_class(cp); - if (!term_sc_extend_cluster(t, cp, klass)) + int klass = wsap_vtcore_text_class(cp); + if (!wsap_vtcore_sc_extend_cluster(t, cp, klass)) emit_codepoint(t, cp, klass, flags); } /* A byte that cannot continue a UTF-8 sequence ends it: the unfinished * sequence prints U+FFFD (Unicode 3.9, maximal subparts). */ -void term_text_utf8_interrupt(struct term *t) +void wsap_vtcore_text_utf8_interrupt(struct wsap_vtcore *t) { - if (TERM_EXPECT(t->utf8_state == TERM_UTF8_ACCEPT, 1)) + if (WSAP_VTCORE_EXPECT(t->utf8_state == WSAP_VTCORE_UTF8_ACCEPT, 1)) return; - t->utf8_state = TERM_UTF8_ACCEPT; - emit_decoded(t, 0xFFFD, term_current_flags(t)); + t->utf8_state = WSAP_VTCORE_UTF8_ACCEPT; + emit_decoded(t, 0xFFFD, wsap_vtcore_current_flags(t)); } -void term_text_ground(struct term *t, unsigned char ch) +void wsap_vtcore_text_ground(struct wsap_vtcore *t, unsigned char ch) { - if (ch >= 0x20 && ch < 0x7f && t->utf8_state == TERM_UTF8_ACCEPT) { - emit_codepoint(t, ch, 1, term_current_flags(t)); + if (ch >= 0x20 && ch < 0x7f && t->utf8_state == WSAP_VTCORE_UTF8_ACCEPT) { + emit_codepoint(t, ch, 1, wsap_vtcore_current_flags(t)); return; } if (ch < 0x20 || ch == 0x7f) - term_text_utf8_interrupt(t); + wsap_vtcore_text_utf8_interrupt(t); - if (TERM_EXPECT(ch == 0x1b, 0)) { - term_escape_begin(t); + if (WSAP_VTCORE_EXPECT(ch == 0x1b, 0)) { + wsap_vtcore_escape_begin(t); } else if (ch == '\n' || ch == 0x0b || ch == 0x0c) { /* VT and FF act as LF (xterm). */ - if (term_lnm(t)) sc_cr(t); + if (wsap_vtcore_lnm(t)) sc_cr(t); sc_linefeed(t, 1); } else if (ch == '\r') { sc_cr(t); @@ -78,9 +78,9 @@ void term_text_ground(struct term *t, unsigned char ch) t->pending_wrap = false; if (t->cursor_x > 0) t->cursor_x--; - term_row(t, t->cursor_y)->version++; + wsap_vtcore_row(t, t->cursor_y)->version++; } else if (ch == '\t') { - term_sc_tab(t, 1); + wsap_vtcore_sc_tab(t, 1); } else if (ch == 0x07) { if (t->cb.bell) t->cb.bell(t->cb.ud); @@ -92,55 +92,55 @@ void term_text_ground(struct term *t, unsigned char ch) t->graphics = t->charsets[0] == '0'; } else if (ch >= 0x20 && ch != 0x7f) { uint32_t before = t->utf8_state; - uint32_t st = term_utf8_decode(&t->utf8_state, &t->utf8_codep, ch); - if (st == TERM_UTF8_ACCEPT) { - emit_decoded(t, t->utf8_codep, term_current_flags(t)); - } else if (st == TERM_UTF8_REJECT) { - t->utf8_state = TERM_UTF8_ACCEPT; - emit_decoded(t, 0xFFFD, term_current_flags(t)); + uint32_t st = wsap_vtcore_utf8_decode(&t->utf8_state, &t->utf8_codep, ch); + if (st == WSAP_VTCORE_UTF8_ACCEPT) { + emit_decoded(t, t->utf8_codep, wsap_vtcore_current_flags(t)); + } else if (st == WSAP_VTCORE_UTF8_REJECT) { + t->utf8_state = WSAP_VTCORE_UTF8_ACCEPT; + emit_decoded(t, 0xFFFD, wsap_vtcore_current_flags(t)); /* The byte that ended an unfinished sequence starts anew. */ - if (before != TERM_UTF8_ACCEPT) - term_text_ground(t, ch); + if (before != WSAP_VTCORE_UTF8_ACCEPT) + wsap_vtcore_text_ground(t, ch); } } } -static inline bool can_stream_bottom(const struct term *t) +static inline bool can_stream_bottom(const struct wsap_vtcore *t) { return t->state == ST_GROUND && !t->graphics && !t->insert_mode && t->autowrap && !t->lr_margin_mode && - t->utf8_state == TERM_UTF8_ACCEPT && !t->inverse && + t->utf8_state == WSAP_VTCORE_UTF8_ACCEPT && !t->inverse && t->scroll_top == 0 && t->scroll_bottom == t->rows - 1 && t->cursor_y == t->rows - 1 && !t->alternate && t->sb_capacity > 0 && using_default_colors(t); } -static inline bool try_text_run(struct term *t, const char *buf, size_t len, +static inline bool try_text_run(struct wsap_vtcore *t, const char *buf, size_t len, size_t *idx) { size_t i = *idx; if (t->pending_wrap || i + 4 > len || ((unsigned char)buf[i] >= 0x80 && ((unsigned char)buf[i] < 0xc2 || (unsigned char)buf[i] > 0xf4)) || - t->last_char == 0x200D || term_grapheme_is_handle(t->last_char)) + t->last_char == 0x200D || wsap_vtcore_grapheme_is_handle(t->last_char)) return false; if (t->cursor_x != 0 && - t->cursor_x != term_row(t, t->cursor_y)->len) + t->cursor_x != wsap_vtcore_row(t, t->cursor_y)->len) return false; if ((unsigned char)buf[i] >= 0x80) { uint32_t cp; - int bytes = term_utf8_decode_one(buf + i, len - i, &cp); - if (!bytes || term_text_class(cp) <= 0) + int bytes = wsap_vtcore_utf8_decode_one(buf + i, len - i, &cp); + if (!bytes || wsap_vtcore_text_class(cp) <= 0) return false; } - struct text_pen pen = term_text_pen(t); + struct text_pen pen = wsap_vtcore_text_pen(t); bool wrote = false; do { struct srow *text = t->insert_mode || t->lr_margin_mode ? NULL : text_append_row(t); if (text) { int x = t->cursor_x, avail = t->cols - x; - struct text_run_bytes r = term_text_run_bytes(text->text.text + text->text.text_len, + struct text_run_bytes r = wsap_vtcore_text_run_bytes(text->text.text + text->text.text_len, buf + i, (int)(len - i), avail, t->last_char, &t->text_width); if (!r.bytes) @@ -156,7 +156,7 @@ static inline bool try_text_run(struct term *t, const char *buf, size_t len, struct span span = sc_span_begin(t, t->cols); if (span.avail < 2) break; - struct text_run_result r = term_text_run(span.cells, buf + i, (int)(len - i), + struct text_run_result r = wsap_vtcore_text_run(span.cells, buf + i, (int)(len - i), span.avail, pen.fg, pen.bg, pen.sl, t->last_char, &t->text_width); if (!r.bytes) @@ -175,45 +175,45 @@ static inline bool try_text_run(struct term *t, const char *buf, size_t len, newline = true; } } else if (i < len && buf[i] == '\n') { - if (term_lnm(t)) sc_cr(t); + if (wsap_vtcore_lnm(t)) sc_cr(t); sc_linefeed(t, 1); i++; newline = true; } if (!newline || i + 4 > len || t->pending_wrap || - t->last_char == 0x200D || term_grapheme_is_handle(t->last_char) || + t->last_char == 0x200D || wsap_vtcore_grapheme_is_handle(t->last_char) || (t->cursor_x != 0 && - t->cursor_x != term_row(t, t->cursor_y)->len)) + t->cursor_x != wsap_vtcore_row(t, t->cursor_y)->len)) break; } while (true); if (wrote) *idx = i - 1; return wrote; } -/* The feed flags this build knows. term_feed() rejects any other bit. */ -#define TERM_FEED_KNOWN TERM_FEED_ONLCR +/* The feed flags this build knows. wsap_vtcore_feed() rejects any other bit. */ +#define WSAP_VTCORE_FEED_KNOWN WSAP_VTCORE_FEED_ONLCR -static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigned flags) +static void wsap_vtcore_feed_inner(struct wsap_vtcore *t, const char *buf, size_t len, unsigned flags) { - t->transport_newline = (flags & TERM_FEED_ONLCR) != 0; - uint16_t cur_flags = term_current_flags(t); + t->transport_newline = (flags & WSAP_VTCORE_FEED_ONLCR) != 0; + uint16_t cur_flags = wsap_vtcore_current_flags(t); for (size_t i = 0; i < len; i++) { while (t->state != ST_GROUND) { if (t->state == ST_CSI) - i += term_escape_csi(t, buf + i, len - i); + i += wsap_vtcore_escape_csi(t, buf + i, len - i); else if (t->state == ST_OSC || t->state == ST_DCS || t->state == ST_IGNORE) - i += term_escape_str(t, buf + i, len - i); + i += wsap_vtcore_escape_str(t, buf + i, len - i); else - term_escape_byte(t, (unsigned char)buf[i++]); - cur_flags = term_current_flags(t); + wsap_vtcore_escape_byte(t, (unsigned char)buf[i++]); + cur_flags = wsap_vtcore_current_flags(t); if (i == len) return; } unsigned char ch = (unsigned char)buf[i]; - if (TERM_EXPECT(ch >= 0x20 && ch < 0x7f && !t->insert_mode && !t->lr_margin_mode && + if (WSAP_VTCORE_EXPECT(ch >= 0x20 && ch < 0x7f && !t->insert_mode && !t->lr_margin_mode && t->state == ST_GROUND && !t->graphics && - t->utf8_state == TERM_UTF8_ACCEPT, 1)) { + t->utf8_state == WSAP_VTCORE_UTF8_ACCEPT, 1)) { int avail = t->pending_wrap ? t->cols : t->cols - t->cursor_x; int rem = (int)(len - i); if (rem > avail) rem = avail; @@ -221,14 +221,14 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne if (rem > 1 && (unsigned char)buf[i + 1] >= 0x20 && (unsigned char)buf[i + 1] < 0x7f) run += scan_ascii_run(buf + i + 1, rem - 1); - if (TERM_EXPECT(can_stream_bottom(t), 1) && + if (WSAP_VTCORE_EXPECT(can_stream_bottom(t), 1) && (run == t->cols || (i + (size_t)run < len && (buf[i + run] == '\r' || buf[i + run] == '\n')))) { - struct srow *row = term_row(t, t->cursor_y); + struct srow *row = wsap_vtcore_row(t, t->cursor_y); if (t->pending_wrap || (t->cursor_x == 0 && row && row->len == 0)) { - size_t done = term_sc_bulk_ascii_lines(t, buf + i, len - i); + size_t done = wsap_vtcore_sc_bulk_ascii_lines(t, buf + i, len - i); if (done > 0) { i += done - 1; continue; @@ -240,8 +240,8 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne (unsigned char)buf[i + 1] <= 0xf4 && (i + 2 == len || ((unsigned char)buf[i + 2] & 0xc0) == 0x80)) { uint32_t next_cp; - if (term_utf8_decode_one(buf + i + 1, len - i - 1, &next_cp) && - term_text_class(next_cp) > 0 && + if (wsap_vtcore_utf8_decode_one(buf + i + 1, len - i - 1, &next_cp) && + wsap_vtcore_text_class(next_cp) > 0 && try_text_run(t, buf, len, &i)) continue; } @@ -250,8 +250,8 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne } if (i + (size_t)run < len && (unsigned char)buf[i + run] >= 0x80) { uint32_t next_cp; - if (term_utf8_decode_one(buf + i + run, len - i - (size_t)run, &next_cp) && - term_text_class(next_cp) > 0 && + if (wsap_vtcore_utf8_decode_one(buf + i + run, len - i - (size_t)run, &next_cp) && + wsap_vtcore_text_class(next_cp) > 0 && try_text_run(t, buf, len, &i)) continue; } @@ -265,7 +265,7 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne i++; } } else if (i < len && buf[i] == '\n') { - if (term_lnm(t)) sc_cr(t); + if (wsap_vtcore_lnm(t)) sc_cr(t); sc_linefeed(t, 1); i++; } @@ -273,38 +273,38 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne continue; } - if (TERM_EXPECT(ch >= 0x80, 1)) { - if (TERM_EXPECT(t->state == ST_GROUND && - t->utf8_state == TERM_UTF8_ACCEPT && !t->graphics, 1)) { + if (WSAP_VTCORE_EXPECT(ch >= 0x80, 1)) { + if (WSAP_VTCORE_EXPECT(t->state == ST_GROUND && + t->utf8_state == WSAP_VTCORE_UTF8_ACCEPT && !t->graphics, 1)) { if (ch >= 0xc2 && ch <= 0xf4 && (i + 1 == len || ((unsigned char)buf[i + 1] & 0xc0) == 0x80)) { if (!t->insert_mode && !t->lr_margin_mode && try_text_run(t, buf, len, &i)) continue; } else { - if (TERM_EXPECT(t->last_char != 0x200D && !term_grapheme_is_handle(t->last_char), 1)) + if (WSAP_VTCORE_EXPECT(t->last_char != 0x200D && !wsap_vtcore_grapheme_is_handle(t->last_char), 1)) sc_print_cell(t, 0xFFFD, 1, cur_flags); else emit_decoded(t, 0xFFFD, cur_flags); continue; } uint32_t cp; - int cp_len = term_utf8_decode_ground(&t->utf8_state, &t->utf8_codep, buf + i, len - i, &cp); + int cp_len = wsap_vtcore_utf8_decode_ground(&t->utf8_state, &t->utf8_codep, buf + i, len - i, &cp); if (cp) emit_decoded(t, cp, cur_flags); i += (size_t)(cp_len - 1); continue; } - if (TERM_EXPECT(t->state == ST_GROUND, 1)) - term_text_ground(t, ch); + if (WSAP_VTCORE_EXPECT(t->state == ST_GROUND, 1)) + wsap_vtcore_text_ground(t, ch); else - term_escape_byte(t, ch); + wsap_vtcore_escape_byte(t, ch); continue; } - if (TERM_EXPECT(ch < 0x20 || ch == 0x7f, 0)) { + if (WSAP_VTCORE_EXPECT(ch < 0x20 || ch == 0x7f, 0)) { if (t->state == ST_GROUND) { - term_text_utf8_interrupt(t); + wsap_vtcore_text_utf8_interrupt(t); if (ch == 0x7f || ((1u << ch) & 0x0800FF80u) == 0) continue; @@ -313,7 +313,7 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne case 0x0b: case 0x0c: { size_t end = i + 1 + scan_byte_run(buf + i + 1, len - i - 1, '\n'); - if (term_lnm(t)) sc_cr(t); + if (wsap_vtcore_lnm(t)) sc_cr(t); sc_linefeed(t, end - i); i = end - 1; continue; @@ -329,66 +329,66 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne } continue; case 0x1b: - if (t->utf8_state == TERM_UTF8_ACCEPT && i + 1 < len && + if (t->utf8_state == WSAP_VTCORE_UTF8_ACCEPT && i + 1 < len && buf[i + 1] == '[' && !t->insert_mode && !t->lr_margin_mode && !t->graphics) { - int fast = term_try_fast_csi(t, buf + i + 2, len - i - 2); + int fast = wsap_vtcore_try_fast_csi(t, buf + i + 2, len - i - 2); if (fast > 0) { - cur_flags = term_current_flags(t); + cur_flags = wsap_vtcore_current_flags(t); i += 1 + (size_t)fast; continue; } t->state = ST_CSI; csi_parser_reset(&t->csi_parser); - i += 1 + term_escape_csi(t, buf + i + 2, len - i - 2); - cur_flags = term_current_flags(t); + i += 1 + wsap_vtcore_escape_csi(t, buf + i + 2, len - i - 2); + cur_flags = wsap_vtcore_current_flags(t); continue; } - term_text_ground(t, ch); - cur_flags = term_current_flags(t); + wsap_vtcore_text_ground(t, ch); + cur_flags = wsap_vtcore_current_flags(t); continue; default: - term_text_ground(t, ch); - cur_flags = term_current_flags(t); + wsap_vtcore_text_ground(t, ch); + cur_flags = wsap_vtcore_current_flags(t); continue; } } else { - term_escape_byte(t, ch); - cur_flags = term_current_flags(t); + wsap_vtcore_escape_byte(t, ch); + cur_flags = wsap_vtcore_current_flags(t); continue; } } - if (TERM_EXPECT(t->state == ST_GROUND, 1)) - term_text_ground(t, ch); + if (WSAP_VTCORE_EXPECT(t->state == ST_GROUND, 1)) + wsap_vtcore_text_ground(t, ch); else - term_escape_byte(t, ch); - cur_flags = term_current_flags(t); + wsap_vtcore_escape_byte(t, ch); + cur_flags = wsap_vtcore_current_flags(t); } } -bool term_feed(struct term *t, const char *buf, size_t len, unsigned flags) +bool wsap_vtcore_feed(struct wsap_vtcore *t, const char *buf, size_t len, unsigned flags) { - if (!t || (!buf && len > 0) || (flags & ~TERM_FEED_KNOWN)) + if (!t || (!buf && len > 0) || (flags & ~WSAP_VTCORE_FEED_KNOWN)) return false; if (len == 0) return true; - term_write_begin(t); - term_feed_inner(t, buf, len, flags); - term_write_end(t); + wsap_vtcore_write_begin(t); + wsap_vtcore_feed_inner(t, buf, len, flags); + wsap_vtcore_write_end(t); return true; } -void term_text_repeat(struct term *t, int count) +void wsap_vtcore_text_repeat(struct wsap_vtcore *t, int count) { int screen = t->cols * t->rows; if (count > screen) count = screen; if (count <= 0 || !t->last_char) return; if (count == 1) { - term_sc_print_glyph(t, t->last_char, -1, term_current_flags(t)); + wsap_vtcore_sc_print_glyph(t, t->last_char, -1, wsap_vtcore_current_flags(t)); return; } for (int j = 0; j < count && t->last_char; j++) - term_sc_print_glyph(t, t->last_char, -1, term_current_flags(t)); + wsap_vtcore_sc_print_glyph(t, t->last_char, -1, wsap_vtcore_current_flags(t)); } @@ -1,10 +1,10 @@ -#ifndef TERM_TEXT_H -#define TERM_TEXT_H +#ifndef WSAP_VTCORE_TEXT_H +#define WSAP_VTCORE_TEXT_H #include "internal.h" -void term_text_ground(struct term *t, unsigned char ch); +void wsap_vtcore_text_ground(struct wsap_vtcore *t, unsigned char ch); /* End an unfinished UTF-8 sequence: it prints U+FFFD. */ -void term_text_utf8_interrupt(struct term *t); -void term_text_repeat(struct term *t, int count); +void wsap_vtcore_text_utf8_interrupt(struct wsap_vtcore *t); +void wsap_vtcore_text_repeat(struct wsap_vtcore *t, int count); #endif diff --git a/src/text_run.c b/src/text_run.c index c48b73e..872c8de 100644 --- a/src/text_run.c +++ b/src/text_run.c @@ -10,16 +10,16 @@ static uint8_t unicode_fast_class[65536]; static int8_t unicode_width_bmp[65536]; /* Runs of code points with one fast class, for the AVX-512 width cache. */ -#define TERM_WIDTH_RUNS_MAX 1024 -static uint16_t width_run_lo[TERM_WIDTH_RUNS_MAX]; -static uint16_t width_run_hi[TERM_WIDTH_RUNS_MAX]; -static uint8_t width_run_class[TERM_WIDTH_RUNS_MAX]; +#define WSAP_VTCORE_WIDTH_RUNS_MAX 1024 +static uint16_t width_run_lo[WSAP_VTCORE_WIDTH_RUNS_MAX]; +static uint16_t width_run_hi[WSAP_VTCORE_WIDTH_RUNS_MAX]; +static uint8_t width_run_class[WSAP_VTCORE_WIDTH_RUNS_MAX]; static int width_run_count; -void term_text_tables_init(void) +void wsap_vtcore_text_tables_init(void) { for (uint32_t cp = 0; cp < 65536; cp++) { - int w = term_unicode_width(cp); + int w = wsap_vtcore_unicode_width(cp); unicode_fast_class[cp] = (w == 1 || w == 2) && !cluster_contextual(cp) ? (uint8_t)w : 0; unicode_width_bmp[cp] = (int8_t)w; @@ -28,7 +28,7 @@ void term_text_tables_init(void) uint8_t k = unicode_fast_class[cp]; uint32_t lo = cp; while (cp < 65536 && unicode_fast_class[cp] == k) cp++; - if (width_run_count == TERM_WIDTH_RUNS_MAX) { + if (width_run_count == WSAP_VTCORE_WIDTH_RUNS_MAX) { width_run_count = 0; break; } @@ -39,7 +39,7 @@ void term_text_tables_init(void) } } -static TERM_MAYBE_UNUSED int width_run_find(uint32_t cp) +static WSAP_VTCORE_MAYBE_UNUSED int width_run_find(uint32_t cp) { int lo = 0, hi = width_run_count - 1; while (lo < hi) { @@ -50,24 +50,24 @@ static TERM_MAYBE_UNUSED int width_run_find(uint32_t cp) return width_run_count > 0 ? lo : -1; } -static TERM_MAYBE_UNUSED uint16_t width_cache_covers(const struct width_cache *wc, +static WSAP_VTCORE_MAYBE_UNUSED uint16_t width_cache_covers(const struct width_cache *wc, const uint32_t *cp) { uint16_t covered = 0; for (int l = 0; l < 16; l++) { bool hit = false; - for (int k = 0; k < TERM_WIDTH_SLOTS; k++) + for (int k = 0; k < WSAP_VTCORE_WIDTH_SLOTS; k++) hit |= cp[l] - wc->lo[k] <= wc->span[k]; covered |= (uint16_t)(hit << l); } return covered; } -static TERM_MAYBE_UNUSED bool width_cache_extend(struct width_cache *wc, const uint32_t *cp, +static WSAP_VTCORE_MAYBE_UNUSED bool width_cache_extend(struct width_cache *wc, const uint32_t *cp, uint16_t covered) { unsigned miss = (unsigned)~covered & 0xFFFFu; - int r = width_run_find(cp[miss ? term_ctz32(miss) : 0]); + int r = width_run_find(cp[miss ? wsap_vtcore_ctz32(miss) : 0]); if (r < 0) return false; uint8_t k = width_run_class[r]; if (k != 1 && k != 2) return false; @@ -77,25 +77,25 @@ static TERM_MAYBE_UNUSED bool width_cache_extend(struct width_cache *wc, const u wc->klass = k; wc->next = 0; } - for (int added = 0; added < TERM_WIDTH_SLOTS; added++) { + for (int added = 0; added < WSAP_VTCORE_WIDTH_SLOTS; added++) { wc->lo[wc->next] = width_run_lo[r]; wc->span[wc->next] = (uint32_t)(width_run_hi[r] - width_run_lo[r]); - wc->next = (uint8_t)((wc->next + 1) % TERM_WIDTH_SLOTS); + wc->next = (uint8_t)((wc->next + 1) % WSAP_VTCORE_WIDTH_SLOTS); covered = width_cache_covers(wc, cp); if (covered == 0xFFFF) return true; - r = width_run_find(cp[term_ctz32((unsigned)~covered & 0xFFFFu)]); + r = width_run_find(cp[wsap_vtcore_ctz32((unsigned)~covered & 0xFFFFu)]); if (r < 0 || width_run_class[r] != k) return false; } return false; } -int term_text_class(uint32_t cp) +int wsap_vtcore_text_class(uint32_t cp) { - assert(term_tables_ready()); - return TERM_EXPECT(cp < 65536, 1) ? (int)unicode_width_bmp[cp] : term_unicode_width(cp); + assert(wsap_vtcore_tables_ready()); + return WSAP_VTCORE_EXPECT(cp < 65536, 1) ? (int)unicode_width_bmp[cp] : wsap_vtcore_unicode_width(cp); } -#if defined(TERM_KERNEL_AVX512) +#if defined(WSAP_VTCORE_KERNEL_AVX512) static const uint8_t utf8_3byte_shuffle[64] = { 2, 1, 0, 48, 5, 4, 3, 48, 8, 7, 6, 48, 11, 10, 9, 48, @@ -122,7 +122,7 @@ static const uint8_t utf8_3byte_want[64] = { }; #define UTF8_3BYTE_SPAN 0x0000FFFFFFFFFFFFull -TERM_TARGET_AVX512 +WSAP_VTCORE_TARGET_AVX512 static inline __m512i utf8_3byte_decode(__m512i packed) { __m512i b2 = _mm512_and_si512(packed, _mm512_set1_epi32(0x003F)); @@ -132,70 +132,70 @@ static inline __m512i utf8_3byte_decode(__m512i packed) } struct width_ranges { - __m512i lo[TERM_WIDTH_SLOTS]; - __m512i span[TERM_WIDTH_SLOTS]; + __m512i lo[WSAP_VTCORE_WIDTH_SLOTS]; + __m512i span[WSAP_VTCORE_WIDTH_SLOTS]; }; -TERM_TARGET_AVX512 +WSAP_VTCORE_TARGET_AVX512 static inline struct width_ranges width_ranges_load(const struct width_cache *wc) { struct width_ranges r; - for (int k = 0; k < TERM_WIDTH_SLOTS; k++) { + for (int k = 0; k < WSAP_VTCORE_WIDTH_SLOTS; k++) { r.lo[k] = _mm512_set1_epi32((int)wc->lo[k]); r.span[k] = _mm512_set1_epi32((int)wc->span[k]); } return r; } -TERM_TARGET_AVX512 +WSAP_VTCORE_TARGET_AVX512 static inline __mmask16 width_ranges_cover(const struct width_ranges *r, __m512i cps) { __mmask16 covered = 0; - for (int k = 0; k < TERM_WIDTH_SLOTS; k++) + for (int k = 0; k < WSAP_VTCORE_WIDTH_SLOTS; k++) covered |= _mm512_cmple_epu32_mask(_mm512_sub_epi32(cps, r->lo[k]), r->span[k]); return covered; } -TERM_TARGET_AVX512 +WSAP_VTCORE_TARGET_AVX512 static inline void store_wide_cells(uint64_t * restrict dst, __m512i base, __m512i cps) { -#define TERM_WIDE_PAIR(k) _mm512_storeu_si512((void *)(dst + 8 * (k)), \ +#define WSAP_VTCORE_WIDE_PAIR(k) _mm512_storeu_si512((void *)(dst + 8 * (k)), \ _mm512_mask_permutexvar_epi32(base, 0x0101, \ _mm512_setr_epi32((k) * 2, 0, 0, 0, 0, 0, 0, 0, \ (k) * 2 + 1, 0, 0, 0, 0, 0, 0, 0), cps)) - TERM_WIDE_PAIR(0); TERM_WIDE_PAIR(1); TERM_WIDE_PAIR(2); TERM_WIDE_PAIR(3); - TERM_WIDE_PAIR(4); TERM_WIDE_PAIR(5); TERM_WIDE_PAIR(6); TERM_WIDE_PAIR(7); -#undef TERM_WIDE_PAIR + WSAP_VTCORE_WIDE_PAIR(0); WSAP_VTCORE_WIDE_PAIR(1); WSAP_VTCORE_WIDE_PAIR(2); WSAP_VTCORE_WIDE_PAIR(3); + WSAP_VTCORE_WIDE_PAIR(4); WSAP_VTCORE_WIDE_PAIR(5); WSAP_VTCORE_WIDE_PAIR(6); WSAP_VTCORE_WIDE_PAIR(7); +#undef WSAP_VTCORE_WIDE_PAIR } -TERM_TARGET_AVX512 +WSAP_VTCORE_TARGET_AVX512 static inline void store_narrow_cells(uint64_t * restrict dst, __m512i base, __m512i cps) { -#define TERM_NARROW_QUAD(k) _mm512_storeu_si512((void *)(dst + 8 * (k)), \ +#define WSAP_VTCORE_NARROW_QUAD(k) _mm512_storeu_si512((void *)(dst + 8 * (k)), \ _mm512_mask_permutexvar_epi32(base, 0x1111, \ _mm512_setr_epi32((k) * 4, 0, 0, 0, (k) * 4 + 1, 0, 0, 0, \ (k) * 4 + 2, 0, 0, 0, (k) * 4 + 3, 0, 0, 0), cps)) - TERM_NARROW_QUAD(0); TERM_NARROW_QUAD(1); TERM_NARROW_QUAD(2); TERM_NARROW_QUAD(3); -#undef TERM_NARROW_QUAD + WSAP_VTCORE_NARROW_QUAD(0); WSAP_VTCORE_NARROW_QUAD(1); WSAP_VTCORE_NARROW_QUAD(2); WSAP_VTCORE_NARROW_QUAD(3); +#undef WSAP_VTCORE_NARROW_QUAD } /* Both cell and history writers validate and classify the same UTF-8 block. */ -TERM_TARGET_AVX512 +WSAP_VTCORE_TARGET_AVX512 static inline bool classify_3byte_block(__m512i in, struct width_ranges *ranges, struct width_cache *wc, __m512i *cps) { - if (TERM_EXPECT(_mm512_test_epi8_mask( + if (WSAP_VTCORE_EXPECT(_mm512_test_epi8_mask( _mm512_xor_si512(in, _mm512_loadu_si512(utf8_3byte_want)), _mm512_loadu_si512(utf8_3byte_bits)) & UTF8_3BYTE_SPAN, 0)) return false; *cps = utf8_3byte_decode(_mm512_permutexvar_epi8(_mm512_loadu_si512(utf8_3byte_shuffle), in)); - if (_mm512_cmplt_epu32_mask(*cps, _mm512_set1_epi32((int)TERM_UTF8_3BYTE_MIN)) || + if (_mm512_cmplt_epu32_mask(*cps, _mm512_set1_epi32((int)WSAP_VTCORE_UTF8_3BYTE_MIN)) || _mm512_cmple_epu32_mask( - _mm512_sub_epi32(*cps, _mm512_set1_epi32((int)TERM_UTF8_SURROGATE_LO)), - _mm512_set1_epi32((int)(TERM_UTF8_SURROGATE_HI - TERM_UTF8_SURROGATE_LO)))) + _mm512_sub_epi32(*cps, _mm512_set1_epi32((int)WSAP_VTCORE_UTF8_SURROGATE_LO)), + _mm512_set1_epi32((int)(WSAP_VTCORE_UTF8_SURROGATE_HI - WSAP_VTCORE_UTF8_SURROGATE_LO)))) return false; __mmask16 covered = width_ranges_cover(ranges, *cps); - if (TERM_EXPECT(covered != 0xFFFF || wc->klass == 0, 0)) { + if (WSAP_VTCORE_EXPECT(covered != 0xFFFF || wc->klass == 0, 0)) { uint32_t cp[16]; _mm512_storeu_si512(cp, *cps); if (!width_cache_extend(wc, cp, covered)) return false; @@ -204,8 +204,8 @@ static inline bool classify_3byte_block(__m512i in, struct width_ranges *ranges, return true; } -TERM_TARGET_AVX512 -static TERM_NOINLINE int +WSAP_VTCORE_TARGET_AVX512 +static WSAP_VTCORE_NOINLINE int decode_3byte_blocks(uint64_t * restrict dst, const char * restrict buf, int len, int cols_left, __m512i base_wide_pair, __m512i base_narrow_quad, struct width_cache * restrict wc, @@ -241,8 +241,8 @@ decode_3byte_blocks(uint64_t * restrict dst, const char * restrict buf, int len, /* decode_3byte_blocks() that writes the history format: a narrow block * copies its 48 bytes, a wide block puts 0xF5 before each character. */ -TERM_TARGET_AVX512 -static TERM_NOINLINE int +WSAP_VTCORE_TARGET_AVX512 +static WSAP_VTCORE_NOINLINE int text_3byte_blocks(uint8_t * restrict dst, const char * restrict buf, int len, int cols_left, struct width_cache * restrict wc, int * restrict out_cols, int * restrict out_bytes, bool * restrict wide, uint32_t * restrict last_cp) @@ -286,19 +286,19 @@ text_3byte_blocks(uint8_t * restrict dst, const char * restrict buf, int len, in } #endif -struct text_run_bytes term_text_run_bytes(uint8_t *restrict dst, const char *restrict buf, int len, +struct text_run_bytes wsap_vtcore_text_run_bytes(uint8_t *restrict dst, const char *restrict buf, int len, int max_cols, uint32_t last, struct width_cache *restrict wc) { - if (TERM_EXPECT(last == 0x200D || term_grapheme_is_handle(last), 0)) + if (WSAP_VTCORE_EXPECT(last == 0x200D || wsap_vtcore_grapheme_is_handle(last), 0)) return (struct text_run_bytes){ .last = last, .narrow = true }; - /* Unlike term_text_run(), this fills up to the edge and up to the end of + /* Unlike wsap_vtcore_text_run(), this fills up to the edge and up to the end of * buf: the cells path writes those characters one by one with the same * result, and a text row should not settle for them. */ int i = 0, cx = 0, o = 0, chars = 0; bool wide = false, narrow = true; (void)wc; -#if defined(TERM_KERNEL_AVX512) - bool blocks = term_use_avx512(); +#if defined(WSAP_VTCORE_KERNEL_AVX512) + bool blocks = wsap_vtcore_use_avx512(); #endif while (i < len && cx < max_cols) { unsigned char c = (unsigned char)buf[i]; @@ -316,7 +316,7 @@ struct text_run_bytes term_text_run_bytes(uint8_t *restrict dst, const char *res } if (c < 0x20) break; -#if defined(TERM_KERNEL_AVX512) +#if defined(WSAP_VTCORE_KERNEL_AVX512) if ((c & UTF8_LEAD3_MASK) == UTF8_LEAD3_TAG && len - i >= 48 && max_cols - cx >= 32 && ((unsigned char)buf[i + 21] & UTF8_LEAD3_MASK) == UTF8_LEAD3_TAG && blocks) { int cols, bytes; @@ -335,10 +335,10 @@ struct text_run_bytes term_text_run_bytes(uint8_t *restrict dst, const char *res } #endif uint32_t cp; - int bytes = term_utf8_decode_one(buf + i, (size_t)(len - i), &cp); + int bytes = wsap_vtcore_utf8_decode_one(buf + i, (size_t)(len - i), &cp); if (!bytes) break; - int w = bytes < 4 ? unicode_fast_class[cp] : term_text_class(cp); + int w = bytes < 4 ? unicode_fast_class[cp] : wsap_vtcore_text_class(cp); if (w <= 0 || (bytes == 4 && can_extend_cluster(last, cp, w)) || cx + w > max_cols) break; if (w == 2) { @@ -356,8 +356,8 @@ struct text_run_bytes term_text_run_bytes(uint8_t *restrict dst, const char *res return (struct text_run_bytes){ i, cx, o, chars, last, wide, narrow }; } -#if defined(TERM_KERNEL_AVX512) -TERM_TARGET_AVX512 +#if defined(WSAP_VTCORE_KERNEL_AVX512) +WSAP_VTCORE_TARGET_AVX512 static inline __m512i wide_pair_base(uint32_t fg, uint32_t bg, uint32_t flags) { return _mm512_setr_epi32( @@ -367,7 +367,7 @@ static inline __m512i wide_pair_base(uint32_t fg, uint32_t bg, uint32_t flags) 0, fg, bg, (flags & ~CELL_WIDE) | CELL_TRAIL); } -TERM_TARGET_AVX512 +WSAP_VTCORE_TARGET_AVX512 static inline int try_3byte_blocks(uint64_t * restrict dst, const char * restrict buf, int len, int cols_left, uint32_t fg, uint32_t bg, uint32_t flags, struct width_cache * restrict wc, @@ -384,7 +384,7 @@ static inline int try_3byte_blocks(uint64_t * restrict dst, const char * restric } /* Two wide cells side by side: cp and next_cp. */ -TERM_TARGET_AVX512 +WSAP_VTCORE_TARGET_AVX512 static inline void store_wide_pair(uint64_t *dst, uint32_t fg, uint32_t bg, uint32_t flags, uint32_t cp, uint32_t next_cp) { @@ -457,14 +457,14 @@ static inline uint64_t *store_cell_wide(uint64_t * restrict dst, return dst + 4; } -#if defined(TERM_KERNEL_AVX2) +#if defined(WSAP_VTCORE_KERNEL_AVX2) /* * Decode runs of 3-byte UTF-8 four code points at a time. A quad stops the * run when a byte is not a 3-byte sequence, a code point is overlong or a * surrogate, or a code point has no fast width class. The scalar loop then * handles that code point, so both paths store the same cells. */ -TERM_TARGET_AVX2 +WSAP_VTCORE_TARGET_AVX2 static inline int decode_3byte_quads(uint64_t **dst_io, const char *buf, int len, int cols_left, const struct cell_bases *b, int *out_cols, uint32_t *last) @@ -493,9 +493,9 @@ static inline int decode_3byte_quads(uint64_t **dst_io, const char *buf, int len _mm_and_si128(_mm_srli_epi32(packed, 2), _mm_set1_epi32(0x0FC0))), _mm_and_si128(_mm_srli_epi32(packed, 4), _mm_set1_epi32(0xF000))); __m128i bad = _mm_or_si128( - _mm_cmplt_epi32(cps, _mm_set1_epi32((int)TERM_UTF8_3BYTE_MIN)), + _mm_cmplt_epi32(cps, _mm_set1_epi32((int)WSAP_VTCORE_UTF8_3BYTE_MIN)), _mm_cmpeq_epi32(_mm_and_si128(cps, _mm_set1_epi32(0xF800)), - _mm_set1_epi32((int)TERM_UTF8_SURROGATE_LO))); + _mm_set1_epi32((int)WSAP_VTCORE_UTF8_SURROGATE_LO))); if (_mm_movemask_epi8(bad)) break; alignas(16) uint32_t cp[4]; @@ -523,14 +523,14 @@ static inline int decode_3byte_quads(uint64_t **dst_io, const char *buf, int len /* One body for every level. isa is a constant in each copy below, so each * copy keeps only its own kernels. */ -static inline TERM_ALWAYS_INLINE struct text_run_result +static inline WSAP_VTCORE_ALWAYS_INLINE struct text_run_result text_run_body(struct cell *restrict row, const char *restrict buf, int len, int max_cols, uint32_t fg, uint32_t bg, uint32_t flags, uint32_t last, struct width_cache *restrict wc, int isa) { int i = 0; int cx = 0; - if (TERM_EXPECT(last == 0x200D || term_grapheme_is_handle(last), 0)) + if (WSAP_VTCORE_EXPECT(last == 0x200D || wsap_vtcore_grapheme_is_handle(last), 0)) return (struct text_run_result){0, 0, last}; const struct cell_bases bases = cell_bases_make(fg, bg, flags); @@ -538,8 +538,8 @@ text_run_body(struct cell *restrict row, const char *restrict buf, int len, int (void)wc; (void)isa; -#if defined(TERM_KERNEL_AVX512) - if (isa == TERM_ISA_AVX512) { +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (isa == WSAP_VTCORE_ISA_AVX512) { int cols; i += try_3byte_blocks(dst, buf, len, max_cols, fg, bg, flags, wc, &cols, &last); cx += cols; @@ -563,8 +563,8 @@ text_run_body(struct cell *restrict row, const char *restrict buf, int len, int cx++; i++; } -#if defined(TERM_KERNEL_AVX512) - if (isa == TERM_ISA_AVX512 && ascii_at == 0) { +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (isa == WSAP_VTCORE_ISA_AVX512 && ascii_at == 0) { int cols; i += try_3byte_blocks(dst, buf + i, len - i, max_cols - cx, fg, bg, flags, wc, &cols, &last); @@ -579,9 +579,9 @@ text_run_body(struct cell *restrict row, const char *restrict buf, int len, int break; } -#if defined(TERM_KERNEL_AVX2) - if (isa == TERM_ISA_AVX2 && - TERM_EXPECT((c & UTF8_LEAD3_MASK) == UTF8_LEAD3_TAG && i + 16 <= len && +#if defined(WSAP_VTCORE_KERNEL_AVX2) + if (isa == WSAP_VTCORE_ISA_AVX2 && + WSAP_VTCORE_EXPECT((c & UTF8_LEAD3_MASK) == UTF8_LEAD3_TAG && i + 16 <= len && ((unsigned char)buf[i + 9] & UTF8_LEAD3_MASK) == UTF8_LEAD3_TAG, 0)) { int cols; int used = decode_3byte_quads(&dst, buf + i, len - i, max_cols - cx, @@ -593,14 +593,14 @@ text_run_body(struct cell *restrict row, const char *restrict buf, int len, int } #endif uint32_t cp; - int bytes = term_utf8_decode_one(buf + i, (size_t)(len - i), &cp); + int bytes = wsap_vtcore_utf8_decode_one(buf + i, (size_t)(len - i), &cp); if (!bytes) break; - int w = bytes < 4 ? unicode_fast_class[cp] : term_text_class(cp); + int w = bytes < 4 ? unicode_fast_class[cp] : wsap_vtcore_text_class(cp); if (w <= 0 || (bytes == 4 && can_extend_cluster(last, cp, w))) break; -#if defined(TERM_KERNEL_AVX512) - if (isa == TERM_ISA_AVX512 && bytes == 3 && w == 2 && i + 6 <= len && cx + 4 <= max_cols) { +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (isa == WSAP_VTCORE_ISA_AVX512 && bytes == 3 && w == 2 && i + 6 <= len && cx + 4 <= max_cols) { uint32_t next_cp; - if (term_utf8_decode_one(buf + i + 3, (size_t)(len - i - 3), &next_cp) == 3 && + if (wsap_vtcore_utf8_decode_one(buf + i + 3, (size_t)(len - i - 3), &next_cp) == 3 && unicode_fast_class[next_cp] == 2) { store_wide_pair(dst, fg, bg, flags, cp, next_cp); dst += 8; @@ -630,35 +630,35 @@ text_run_body(struct cell *restrict row, const char *restrict buf, int len, int struct width_cache *restrict wc #define TEXT_RUN_ARGS row, buf, len, max_cols, fg, bg, flags, last, wc -#if defined(TERM_KERNEL_AVX512) -TERM_TARGET_AVX512 -static TERM_NOINLINE struct text_run_result text_run_avx512(TEXT_RUN_PARAMS) +#if defined(WSAP_VTCORE_KERNEL_AVX512) +WSAP_VTCORE_TARGET_AVX512 +static WSAP_VTCORE_NOINLINE struct text_run_result text_run_avx512(TEXT_RUN_PARAMS) { - return text_run_body(TEXT_RUN_ARGS, TERM_ISA_AVX512); + return text_run_body(TEXT_RUN_ARGS, WSAP_VTCORE_ISA_AVX512); } #endif -#if defined(TERM_KERNEL_AVX2) -TERM_TARGET_AVX2 -static TERM_NOINLINE struct text_run_result text_run_avx2(TEXT_RUN_PARAMS) +#if defined(WSAP_VTCORE_KERNEL_AVX2) +WSAP_VTCORE_TARGET_AVX2 +static WSAP_VTCORE_NOINLINE struct text_run_result text_run_avx2(TEXT_RUN_PARAMS) { - return text_run_body(TEXT_RUN_ARGS, TERM_ISA_AVX2); + return text_run_body(TEXT_RUN_ARGS, WSAP_VTCORE_ISA_AVX2); } #endif -static TERM_NOINLINE struct text_run_result text_run_base(TEXT_RUN_PARAMS) +static WSAP_VTCORE_NOINLINE struct text_run_result text_run_base(TEXT_RUN_PARAMS) { - return text_run_body(TEXT_RUN_ARGS, TERM_ISA_BASE); + return text_run_body(TEXT_RUN_ARGS, WSAP_VTCORE_ISA_BASE); } -struct text_run_result term_text_run(TEXT_RUN_PARAMS) +struct text_run_result wsap_vtcore_text_run(TEXT_RUN_PARAMS) { -#if defined(TERM_KERNEL_AVX512) - if (term_use_avx512()) +#if defined(WSAP_VTCORE_KERNEL_AVX512) + if (wsap_vtcore_use_avx512()) return text_run_avx512(TEXT_RUN_ARGS); #endif -#if defined(TERM_KERNEL_AVX2) - if (term_use_avx2()) +#if defined(WSAP_VTCORE_KERNEL_AVX2) + if (wsap_vtcore_use_avx2()) return text_run_avx2(TEXT_RUN_ARGS); #endif return text_run_base(TEXT_RUN_ARGS); diff --git a/src/text_run.h b/src/text_run.h index 3ff432b..630c1c7 100644 --- a/src/text_run.h +++ b/src/text_run.h @@ -1,5 +1,5 @@ -#ifndef TERM_TEXT_RUN_H -#define TERM_TEXT_RUN_H +#ifndef WSAP_VTCORE_TEXT_RUN_H +#define WSAP_VTCORE_TEXT_RUN_H #include "cell.h" #include "unicode/unicode.h" @@ -10,19 +10,19 @@ #define UTF8_LEAD3_TAG 0xE0 #define UTF8_LEAD3_MASK 0xF0 -#define TERM_WIDTH_SLOTS 4 +#define WSAP_VTCORE_WIDTH_SLOTS 4 struct width_cache { - uint32_t lo[TERM_WIDTH_SLOTS]; - uint32_t span[TERM_WIDTH_SLOTS]; + uint32_t lo[WSAP_VTCORE_WIDTH_SLOTS]; + uint32_t span[WSAP_VTCORE_WIDTH_SLOTS]; uint8_t klass; uint8_t next; }; -/* term_new() builds the shared tables before any terminal can use them. */ -bool term_tables_ready(void); -void term_text_tables_init(void); +/* wsap_vtcore_new() builds the shared tables before any terminal can use them. */ +bool wsap_vtcore_tables_ready(void); +void wsap_vtcore_text_tables_init(void); -int term_text_class(uint32_t cp); +int wsap_vtcore_text_class(uint32_t cp); struct text_run_result { int bytes; @@ -30,7 +30,7 @@ struct text_run_result { uint32_t last; }; -struct text_run_result term_text_run(struct cell *restrict row, const char *restrict buf, +struct text_run_result wsap_vtcore_text_run(struct cell *restrict row, const char *restrict buf, int len, int max_cols, uint32_t fg, uint32_t bg, uint32_t flags, uint32_t last, struct width_cache *restrict wc); @@ -43,35 +43,35 @@ struct text_run_bytes { bool wide, narrow; /* narrow: every character was one ASCII byte */ }; -/* term_text_run() with the same rules, that writes the text in the history +/* wsap_vtcore_text_run() with the same rules, that writes the text in the history * format instead of cells: raw UTF-8, a wide character after 0xF5. dst has * room for 4 bytes per column. */ -struct text_run_bytes term_text_run_bytes(uint8_t *restrict dst, const char *restrict buf, int len, +struct text_run_bytes wsap_vtcore_text_run_bytes(uint8_t *restrict dst, const char *restrict buf, int len, int max_cols, uint32_t last, struct width_cache *restrict wc); static inline bool joins_cluster(uint32_t cp, int klass) { if (cp < 0x0300) return false; - if (klass == 0 || term_grapheme_emoji_modifier(cp)) + if (klass == 0 || wsap_vtcore_grapheme_emoji_modifier(cp)) return true; - return klass == 1 && term_unicode_spacing_mark(cp); + return klass == 1 && wsap_vtcore_unicode_spacing_mark(cp); } static inline bool can_extend_cluster(uint32_t last_char, uint32_t cp, int klass) { if (klass == 0) return true; - if (last_char == 0x200D || term_grapheme_is_handle(last_char)) return true; - if (cp - 0x1F1E6u <= 0x19u && term_grapheme_regional_indicator(cp)) + if (last_char == 0x200D || wsap_vtcore_grapheme_is_handle(last_char)) return true; + if (cp - 0x1F1E6u <= 0x19u && wsap_vtcore_grapheme_regional_indicator(cp)) return true; return joins_cluster(cp, klass); } static inline bool cluster_contextual(uint32_t cp) { - return term_unicode_spacing_mark(cp) || term_grapheme_emoji_modifier(cp) || - (cp - 0x1F1E6u <= 0x19u && term_grapheme_regional_indicator(cp)); + return wsap_vtcore_unicode_spacing_mark(cp) || wsap_vtcore_grapheme_emoji_modifier(cp) || + (cp - 0x1F1E6u <= 0x19u && wsap_vtcore_grapheme_regional_indicator(cp)); } static inline bool cluster_joins(const uint32_t *cps, int len, @@ -80,10 +80,10 @@ static inline bool cluster_joins(const uint32_t *cps, int len, if (joins_cluster(cp, klass)) return true; if (cps[len - 1] == 0x200D) - return term_unicode_extended_pictographic(cp); + return wsap_vtcore_unicode_extended_pictographic(cp); return len == 1 && cp - 0x1F1E6u <= 0x19u && - term_grapheme_regional_indicator(cp) && - term_grapheme_regional_indicator(cps[0]); + wsap_vtcore_grapheme_regional_indicator(cp) && + wsap_vtcore_grapheme_regional_indicator(cps[0]); } #endif |
