From 5a018fe97551eed746f819c2fa5de917783e26fa Mon Sep 17 00:00:00 2001 From: rootiest Date: Thu, 11 Jun 2026 02:56:12 -0400 Subject: [PATCH] fix(config-toggle): use valid -n read flag, stopping the busy redraw loop The event loop used `read -k 1`, but `-k` is not a valid fish read option (it errors with "unknown option", status 2). read therefore returned instantly every iteration without consuming a keypress, so the loop redrew the panel as fast as the terminal could render and ignored all input. The nchars flag is `-n`, not `-k`. Switch to `read -s -n 1` (one char, silent so keystrokes don't garble the panel) and add `or break` so a read failure (EOF / non-tty stdin) exits cleanly instead of spinning. Applies to the primary read and both escape sequence continuation reads. --- functions/config-toggle.fish | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/functions/config-toggle.fish b/functions/config-toggle.fish index 8f62c64..28908e9 100644 --- a/functions/config-toggle.fish +++ b/functions/config-toggle.fish @@ -81,10 +81,11 @@ function config-toggle --description 'Interactive TUI for toggling opinionated c __config_toggle_draw $cur_row $cur_scope $vars # ── Event loop ──────────────────────────────────────── - # read -k 1 reads exactly one raw byte. Arrow keys send ESC+[+letter as a - # 3-byte burst — after reading the ESC we immediately read 2 more bytes - # which are already in the terminal buffer. Single-char keys ('j','k',' ', - # 'q', Tab) are returned right away with no extra blocking. + # read -s -n 1 reads exactly one char without echoing it. Arrow keys send + # ESC+[+letter as a 3-byte burst — after reading the ESC we immediately + # read 2 more bytes which are already in the terminal buffer. Single-char + # keys ('j','k',' ','q', Tab) are returned right away with no extra + # blocking. NOTE: the nchars flag is -n; -k is not a valid read option. while true # Check for Ctrl-C signal (trap sets this flag) if set -q __config_toggle_exit @@ -92,13 +93,17 @@ function config-toggle --description 'Interactive TUI for toggling opinionated c break end - read -k 1 -l key + # -n 1 reads exactly one char; -s suppresses echo so keystrokes do + # not garble the panel. If read fails (EOF / non-tty stdin) bail out + # instead of spinning the redraw loop. + read -s -n 1 -l key + or break # Detect CSI escape sequences (arrow keys: ESC [ A/B) if test "$key" = \e - read -k 1 -l key2 + read -s -n 1 -l key2 if test "$key2" = "[" - read -k 1 -l key3 + read -s -n 1 -l key3 set key "$key$key2$key3" # \e[A or \e[B else # ESC + non-bracket (ALT+key or plain ESC): treat key2 as key