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
//! Panic-safe terminal lifecycle.
//!
//! Every example's `main` opened the alternate screen and enabled raw mode by
//! hand, then restored them after the loop — which means a panic *inside* the
//! loop left the user's terminal wrecked (no echo, stuck in the alternate
//! screen). [`enter`] returns a guard that restores the terminal on drop, so
//! teardown happens on the normal path and while unwinding alike. The crate
//! owns the ceremony; the application owns the draw loop.
//!
//! ```ignore
//! let _guard = tui_pages::terminal::enter()?;
//! let mut terminal = Terminal::new(CrosstermBackend::new(std::io::stderr()))?;
//! loop { /* draw + handle_key */ }
//! // `_guard` restores the terminal here — or if the loop panics.
//! ```
//!
//! The guard targets `stderr`, leaving `stdout` free for piping the app's
//! output. This needs only `crossterm`, which the crate already depends on; no
//! rendering backend is pulled in.
use io;
use ;
/// Enable raw mode, switch `stderr` to the alternate screen, and turn on
/// bracketed paste, returning a guard that reverses all three when dropped.
/// Hold the guard for the lifetime of the UI; let it drop (or be dropped by
/// unwinding) to restore the terminal.
///
/// Bracketed paste makes the terminal deliver a paste as a single
/// `Event::Paste(text)` rather than a flood of synthetic key presses, so a text
/// widget can insert it in one shot. Forward terminal events to
/// [`crate::runtime::TuiPages::handle_event`] for the default key and paste
/// routing.
/// Restores the terminal — leaves the alternate screen and disables raw mode —
/// when dropped. Created by [`enter`].