fix(cli): keel tui fails gracefully without an interactive terminal - #141
Merged
Conversation
Running `keel tui` (the live path) without a real controlling TTY dumped a raw `_curses.error: cbreak() returned ERR` traceback — hit when it's run through a pipe or a harness that captures stdio instead of a terminal. - Pre-check `_stdio_is_interactive()` (both stdin AND stdout are TTYs) in `tui_cmd` before entering curses; if not, raise a clean `ClickException` pointing at `keel tui --once`. - Belt-and-braces: `run_live` now also catches `curses.error` from `curses.wrapper` itself (a TTY that passes `isatty()` yet can't be put into cbreak mode) and turns it into the same actionable message. `--once` (the non-curses snapshot path) is unaffected. +3 tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Follow-up to #140. Running
keel tui(the live, full-screen path) without a real controlling TTY dumped a raw traceback:This surfaced when launching it through a pipe / a harness that captures stdio rather than owning a terminal. Now it fails with a clean, actionable message instead.
Fix
_stdio_is_interactive()(both stdin and stdout are TTYs) intui_cmdbefore entering curses; if not, raise aClickExceptionpointing the user atkeel tui --once.run_livealso catchescurses.errorraised bycurses.wrapperitself — the case where a terminal passesisatty()but still can't be put into cbreak mode — and turns it into the same helpful message.--once(the non-curses snapshot path, used by pipes/CI) is unaffected.Testing
_stdio_is_interactiveboth-TTY logic;keel tuiunder CliRunner exits cleanly with a--oncehint;run_livewraps acurses.errorfromwrapperas aClickException).ruff checkclean.keel tuinow printsError: keel tui needs an interactive terminal … use \keel tui --once`instead of a traceback;--once` still renders a snapshot.🤖 Generated with Claude Code