aboutsummaryrefslogtreecommitdiffstats
path: root/src/server.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/server.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/server.c')
-rw-r--r--src/server.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/server.c b/src/server.c
index 4326fb2..55696d1 100644
--- a/src/server.c
+++ b/src/server.c
@@ -121,7 +121,7 @@ static void drop_display(server_t *s, uint8_t reason) {
}
int server_run(const char *name, const char *const argv[], uint16_t cols,
- uint16_t rows) {
+ uint16_t rows, const char *layout) {
char path[512];
if (session_socket_path(name, path, sizeof path) != 0) return 1;
int lfd = listen_socket(path);
@@ -139,6 +139,11 @@ int server_run(const char *name, const char *const argv[], uint16_t cols,
server_t s = {0};
s.app = app_new(argv, cols, rows);
if (!s.app) return 1;
+ if (layout) {
+ char err[256] = {0};
+ if (!app_apply_layout_file(s.app, layout, true, err, sizeof err))
+ fprintf(stderr, "sl0ptty: %s: %s\n", layout, err[0] ? err : "bad layout");
+ }
app_resize(s.app, cols, rows);
screen_init(&s.screen, cols, rows);
s.in = input_new();
@@ -299,7 +304,7 @@ int server_run(const char *name, const char *const argv[], uint16_t cols,
/* Fork a server into the background and wait for its socket to answer. */
int server_spawn(const char *name, const char *const argv[], uint16_t cols,
- uint16_t rows) {
+ uint16_t rows, const char *layout) {
char path[512], logp[512];
if (session_socket_path(name, path, sizeof path) != 0) return -1;
session_log_path(name, logp, sizeof logp);
@@ -316,7 +321,7 @@ int server_spawn(const char *name, const char *const argv[], uint16_t cols,
dup2(log >= 0 ? log : null, STDERR_FILENO);
if (null > 2) close(null);
if (log > 2) close(log);
- _exit(server_run(name, argv, cols, rows));
+ _exit(server_run(name, argv, cols, rows, layout));
}
waitpid(pid, NULL, 0); /* the intermediate exits immediately */