aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-14 19:27:54 +0200
committeruser <user@clank>2026-08-14 19:27:54 +0200
commit1b9a23b4c8be1b8009456f0a50ece6422b3c797c (patch)
tree7e1d7ba88813d7edd47e349d6f7d59f8ba4688e0 /src/main.c
parentsl0ppty: a pane that rings says so (diff)
downloadslosh-1b9a23b4c8be1b8009456f0a50ece6422b3c797c.tar.gz
slosh-1b9a23b4c8be1b8009456f0a50ece6422b3c797c.tar.xz
slosh-1b9a23b4c8be1b8009456f0a50ece6422b3c797c.zip
sl0ppty: saving the config reloads it
The reload existed but you had to ask for it, which is the wrong shape for the thing it is mostly used for: changing a colour and looking at the result. The server now watches the config and re-reads it when it changes. It watches the config's *directory* and filters by name, rather than watching the file. Editors overwhelmingly save by writing a temporary file and renaming it over the target, which swaps the inode out from under a watch on the file itself — it fires once and then never again, which is worse than not watching at all because it looks like it works. The test writes in place *and* renames over, because only the second one would have caught that. Reloading goes through the same call the command does, so it keeps the fail-open behaviour: a file that does not parse leaves the running config alone and says so in a toast. That matters more here than it did for the command, because a file caught halfway through a save is a normal thing for a watcher to see rather than an operator mistake — and there is a test for it, and for the recovery once the file is valid again. Turning it off is a command-line flag rather than a setting, because a setting would be circular: you would have to reload the config to stop it reloading the config. --no-reload only stops the *watching*; asking explicitly still works, which is the distinction the flag name is trying to make. The test is a live one because inotify lives in the server's poll loop and the headless driver has no server. It polls for the colour it expects rather than sleeping a guess, so the passing cases cost milliseconds; the two cases that assert nothing happened are the only ones that wait, because proving a negative has to.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 94621c1..f898746 100644
--- a/src/main.c
+++ b/src/main.c
@@ -36,7 +36,7 @@ static void term_size(uint16_t *cols, uint16_t *rows) {
}
static void usage(void) {
- fputs("usage: sl0ppty [-s NAME] [--layout FILE] [ls | cmd LINE | -- CMD...]\n",
+ fputs("usage: sl0ppty [-s NAME] [--layout FILE] [--no-reload]\n [ls | cmd LINE | -- CMD...]\n",
stderr);
}
@@ -47,6 +47,7 @@ int main(int argc, char **argv) {
const char *name = "main";
const char *cmd_line = NULL;
const char *layout = NULL;
+ bool watch = true;
bool list = false;
const char *cmd_argv[64];
int cmd_n = 0;
@@ -58,6 +59,7 @@ int main(int argc, char **argv) {
else if (strcmp(a, "--server") == 0) server = true;
else if (strcmp(a, "-s") == 0 && i + 1 < argc) name = argv[++i];
else if (strcmp(a, "--layout") == 0 && i + 1 < argc) layout = argv[++i];
+ else if (strcmp(a, "--no-reload") == 0) watch = false;
else if (strcmp(a, "ls") == 0) list = true;
else if (strcmp(a, "cmd") == 0 && i + 1 < argc) cmd_line = argv[++i];
else if (strcmp(a, "--cols") == 0 && i + 1 < argc) cols = (uint16_t)atoi(argv[++i]);
@@ -107,11 +109,11 @@ int main(int argc, char **argv) {
if (headless) return run_headless(cmd_argv, cols, rows, idle_ms, script, layout);
if (isatty(STDOUT_FILENO)) term_size(&cols, &rows);
- if (server) return server_run(name, cmd_argv, cols, rows, layout);
+ if (server) return server_run(name, cmd_argv, cols, rows, layout, watch);
/* attach, creating the session if nobody is home */
int fd = server_connect(name);
- if (fd < 0) fd = server_spawn(name, cmd_argv, cols, rows, layout);
+ if (fd < 0) fd = server_spawn(name, cmd_argv, cols, rows, layout, watch);
if (fd < 0) {
fprintf(stderr, "sl0ppty: cannot start session %s\n", name);
return 1;