diff options
| author | eunhhu <[email protected]> | 2026-09-26 11:08:29 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-26 11:08:29 +0100 |
| commit | 0054ea8452a811f2745d72ce4b7764ea158f1d5f (patch) | |
| tree | 62fef2445feedd1a8f679ee7255944b80dc0dc88 /src/screen.c | |
| parent | f6be15d01ac184f070e1bb34af12689f68eb9140 (diff) | |
| download | vega-0054ea8452a811f2745d72ce4b7764ea158f1d5f.tar.gz vega-0054ea8452a811f2745d72ce4b7764ea158f1d5f.zip | |
Add a web surface: the same spec as a page
vega web MODULE serves the screen to a browser (127.0.0.1 unless given
--listen): one dependency-free page draws the title, fields, lists as
listboxes and tables, with tones as colors and the focus highlighted. It
asks for the screen as JSON with the rows it can show per list or table,
so only those cells are evaluated, scrolled like the TUI around the
focus. Keys go as KeyboardEvent.code, which is Pure's key naming already;
typed text commits with Enter; a click or the wheel moves the focus
through pure_app_point; an event stream tells every open page of each
change. Scrolling, key presses and text commits are now shared helpers.
The checks drive it against the model (1,200 random steps: title, field,
rows, focus, the window of items with badges and tones), check a table's
columns and cells, post at random to every example, and in headless
Chromium over the DevTools protocol press keys, click a row and type
Korean text into the page itself.
Diffstat (limited to 'src/screen.c')
| -rw-r--r-- | src/screen.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/screen.c b/src/screen.c index 3e8b2c4..bb50de1 100644 --- a/src/screen.c +++ b/src/screen.c @@ -157,6 +157,32 @@ size_t vega_focus(PureApp *app, const VegaPart *part) { return focus >= (double)(rows - 1) ? rows - 1 : (size_t)focus; } +size_t vega_scroll(size_t first, size_t focus, size_t visible, size_t rows) { + if (focus < first) first = focus; + if (visible && focus >= first + visible) first = focus - visible + 1; + if (first + visible > rows) first = rows > visible ? rows - visible : 0; + return first; +} + +int vega_key_input(const PureModule *m, const char *key) { + for (uint32_t i = 0; i < m->inputs; ++i) + if (m->input[i].kind == PURE_KIND_KEY && !strcmp(m->input_keys[i], key)) return (int)i; + return -1; +} + +bool vega_press(PureApp *app, const char *key) { + int input = vega_key_input(app->module, key); + if (input < 0) return false; + bool ok = pure_app_input(app, (uint32_t)input, PURE_EDGE_DOWN) == PURE_OK; + pure_app_input(app, (uint32_t)input, PURE_EDGE_UP); + return ok; +} + +bool vega_commit(PureApp *app, const VegaScreen *screen, const char *text, size_t length) { + return screen->prompt >= 0 && + pure_app_text(app, (uint32_t)screen->prompt, (PureSpan){(const unsigned char *)text, length}) == PURE_OK; +} + bool vega_point(PureApp *app, const VegaPart *part, size_t row) { return part->pointer >= 0 && pure_app_point(app, (uint32_t)part->pointer, row) == PURE_OK; } |
