pub fn install_panic_hook()Expand description
Installs a panic hook that restores the terminal before delegating to the previously installed hook.
A TUI application puts the terminal into raw mode and an alternate screen.
If the application panics, the stack unwinds straight out of
Runtime::run and the ratatui::restore() call
that would normally run afterwards is skipped, leaving the user’s
terminal in a broken state (no echo, no line editing, stuck on the
alternate screen). This function wraps the current panic hook so the
terminal is restored before the original hook runs. Because it chains
into the existing hook rather than replacing it, panic reporters such as
color_eyre still print their report — now on a restored, readable
terminal.
Call it once, after initializing the terminal (and after installing any
panic reporter such as color_eyre):
color_eyre::install()?;
let mut terminal = ratatui::init();
tears::install_panic_hook();
// ... run the application ...Call it only once. Each call wraps the previous hook, so repeated calls would restore the terminal multiple times (harmless, but pointless).