aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd.c
diff options
context:
space:
mode:
authorsl0p <sl0p@sl0p.foo>2026-08-13 23:27:47 +0200
committersl0p <sl0p@sl0p.foo>2026-08-13 23:27:47 +0200
commit58afd137373fb395fc0479d091c4da9ffa60324a (patch)
tree93839e3c20ff722819444ed22deaef07dc6e6041 /src/cmd.c
parentsl0ptty: M6 — the config file, and a README (diff)
downloadslosh-58afd137373fb395fc0479d091c4da9ffa60324a.tar.gz
slosh-58afd137373fb395fc0479d091c4da9ffa60324a.tar.xz
slosh-58afd137373fb395fc0479d091c4da9ffa60324a.zip
sl0ptty: M7 — layout files and suspended panes
A session can be a file: layout { tab name="api" purpose="project:api.a1b2c3" cwd="~/dev/api" { pane purpose="agent:main" command="pi" pane split="rows" { pane purpose="service:web" command="npm run dev" suspended=true pane purpose="shell:scratch" } } } built by --layout at startup or applied to a running session with {"cmd":"apply-layout", path|kdl, replace?}. Idempotency stays with the caller, which is where sl0ppi's CLI design already puts it: diff list-tabs against the projects on disk, then apply what is missing. close-tab completes that loop. Purposes a layout declares are locked, so identity comes from the file rather than from whatever the program inside prints — tested by having a pane try to take one in-band and be refused. Suspended panes: a pane that exists, is laid out, and has run nothing, showing what it would run and starting on its first keystroke (which is consumed, not forwarded). This is sl0ppi's D6 — a root with twelve projects must not become twelve running servers — and it is the reason can be cheap. Also fixes a test-isolation bug latent since M2: the live tests attached to the session called "main", which is whatever happens to exist on the box rather than one they created. They now use a unique session per run, which is how a run that had somebody else's htop in it became reproducible. 284 checks green (257 headless + 27 live).
Diffstat (limited to 'src/cmd.c')
-rw-r--r--src/cmd.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/cmd.c b/src/cmd.c
index 5cc25b2..df367db 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -158,6 +158,11 @@ static char *cmd_json(app_t *a, screen_t *s, input_parser_t *in,
: app_select_tab(a, (size_t)(jv_geti(req, "index", 1) - 1));
return ok ? jok_int("id", app_current_tab_id(a)) : jerr("no such tab");
}
+ if (strcmp(cmd, "close-tab") == 0) {
+ return app_close_tab(a, (uint32_t)jv_geti(req, "id", 0))
+ ? jok_int(NULL, 0)
+ : jerr("no such tab");
+ }
if (strcmp(cmd, "set-name") == 0) {
return app_set_tab_name(a, (uint32_t)jv_geti(req, "id", 0),
jv_gets(req, "name", ""))
@@ -176,6 +181,19 @@ static char *cmd_json(app_t *a, screen_t *s, input_parser_t *in,
: app_set_pane_purpose(a, id, purpose, declared);
return ok ? jok_int(NULL, 0) : jerr("refused");
}
+ if (strcmp(cmd, "apply-layout") == 0) {
+ const char *path = jv_gets(req, "path", NULL);
+ const char *text = jv_gets(req, "kdl", NULL);
+ bool replace = jv_getb(req, "replace", false);
+ char err[256] = {0};
+ bool ok = text ? app_apply_layout_text(a, text, replace, err, sizeof err)
+ : path ? app_apply_layout_file(a, path, replace, err, sizeof err)
+ : false;
+ if (!ok) return jerr(err[0] ? err : "need a path or kdl");
+ app_resize(a, s->cols, s->rows);
+ s->force_full = true;
+ return jok_raw("tabs", app_tabs_json(a));
+ }
if (strcmp(cmd, "reload") == 0) {
char err[256] = {0};
if (!app_reload_config(err, sizeof err)) return jerr(err[0] ? err : "reload failed");