summaryrefslogtreecommitdiff
path: root/src/kinds
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 06:24:42 -0300
committerGabriel Schneider <[email protected]>2026-11-06 11:19:32 -0300
commit0893d632e242553390d968751fff0e880627c34a (patch)
tree154e40245fd97bf399efa2cc99872b5a48b1d0a0 /src/kinds
parent7ccbb0fa852e327b6663ba933f134d5013484007 (diff)
downloadpardes-0893d632e242553390d968751fff0e880627c34a.tar.gz
pardes-0893d632e242553390d968751fff0e880627c34a.zip
kinds #12, ABI 2.1: pardes_addon.h grows at the ends of its records (pa_api's heap, view, exec and select, pa_paint's rail thumb, pa_ops's search, PA_WHEEL_LEFT and RIGHT) and the core reads them only from a 2.1 head: Esc goes to a 2.1 kind first, a press's drag and release stay its own and the pointer leaving is told, tick comes again on a view change, a kind's search rows, place, Exec and selection are taped, the jobs a call asks are emitted on every core from its taped outcome, a Shadow lays its tag out from the authority's prefix and keeps its tick state when it joins, a view's raster is its frontend's, and fake.c and snake.c leave Esc to the core
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/kinds')
-rw-r--r--src/kinds/pardes_addon.h65
1 files changed, 53 insertions, 12 deletions
diff --git a/src/kinds/pardes_addon.h b/src/kinds/pardes_addon.h
index 6241c6c0..e7334063 100644
--- a/src/kinds/pardes_addon.h
+++ b/src/kinds/pardes_addon.h
@@ -16,7 +16,9 @@
* Conventions: init, ctl and load return PA_OK (0), or nonzero to refuse;
* key, mouse and address return nonzero when the event or text was theirs.
* The pa_api pointer handed to init is kept by the addon; it is about the
- * pane of the current call.
+ * pane of the current call. ABI 2.1 adds fields at the ends of pa_api,
+ * pa_paint and pa_ops: a core reads an addon's new ones by its head's
+ * minor, an addon pardes's by api->size.
*
* addons/fake/fake.c implements every function; it is the template, and
* addons/snake/snake.c a game in it.
@@ -30,7 +32,7 @@
/* Major in the high half: an addon of another major is refused. */
#define PA_ABI_MAJOR 2u
-#define PA_ABI_MINOR 0u
+#define PA_ABI_MINOR 1u
#define PA_ABI ((PA_ABI_MAJOR << 16) | PA_ABI_MINOR)
#define PA_OK 0
@@ -101,12 +103,16 @@ typedef struct pa_placement {
* core follows with one space, its own words for a picture shown
* (`petscii:on palette:commodore ascii:off`, when this frame placed one),
* and the pane's path; empty, the kind's name. paint is called once a
- * frame, body and prefix together, never over no cells. */
+ * frame, body and prefix together, never over no cells. 2.1: `at` and
+ * `span`, where the window is in the pane's whole (the share above it and
+ * the share it shows, 0 to 1), are the rail's thumb; 0 and 0, none. A kind
+ * writes them only to a core whose api->size says 2.1. */
typedef struct pa_paint {
pa_placement *placements;
uint32_t cap, n;
char prefix[96];
uint32_t prefix_len;
+ float at, span;
} pa_paint;
/* ---- input ---- */
@@ -134,11 +140,14 @@ typedef struct pa_key {
#define PA_RIGHT 2
#define PA_WHEEL_UP 3
#define PA_WHEEL_DOWN 4
+#define PA_WHEEL_LEFT 5
+#define PA_WHEEL_RIGHT 6
#define PA_PRESS 0
#define PA_RELEASE 1
#define PA_MOTION 2
#define PA_DRAG 3
-/* A pointer event in the window's cells. */
+/* A pointer event in the window's cells; a motion at col and row 0xffff
+ * when the pointer leaves the window. */
typedef struct pa_mouse {
uint8_t button, action, ctrl, shift, alt, pad;
uint16_t col, row;
@@ -146,6 +155,17 @@ typedef struct pa_mouse {
/* ---- what pardes does for an addon ---- */
+/* The pane as its next paint will see it (2.1, api->view): its window, a
+ * cell's pixels; the theme's text, paper, selection and link colours
+ * (PA_RGB); and the raster a picture is wanted at: `dpi`, at most `max_px`
+ * a side, and never smaller than the pixels it covers when `fill` is set. */
+typedef struct pa_view {
+ uint16_t cols, rows, cell_w, cell_h;
+ uint32_t fg, bg, sel, link;
+ uint16_t dpi, max_px;
+ uint8_t fill, pad[3];
+} pa_view;
+
/* Valid during any call pardes makes for a pane, and about that pane. */
typedef struct pa_api {
uint32_t size;
@@ -165,6 +185,17 @@ typedef struct pa_api {
/* The pane's seed: the same pane, the same number, on every machine (a
* game's board), and what `pardes --addon-test`'s `seed N` sets. */
uint64_t (*seed)(void);
+ /* 2.1 (api->size >= 96): memory of pardes's that outlives a call, as
+ * realloc's (n 0 frees it), on any thread at any time: what a pane's
+ * arena cannot hold, a cache, a library's own heap. */
+ void *(*heap)(void *ptr, size_t n);
+ /* The pane's window and the theme now (pa_view). */
+ void (*view)(pa_view *out);
+ /* Run `text` as a middle click would. */
+ void (*exec)(const char *text, uint32_t n);
+ /* The text the pane has selected now, which a yank, a chord's Snarf and
+ * a keyboard Look take; n 0, none. */
+ void (*select)(const char *text, uint32_t n);
} pa_api;
/* What a job allocates from, on its worker (pa_api is not there): as often
@@ -222,22 +253,29 @@ typedef struct pa_ops {
/* Time has come to now_ns (monotonic, any origin; --addon-test's starts
* at 1 s): step, and return the absolute time of the next step, 0 for
* none. Called when that time comes and once after open, a taken key or
- * mouse, ctl, job_done, load, and a change of PA_FOCUSED in `flags`: a
- * kind that returned 0 is woken by the next thing that happens to it.
+ * mouse, ctl, job_done, load, and a change of PA_FOCUSED in `flags` (2.1:
+ * or of its pa_view): a kind that returned 0 is woken by the next thing
+ * that happens to it.
* Absent, the pane repaints when the core repaints. */
uint64_t (*tick)(void *st, uint64_t now_ns, uint32_t flags);
/* Required. Pure: the same state paints the same, and changes nothing. */
void (*paint)(void *st, const pa_window *win, pa_paint *out);
/* Every key but Esc, which leaves; nonzero if taken. A key not taken goes
- * to the editor's own navigation. Absent: no keys. */
+ * to the editor's own navigation. Absent: no keys. 2.1: Esc too, first;
+ * not taken, it leaves. */
int (*key)(void *st, const pa_key *k);
/* Nonzero if taken. Absent: a click focuses the pane. */
int (*mouse)(void *st, const pa_mouse *m);
/* The pane's body as text (9P `body`). Absent: empty. */
uint64_t (*body_len)(void *st);
uint32_t (*body)(void *st, uint64_t off, char *buf, uint32_t n);
- /* Go to `text` (`:12`, `12:0.33`); nonzero if it is a place here. And
- * where the pane is now, as such a text (jumps, Recent, a Restore). */
+ /* Go to `text` (`:12`, `12:0.33`); nonzero if it is a place here (a miss
+ * may `say` why, an error). A place looked at in a list the kind made
+ * (`text`) comes as `<name> <place>`. And where the pane is now, as such
+ * a text (jumps, Recent, a Restore): `L` or `L:F`, its first number a
+ * line's and F how far into it, then, after a space, the window's height
+ * in lines if it has one: two places within it are one visit of the
+ * jumps. */
int (*address)(void *st, const char *text, uint32_t n);
uint32_t (*where)(void *st, char *buf, uint32_t n);
/* One of the addon's words, as written (`Fit width`): PA_OK, else
@@ -258,6 +296,9 @@ typedef struct pa_ops {
* head.version: PA_OK, or nonzero to refuse (the pane waits as a
* placeholder, its record kept). */
int (*load)(void *st, const uint8_t *buf, uint32_t n, uint32_t version);
+ /* 2.1: the pane's own search for the core's `/`: rows `place text`, a
+ * line each, into `buf`; their length. Absent: `/` finds nothing here. */
+ uint32_t (*search)(void *st, const char *pat, uint32_t n, char *buf, uint32_t cap);
} pa_ops;
/* The records' sizes on a 64-bit target: an addon built against another
@@ -267,11 +308,11 @@ _Static_assert(sizeof(pa_cell) == 20, "pa_cell");
_Static_assert(sizeof(pa_window) == 24, "pa_window");
_Static_assert(sizeof(pa_rect) == 16 && sizeof(pa_cells) == 8, "pa_rect");
_Static_assert(sizeof(pa_placement) == 80, "pa_placement");
-_Static_assert(sizeof(pa_paint) == 120, "pa_paint");
+_Static_assert(sizeof(pa_paint) == 128 && sizeof(pa_view) == 32, "pa_paint");
_Static_assert(sizeof(pa_key) == 8 && sizeof(pa_mouse) == 10, "pa_key");
-_Static_assert(sizeof(pa_api) == 64 && sizeof(pa_out) == 16, "pa_api");
+_Static_assert(sizeof(pa_api) == 96 && sizeof(pa_out) == 16, "pa_api");
_Static_assert(sizeof(pa_word) == 32 && sizeof(pa_head) == 56, "pa_head");
-_Static_assert(sizeof(pa_ops) == 192, "pa_ops");
+_Static_assert(sizeof(pa_ops) == 200, "pa_ops");
#endif
/* ---- helpers ---- */