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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! TUI rendering layer built on ratatui + crossterm.
//!
//! Houses:
//! - `arrow_select`: raw-mode arrow-key selector (pre-existing)
//! - `list_view`: Inline Viewport renderer for `gw list` (new)
//! - `style`: shared ratatui `Style` palette mirroring `crate::console`
//!
//! Simple commands with pure text output continue to use `crate::console`.
//! ratatui is reserved for commands that need declarative/progressive rendering.
// Re-export for backwards-compatible call sites that use `crate::tui::arrow_select(...)`.
pub use arrow_select;
use IsTerminal;
use ;
/// Whether stdout is attached to a terminal. Commands should fall back to
/// static rendering when this returns false (pipes, redirects, CI).
// #20/#4: tracks whether a ratatui terminal is currently active. The panic hook
// checks this flag so `ratatui::restore()` is only called when it matters —
// a non-ratatui panic must not clobber terminal state it never set up.
//
// Single-thread invariant: only the main thread creates ratatui terminals
// in this codebase. Relaxed ordering is sufficient. If callers ever cross
// threads, upgrade to Acquire/Release.
static RATATUI_ACTIVE: AtomicBool = new;
/// Mark that a ratatui terminal is now active.
///
/// # Safety contract
/// Must be called only from `TerminalGuard::new`. Direct callers can corrupt
/// the panic-hook contract.
pub
/// Mark that the ratatui terminal has been released.
///
/// # Safety contract
/// Must be called only from `TerminalGuard::Drop`. Direct callers can corrupt
/// the panic-hook contract.
pub
/// Install a panic hook that restores the terminal state before the default
/// panic handler prints. Safe to call once at process start.
///
/// The hook is gated on `RATATUI_ACTIVE` so it only calls `ratatui::restore()`
/// when a ratatui terminal is actually in use — avoiding spurious restores for
/// non-TTY panics (pipes, redirects, CI). `TerminalGuard` in `display.rs`
/// sets and clears this flag.
///
/// `default(info)` chains to the original hook, which prints the panic message
/// and respects `RUST_BACKTRACE` — so backtrace behaviour is preserved.