feat(config-toggle): add interactive TUI for toggling opinionated component settings #43
Reference in New Issue
Block a user
Delete Branch "feat/config-toggle"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
config-toggle— a full ANSI TUI (pure fish, no external deps beyondstty/dd/od) for toggling all 7 opinionated component variables (the six C1–C6 categories plus the master__fish_config_opinionated) without typing variable namesTab; changes apply immediately viaset -U/set -g— no confirm step. The two scopes are independent (e.g. Integrations off universally, on for this session)ON,OFF,DEFAULT— set directionally along anOFF ← DEFAULT → ONscale (clamped at the ends).DEFAULTerases the variable so the master switch / built-in default takes overhjkl-consistent keymap (see below)Keymap
↑↓orkj←→orhlOFF ← DEFAULT → ON(clamped)Tabq/EscFiles
functions/config-toggle.fish— entry point: arg/help parsing, terminal setup, event loopfunctions/__config_toggle_read_key.fish— raw-tty single-keypress reader (see note below)functions/__config_toggle_draw.fish— bordered panel rendererfunctions/__config_toggle_get_val.fish— scope-aware value reader (parsesset --show)functions/__config_toggle_apply.fish— shared scope-awareset -U/-g/-Ue/-egapply logicdocs/fish-config.md+docs/fish-config.index— offline docs entry;README.md— Minimal Mode tipImplementation note: why not fish
read?fish's
readbuiltin invokes its interactive line editor on a TTY, which prints aread>prompt, intercepts Tab and arrow keys for its own editing (so they never reach the handler), and shifts the cursor — breaking in-place redraws.__config_toggle_read_keyinstead puts the terminal in raw mode (stty raw -echo min 1 time 1), reads one keypress from/dev/tty, and decodes the raw bytes into normalized tokens (up/down/left/right/tab/escape/quit/literal char). This makes arrow keys and Tab work, removes the stray prompt, keeps the redraw aligned, and lets bareEscexit cleanly (Ctrl-C in raw mode arrives as byte 3 → handled as quit).Manual Verification
config-toggle— panel renders once with a clean border, 7 rows (Aliases → Master), Universal tab active, noread>line, no flicker/stacking↓/↑andj/k— cursor moves through rows, clamped at the first and last row→/lon a row — value stepsOFF → DEFAULT → ONand stops atON(no wrap)←/hon a row — value stepsON → DEFAULT → OFFand stops atOFF(no wrap)set --show <var>in another shell — the universal variable reflects the change immediatelyTab— scope switches between Universal and Session; the highlighted tab updatesONin Universal andOFFin Session (Tab between scopes) — both held independently; confirm withset --show __fish_config_op_aliasesq,Esc, andCtrl-C(separately) — each exits cleanly, cursor restored, prompt on a fresh lineconfig-toggle -h— prints the keymap/help to stdout without entering the TUIhelp config toggle— jumps to the config-toggle section in the offline docsfish's read -k N waits for exactly N bytes; single-char keys ('q', 'j', Space, Tab) were blocking indefinitely waiting for 2 more bytes, causing the input loop to appear unresponsive. Random 3-key bundles were then processed as unrecognised input, triggering infinite redraws. Switch to read -k 1 (one raw byte per call). Arrow keys still work: the terminal sends ESC+[+A/B as a burst, so after reading ESC the two continuation bytes are already in the TTY buffer and the follow-up reads return immediately. Bare ESC now passes the next keypress through as the effective key rather than exiting (q/Q remain the exit keys).