aboutsummaryrefslogtreecommitdiffstats
path: root/src/jsonval.h
diff options
context:
space:
mode:
authorsl0p <sl0p@sl0p.foo>2026-08-13 22:58:24 +0200
committersl0p <sl0p@sl0p.foo>2026-08-13 22:58:24 +0200
commit7d416d95cb49f783f8c4ee6eddd5c2cdcd81bb40 (patch)
tree6aaced8bd6927565816ce48ae07fb5f397d6edf7 /src/jsonval.h
parentsl0ptty: M2 — server/client split, detach/reattach, control socket (diff)
downloadslosh-7d416d95cb49f783f8c4ee6eddd5c2cdcd81bb40.tar.gz
slosh-7d416d95cb49f783f8c4ee6eddd5c2cdcd81bb40.tar.xz
slosh-7d416d95cb49f783f8c4ee6eddd5c2cdcd81bb40.zip
sl0ptty: M3 — tabs, purposes, and the JSON control API
Tabs are layout trees, one per tab, and panes in every tab keep running: fds, pumping and reaping span all of them, only the current one is composed. A one-row strip shows them (M5 makes it the real status bar) and each label registers a hit, so clicking a tab switches to it through the same mechanism as every other click. C-a c new tab C-a n / C-a p cycle C-a 1..9 select Purposes on panes and tabs with D8's trust model implemented as a lock: declared (from a layout or an operator) outranks in-band, cannot be overridden, and everything is sanitised to [A-Za-z0-9_.:/-] on ingest — 'project:foo bar/../$(rm -rf)' becomes 'project:foobar/../rm-rf'. The in-band path arrives with the OSC scanner in M4 and always passes declared:false; the refusal is already tested. The control API is now JSON in, JSON out: {"cmd":"new-tab","name":"agent","purpose":"project:x.deadbeef"} {"ok":true,"id":2} with panes/tabs/snapshot/send/raw/resize/split/focus/close/select-tab/ set-name/set-purpose/alive/quit. Panes are addressed by id, not by 'the focused one', so a background tab can be scripted. The bare-verb form stays as a harness alias and runs the same code, so the tests cannot drift from the API. Adds a small JSON reader (jsonval.c) — we could only emit until now. 129 checks green.
Diffstat (limited to 'src/jsonval.h')
-rw-r--r--src/jsonval.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/jsonval.h b/src/jsonval.h
new file mode 100644
index 0000000..34cc597
--- /dev/null
+++ b/src/jsonval.h
@@ -0,0 +1,40 @@
+/* A small JSON reader, for the control API (D3). We already emit JSON; this
+ * is the other half. Deliberately minimal: no streaming, no comments, no
+ * duplicate-key policy beyond "last wins". */
+#ifndef SL0PTTY_JSONVAL_H
+#define SL0PTTY_JSONVAL_H
+
+#include <stdbool.h>
+#include <stddef.h>
+
+typedef enum {
+ JV_NULL, JV_BOOL, JV_NUM, JV_STR, JV_ARR, JV_OBJ,
+} jv_kind_t;
+
+typedef struct jv jv_t;
+
+struct jv {
+ jv_kind_t kind;
+ bool b;
+ double num;
+ char *str; /* JV_STR: NUL-terminated, UTF-8 */
+ size_t len; /* JV_STR bytes; JV_ARR/JV_OBJ element count */
+ jv_t **kids; /* JV_ARR/JV_OBJ values */
+ char **keys; /* JV_OBJ keys */
+};
+
+/* NULL on malformed input. */
+jv_t *jv_parse(const char *text);
+void jv_free(jv_t *v);
+
+const jv_t *jv_get(const jv_t *obj, const char *key);
+const char *jv_str(const jv_t *v, const char *fallback);
+long jv_int(const jv_t *v, long fallback);
+bool jv_bool(const jv_t *v, bool fallback);
+
+/* Convenience: obj.key as a string/int/bool, with a fallback. */
+const char *jv_gets(const jv_t *obj, const char *key, const char *fallback);
+long jv_geti(const jv_t *obj, const char *key, long fallback);
+bool jv_getb(const jv_t *obj, const char *key, bool fallback);
+
+#endif /* SL0PTTY_JSONVAL_H */