diff options
Diffstat (limited to 'tests/extern/kitty')
| -rw-r--r-- | tests/extern/kitty/.gitignore | 2 | ||||
| -rw-r--r-- | tests/extern/kitty/screen.py | 54 | ||||
| -rw-r--r-- | tests/extern/kitty/screen_bridge.c | 72 |
3 files changed, 64 insertions, 64 deletions
diff --git a/tests/extern/kitty/.gitignore b/tests/extern/kitty/.gitignore index 79a6f1c..42be567 100644 --- a/tests/extern/kitty/.gitignore +++ b/tests/extern/kitty/.gitignore @@ -1,2 +1,2 @@ __pycache__/ -libterm.so +libkitty_bridge.so diff --git a/tests/extern/kitty/screen.py b/tests/extern/kitty/screen.py index a3336d8..1b66234 100644 --- a/tests/extern/kitty/screen.py +++ b/tests/extern/kitty/screen.py @@ -1,9 +1,9 @@ """ctypes wrapper providing the Kitty ``Screen`` API on top of our C terminal. -The shared library ``libterm.so`` is loaded via :mod:`ctypes`. Python calls -only the ``kitty_*`` functions of ``screen_bridge.c``, which wrap the public -API (declared in ``src/term/term.h``). Python classes on top of them match the -subset of Kitty's test API used by ``parser.py``. +The bridge library ``libkitty_bridge.so`` is loaded via :mod:`ctypes`. Python +calls only the ``kitty_*`` functions of ``screen_bridge.c``, which wrap the +public API (declared in ``include/wsap_vtcore/wsap_vtcore.h``). Python classes +on top of them match the subset of Kitty's test API used by ``parser.py``. """ import ctypes @@ -15,7 +15,7 @@ import os _lib = ctypes.CDLL(os.environ.get('WSAP_KITTY_LIB', os.path.join(os.path.dirname(__file__), 'libkitty_bridge.so'))) -# struct term_cell { uint32_t text, fg, bg; uint16_t attrs; uint8_t width, reserved; } +# struct wsap_vtcore_cell { uint32_t text, fg, bg; uint16_t attrs; uint8_t width, reserved; } class TermCell(ctypes.Structure): _fields_ = [ ('text', ctypes.c_uint32), @@ -65,19 +65,19 @@ for _name, _type in { # Constants # --------------------------------------------------------------------------- -TERM_DEFAULT_FG = 0xFFFFFFFF -TERM_DEFAULT_BG = 0xFF1E1E2E +WSAP_VTCORE_DEFAULT_FG = 0xFFFFFFFF +WSAP_VTCORE_DEFAULT_BG = 0xFF1E1E2E -# Cell attributes (must match enum term_attr in term.h) -TERM_ATTR_BOLD = 1 << 0 -TERM_ATTR_ITALIC = 1 << 1 -TERM_ATTR_FAINT = 1 << 10 -TERM_ATTR_STRIKE = 1 << 3 -TERM_ATTR_OVERLINE = 1 << 4 -TERM_ATTR_LINK = 1 << 15 -TERM_ATTR_EMOJI = 1 << 5 -TERM_ATTR_TEXT = 1 << 6 -TERM_UNDERLINE_FLAGS = (1 << 2, 1 << 11, 1 << 12, 1 << 13, 1 << 14) +# Cell attributes (must match enum wsap_vtcore_attr in wsap_vtcore.h) +WSAP_VTCORE_ATTR_BOLD = 1 << 0 +WSAP_VTCORE_ATTR_ITALIC = 1 << 1 +WSAP_VTCORE_ATTR_FAINT = 1 << 10 +WSAP_VTCORE_ATTR_STRIKE = 1 << 3 +WSAP_VTCORE_ATTR_OVERLINE = 1 << 4 +WSAP_VTCORE_ATTR_LINK = 1 << 15 +WSAP_VTCORE_ATTR_EMOJI = 1 << 5 +WSAP_VTCORE_ATTR_TEXT = 1 << 6 +WSAP_VTCORE_UNDERLINE_FLAGS = (1 << 2, 1 << 11, 1 << 12, 1 << 13, 1 << 14) # The longest grapheme cluster that a cell's text is read with. _CLUSTER_CAP = 32 @@ -105,7 +105,7 @@ _lib.kitty_screen_cell_is_tab.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes. _lib.kitty_screen_cell_is_tab.restype = ctypes.c_bool # ANSI color table from escape.c — used for reverse-mapping to Kitty indices. -# Must match the built-in default palette in src/term/palette.c. +# Must match the built-in default palette in src/palette.c. _ANSI_COLORS = [ 0xFF585B70, 0xFFCC6666, 0xFFB5BD68, 0xFFF0C674, 0xFF81A2BE, 0xFFB294BB, 0xFF8ABEB7, 0xFFC5C8C6, @@ -135,7 +135,7 @@ def _build_color_table(): _COLOR_TO_KITTY = _build_color_table() -TERM_COLOR_REF = 0x01000000 +WSAP_VTCORE_COLOR_REF = 0x01000000 def _convert_color(color): @@ -149,10 +149,10 @@ def _convert_color(color): index<<8|1 = indexed (0-255) r<<24|g<<16|b<<8|2 = RGB """ - if (color >> 24) == (TERM_COLOR_REF >> 24): + if (color >> 24) == (WSAP_VTCORE_COLOR_REF >> 24): slot = color & 0x1FF return 0 if slot >= 0x100 else (slot << 8) | 1 - if color == TERM_DEFAULT_FG or color == TERM_DEFAULT_BG: + if color == WSAP_VTCORE_DEFAULT_FG or color == WSAP_VTCORE_DEFAULT_BG: return 0 kitty = _COLOR_TO_KITTY.get(color) if kitty is not None: @@ -251,15 +251,15 @@ class CellCursor: @property def bold(self): - return bool(self._cell.attrs & TERM_ATTR_BOLD) + return bool(self._cell.attrs & WSAP_VTCORE_ATTR_BOLD) @property def italic(self): - return bool(self._cell.attrs & TERM_ATTR_ITALIC) + return bool(self._cell.attrs & WSAP_VTCORE_ATTR_ITALIC) @property def dim(self): - return bool(self._cell.attrs & TERM_ATTR_FAINT) + return bool(self._cell.attrs & WSAP_VTCORE_ATTR_FAINT) @property def reverse(self): @@ -269,13 +269,13 @@ class CellCursor: @property def strikethrough(self): - return bool(self._cell.attrs & TERM_ATTR_STRIKE) + return bool(self._cell.attrs & WSAP_VTCORE_ATTR_STRIKE) @property def decoration(self): - # enum term_underline uses Kitty's numbers: 0=none, 1=straight, + # enum wsap_vtcore_underline uses Kitty's numbers: 0=none, 1=straight, # 2=double, 3=curly, 4=dotted, 5=dashed. - return next((i for i, flag in enumerate(TERM_UNDERLINE_FLAGS, 1) + return next((i for i, flag in enumerate(WSAP_VTCORE_UNDERLINE_FLAGS, 1) if self._cell.attrs & flag), 0) @property diff --git a/tests/extern/kitty/screen_bridge.c b/tests/extern/kitty/screen_bridge.c index 50f86a7..c307c1a 100644 --- a/tests/extern/kitty/screen_bridge.c +++ b/tests/extern/kitty/screen_bridge.c @@ -1,87 +1,87 @@ /* Test-only entry points for the Kitty screen wrapper in screen.py. * Python calls only these functions, so it needs no struct layouts other - * than the public struct term_cell. The kitty_screen_* accessors read - * properties that term.h does not expose. They compile against the current + * than the public struct wsap_vtcore_cell. The kitty_screen_* accessors read + * properties that wsap_vtcore.h does not expose. They compile against the current * terminal layout rather than duplicating byte offsets in Python. */ #include "internal.h" #include "screen.h" typedef void (*kitty_reply_fn)(void *ud, const char *bytes, size_t len); -struct term *kitty_term_new(int cols, int rows, kitty_reply_fn reply, void *ud) +struct wsap_vtcore *kitty_term_new(int cols, int rows, kitty_reply_fn reply, void *ud) { - return term_new(&(struct term_options){ + return wsap_vtcore_new(&(struct wsap_vtcore_options){ .size = { .x = cols, .y = rows }, .callbacks = { .ud = ud, .reply = reply }, }); } /* One snapshot serves every cell read. */ -static struct term_snapshot *snap; +static struct wsap_vtcore_snapshot *snap; -void kitty_term_free(struct term *t) +void kitty_term_free(struct wsap_vtcore *t) { /* A new terminal can get the address of the freed one. The snapshot * would then keep its rows, so it goes away too. */ - term_snapshot_free(snap); + wsap_vtcore_snapshot_free(snap); snap = NULL; - term_free(t); + wsap_vtcore_free(t); } -void kitty_term_write(struct term *t, const char *bytes, size_t len) +void kitty_term_write(struct wsap_vtcore *t, const char *bytes, size_t len) { - term_feed(t, bytes, len, 0); + wsap_vtcore_feed(t, bytes, len, 0); } -bool kitty_term_resize(struct term *t, int cols, int rows) +bool kitty_term_resize(struct wsap_vtcore *t, int cols, int rows) { - return term_resize(t, (struct term_vector2i){ .x = cols, .y = rows }); + return wsap_vtcore_resize(t, (struct wsap_vtcore_vector2i){ .x = cols, .y = rows }); } -int kitty_term_cols(struct term *t) { return term_size(t).x; } -int kitty_term_rows(struct term *t) { return term_size(t).y; } -int kitty_term_cursor_x(struct term *t) { return term_cursor(t).pos.x; } -int kitty_term_cursor_y(struct term *t) { return term_cursor(t).pos.y; } -int kitty_term_cursor_style(struct term *t) { return (int)term_cursor(t).style; } -bool kitty_term_cursor_blink(struct term *t) { return term_cursor(t).blink; } -bool kitty_term_application_cursor(struct term *t) { return term_modes(t).app_cursor; } +int kitty_term_cols(struct wsap_vtcore *t) { return wsap_vtcore_size(t).x; } +int kitty_term_rows(struct wsap_vtcore *t) { return wsap_vtcore_size(t).y; } +int kitty_term_cursor_x(struct wsap_vtcore *t) { return wsap_vtcore_cursor(t).pos.x; } +int kitty_term_cursor_y(struct wsap_vtcore *t) { return wsap_vtcore_cursor(t).pos.y; } +int kitty_term_cursor_style(struct wsap_vtcore *t) { return (int)wsap_vtcore_cursor(t).style; } +bool kitty_term_cursor_blink(struct wsap_vtcore *t) { return wsap_vtcore_cursor(t).blink; } +bool kitty_term_application_cursor(struct wsap_vtcore *t) { return wsap_vtcore_modes(t).app_cursor; } /* Update the snapshot from the live screen, as a renderer reads it. * Returns NULL when the cell is out of range or memory runs out. */ -static struct term_snapshot *cell_snapshot(struct term *t, int col, int row) +static struct wsap_vtcore_snapshot *cell_snapshot(struct wsap_vtcore *t, int col, int row) { - struct term_vector2i size = term_size(t); + struct wsap_vtcore_vector2i size = wsap_vtcore_size(t); if (col < 0 || col >= size.x || row < 0 || row >= size.y) return NULL; if (!snap) - snap = term_snapshot_new(); - term_scroll_to(t, 0); - if (!snap || !term_snapshot_update(snap, t)) + snap = wsap_vtcore_snapshot_new(); + wsap_vtcore_scroll_to(t, 0); + if (!snap || !wsap_vtcore_snapshot_update(snap, t)) return NULL; return snap; } -bool kitty_term_cell(struct term *t, int col, int row, struct term_cell *out) +bool kitty_term_cell(struct wsap_vtcore *t, int col, int row, struct wsap_vtcore_cell *out) { - struct term_snapshot *s = cell_snapshot(t, col, row); + struct wsap_vtcore_snapshot *s = cell_snapshot(t, col, row); if (!s) return false; - *out = term_snapshot_row(s, row)[col]; + *out = wsap_vtcore_snapshot_row(s, row)[col]; return true; } /* The code points of a cell's text: one, or a whole grapheme cluster. * Returns the number of code points and writes at most cap of them. */ -int kitty_term_cell_text(struct term *t, int col, int row, uint32_t *cps, int cap) +int kitty_term_cell_text(struct wsap_vtcore *t, int col, int row, uint32_t *cps, int cap) { - struct term_snapshot *s = cell_snapshot(t, col, row); + struct wsap_vtcore_snapshot *s = cell_snapshot(t, col, row); if (!s) return 0; - return term_snapshot_cluster(s, term_snapshot_row(s, row)[col].text, cps, cap); + return wsap_vtcore_snapshot_cluster(s, wsap_vtcore_snapshot_row(s, row)[col].text, cps, cap); } #define PROPERTY(type, name) \ - type kitty_screen_##name(struct term *t) { return t->name; } + type kitty_screen_##name(struct wsap_vtcore *t) { return t->name; } PROPERTY(int, scroll_top) PROPERTY(int, scroll_bottom) @@ -94,20 +94,20 @@ PROPERTY(bool, strike) PROPERTY(bool, inverse) PROPERTY(uint8_t, underline) -int kitty_screen_row_length(struct term *t, int row) +int kitty_screen_row_length(struct wsap_vtcore *t, int row) { if (!t || row < 0 || row >= t->rows) return 0; - const struct srow *r = term_row(t, row); + const struct srow *r = wsap_vtcore_row(t, row); return r ? (int)r->len : 0; } /* A tab stores a marker cell that a snapshot shows as a blank. Kitty keeps * the tab in its line text, so the wrapper asks for the marker. */ -bool kitty_screen_cell_is_tab(struct term *t, int col, int row) +bool kitty_screen_cell_is_tab(struct wsap_vtcore *t, int col, int row) { if (col < 0 || col >= t->cols || row < 0 || row >= t->rows) return false; - term_scroll_to(t, 0); - const struct cell *cells = term_screen_view_row(t, row); + wsap_vtcore_scroll_to(t, 0); + const struct cell *cells = wsap_vtcore_screen_view_row(t, row); return cells && cells[col].c == '\t'; } |
