Skip to content

fix: restore the terminal on every exit path - #9

Merged
greenbugx merged 2 commits into
mainfrom
fix/TUI-bug
Aug 26, 2026
Merged

greenbugx merged 2 commits into
mainfrom
fix/TUI-bug

Conversation

@greenbugx

@greenbugx greenbugx commented Aug 26, 2026

Copy link
Copy Markdown
Owner

Raw mode and the alternate screen were undone only at the end of the happy
path in run, so a panic left the shell with no echo and no line editing.
The panic message was printed into the alternate screen while raw mode was
still on, so it staircased down the screen and then scrolled away with the
alternate screen, leaving the user a broken terminal and no explanation.
An early ? from Terminal::new did the same thing silently.

Move setup and teardown into src/terminal.rs behind a TerminalGuard
whose Drop restores, so it runs on a normal return, an early ? and an
unwind alike. enter constructs the guard before entering the alternate
screen, so a failure there still switches raw mode back off.

The panic hook restores before delegating to the previous hook, which puts
the message on the normal screen and keeps RUST_BACKTRACE working. It
restores only when the thread that owns the terminal panics: a panic on
the loading or detail worker kills only that thread and leaves the TUI
running, where restoring would turn a background failure into a corrupted
screen.

Teardown is best effort rather than a chain of ?, which previously meant
a failing disable_raw_mode skipped LeaveAlternateScreen entirely.

Related Issues

Closes #3

Related PR's & Commits

7c6584f of #7 which replaced fn main() -> Result<..> with fn main() -> ExitCode: errors now print with Display via eprintln!("gitloom: {err}") instead of println!("{:?}", err), and the error path returns ExitCode::FAILURE instead of falling through to Ok(()) and exiting 0.

Repository owner deleted a comment from chatgpt-codex-connector Bot Aug 26, 2026
@greenbugx greenbugx self-assigned this Aug 26, 2026
@greenbugx
greenbugx merged commit b687bc4 into main Aug 26, 2026
0 of 4 checks passed
@greenbugx
greenbugx deleted the fix/TUI-bug branch August 26, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Terminal state is not restored when GitLoom panics

1 participant