diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-25 19:02:35 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-25 19:02:35 +0200 |
| commit | 8f99f1650e4a7363af1d83190b4082fb72a9f73f (patch) | |
| tree | 86ed3b714c376e95f98d33d7572e76d6b43f06d3 /patches/ttym-flash-2.0.diff | |
| parent | 2f6b29abd0d766ef477eb29c5a7bf6c1e88e9630 (diff) | |
| download | ttym-8f99f1650e4a7363af1d83190b4082fb72a9f73f.tar.gz ttym-8f99f1650e4a7363af1d83190b4082fb72a9f73f.zip | |
ttym 3.0: fix terminal and config bugs, fold terminal-only patches into base
Correctness fixes:
- restore the terminal on SIGQUIT and SIGHUP. atexit never runs on an
uncaught fatal signal, so Ctrl+\ left the cursor hidden and autowrap
disabled.
- drop the unconditional newline in restore_tty. Every run emitted a
stray blank line, including piped output.
- treat EINTR as an interruption rather than a poll() failure, which
delayed Ctrl+C by up to one 100ms frame.
config-file patch:
- make comment stripping quote-aware so a value may contain '#', and
strip one matched pair of quotes. bar_fill = "#" was silently dropped,
despite '#' being the glyph of the hash style this build ships.
- resolve bar_fill/bar_empty inside resolve_bar and clear them on --bar,
so command-line flags beat the config file as documented. Previously
config glyphs silently overrode --bar.
- report unknown keys, unparseable booleans and malformed lines on
stderr. flash = enabled silently meant off.
- never write to disk. --dump-config prints a commented template on
stdout instead of the binary creating ~/.config/ttym/config on first
run.
Patch set:
- fold persist-alert, flash and bar-styles into the base. The base is
now terminal-only: it opens /dev/tty, draws and exits, with no file
writes and no subprocesses. Everything still in patches/ changes what
the program touches.
- seven patches become four; config-file's prerequisites drop from six
patches to one (notify), so it is regenerable mechanically.
- regenerate every patch. All apply with zero fuzz and compile.
Source:
- rewrite argv in place rather than into a malloc'd copy (C99
5.1.2.2.1), removing die(), four free() calls and <stdarg.h>.
- fold the duplicated elapsed-time expression into elapsed().
- drop dead code: have_any, (void)cfg, and an unreachable branch in
parse_duration.
- replace hand-counted padding with \033[K.
Docs and build:
- timer.1: -c is the third hook argument, not the fourth. Add EXIT
STATUS (a stopwatch always exits 130 -- it has no natural end) and
ENVIRONMENT. Document config precedence and quoting.
- wire VERSION into a dist target; it was defined and never used.
- track .gitignore, which previously ignored itself, so a fresh clone
had no ignore rules.
Claude-Session: https://claude.ai/code/session_01APLBs8RB1FcUaC4viVkzbP
Diffstat (limited to 'patches/ttym-flash-2.0.diff')
| -rw-r--r-- | patches/ttym-flash-2.0.diff | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/patches/ttym-flash-2.0.diff b/patches/ttym-flash-2.0.diff deleted file mode 100644 index 0ee30b5..0000000 --- a/patches/ttym-flash-2.0.diff +++ /dev/null @@ -1,113 +0,0 @@ -diff -ruN a/config.def.h b/config.def.h ---- a/config.def.h 2026-05-20 12:14:52.639963552 +0200 -+++ b/config.def.h 2026-05-20 12:14:52.639963552 +0200 -@@ -9,3 +9,8 @@ - * Override per-run with --no-persist. - */ - static const int ALERT_PERSIST = 1; -+ -+/* reverse-video flash during the alert loop. -+ * Override per-run with --flash on|off. -+ */ -+static const int FLASH = 1; -diff -ruN a/ttym.c b/ttym.c ---- a/ttym.c 2026-05-20 12:14:52.639963552 +0200 -+++ b/ttym.c 2026-05-20 12:17:37.203364538 +0200 -@@ -11,6 +11,7 @@ - #include <stdio.h> - #include <stdlib.h> - #include <string.h> -+#include <strings.h> - #include <sys/ioctl.h> - #include <termios.h> - #include <time.h> -@@ -24,6 +25,7 @@ - int quiet; /* -q: suppress completion bell */ - int silent; /* -s: no bell, no extras */ - int alert_persist; /* alert loop until keypress; --no-persist disables */ -+ int flash; /* reverse-video flash during alert loop */ - } Config; - - static struct termios oldtios; -@@ -81,6 +83,13 @@ - interrupted = 1; - } - -+static int -+parse_bool_str(const char *v) -+{ -+ return !strcasecmp(v, "true") || !strcasecmp(v, "yes") || -+ !strcmp(v, "1") || !strcasecmp(v, "on"); -+} -+ - static void - restore_tty(void) - { -@@ -88,7 +97,7 @@ - tcsetattr(ttyfd, TCSANOW, &oldtios); - rawset = 0; - if (out_tty) -- fputs("\033[?7h\033[?25h", stdout); /* re-enable wrap, show cursor */ -+ fputs("\033[?5l\033[?7h\033[?25h", stdout); /* clear reverse, re-enable wrap, show cursor */ - fputc('\n', stdout); - fflush(stdout); - } -@@ -241,14 +250,17 @@ - } - - static void --alert_loop(void) -+alert_loop(int flash) - { - fputs("\033[?25h\033[?7h", stdout); - int ticks = 0; - while (!interrupted) { - fputc('\a', stdout); -+ if (flash) fputs("\033[?5h", stdout); - fflush(stdout); - sleep_ms(150); -+ if (flash) fputs("\033[?5l", stdout); -+ fflush(stdout); - - int acked = 0; - for (int i = 0; i < 15 && !interrupted; i++) { -@@ -287,6 +299,7 @@ - " -q no sound\n" - " -s silent\n" - " --no-persist skip alert-until-keypress loop\n" -+" --flash on|off terminal flash during alert loop\n" - " -- end of options\n" - " -h help\n" - "\n" -@@ -421,7 +434,7 @@ - } - if (!cfg->silent && cfg->alert_persist && is_foreground()) { - interrupted = 0; -- alert_loop(); -+ alert_loop(cfg->flash); - } - } - -@@ -436,6 +449,7 @@ - { - Config cfg = {0}; - cfg.alert_persist = ALERT_PERSIST; -+ cfg.flash = FLASH; - - /* Pre-strip long-form flags before getopt. Stop at "--". */ - int new_argc = 0; -@@ -452,6 +466,14 @@ - cfg.alert_persist = 0; - continue; - } -+ if (!past_dd && !strncmp(argv[i], "--flash=", 8)) { -+ cfg.flash = parse_bool_str(argv[i] + 8); -+ continue; -+ } -+ if (!past_dd && !strcmp(argv[i], "--flash") && i + 1 < argc) { -+ cfg.flash = parse_bool_str(argv[++i]); -+ continue; -+ } - new_argv[new_argc++] = argv[i]; - } - new_argv[new_argc] = NULL; |
