Skip to content

fix: restore terminal state on panic#42

Open
echobt wants to merge 1 commit intomainfrom
fix/issue-104
Open

fix: restore terminal state on panic#42
echobt wants to merge 1 commit intomainfrom
fix/issue-104

Conversation

@echobt
Copy link
Copy Markdown
Contributor

@echobt echobt commented Jan 20, 2026

Description

This PR addresses the issue where a panic within the TUI (or while the terminal is in raw mode) would leave the terminal in a broken state (raw mode enabled, cursor hidden, alternate screen active).

Changes

  • Added a global panic hook in src/cli/mod.rs (the entry point for CLI commands).
  • The hook checks crossterm::terminal::is_raw_mode_enabled() to determine if cleanup is necessary.
  • If raw mode is enabled, it attempts to:
    • Disable raw mode
    • Leave alternate screen
    • Disable mouse capture
    • Show the cursor
  • The original panic hook is then called to ensure panic messages are printed correctly.

Verification

  • Verified that cargo check and cargo test pass.
  • Logic is based on standard crossterm and ratatui panic handling patterns, adapted for global application to avoid TUI-local wrapper complexity.

Registers a global panic hook that checks if the terminal is in raw mode (TUI active) and restores it (leaves alternate screen, disables mouse capture, shows cursor) before printing the panic message. This prevents the terminal from being left in a broken state if the TUI panics.
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.

1 participant