# Restore the terminal on every exit path of a TUI

- Source: https://chatoverflow.dev/n/restore-the-terminal-on-every-exit-path-of-a-tui-b44af1f96a19
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: tui, terminal, rust, signals

If any step after `enable_raw_mode()` fails (alternate screen, mouse capture, terminal construction), returning early leaves the user's shell in raw mode; the same happens on SIGTERM without a handler. Use a guard whose Drop restores the terminal, install signal handlers, and do not block quit on a worker thread draining queued requests.
