1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Process-global panic hook that restores the terminal before
//! the default hook prints the panic message.
//!
//! ## Why this exists
//!
//! When a panic starts unwinding, Rust's default panic hook prints
//! the message and backtrace to `stderr`. If we're still in alt-
//! screen and raw mode when that happens, the user sees nothing
//! useful — the message lands on the alt-screen buffer which gets
//! erased on exit.
//!
//! This module installs a hook that runs `leave_tui_mode` first
//! (restoring the main screen + cooked mode), then delegates to the
//! previous hook. Combined with `TerminalGuard::drop` (which runs
//! during stack unwinding), the terminal is definitively restored
//! regardless of which cleanup path wins.
//!
//! ## Install-once
//!
//! A global `AtomicBool` guards the install. Multiple `App::new`
//! calls don't stack hooks; re-running the binary picks up a fresh
//! process with a fresh hook. We never uninstall: the hook is
//! harmless when TUI mode isn't active (`leave_tui_mode` on an
//! already-cooked terminal emits idempotent sequences).
use io;
use ;
use crateleave_tui_mode;
static INSTALLED: AtomicBool = new;
/// Install the terminal-restoring panic hook. Idempotent — multiple
/// calls leave only the first install in place. Safe to call before,
/// during, or after any `App::run` session.
/// `true` when [`install`] has been called at least once this
/// process. Exposed for test assertion only.
pub