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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//! Terminal handles and platform-neutral terminal operations.
//!
//! [`PlatformTerminal`] opens the process terminal for the current target. It implements
//! [`Terminal`], which combines byte output, raw/cooked mode switching, terminal dimensions,
//! synchronous event reads, polling, and panic-hook cleanup. Termina does not enter alternate
//! screen with [`DecPrivateModeCode::ClearAndEnableAlternateScreen`], enable
//! [`DecPrivateModeCode::BracketedPaste`], or enable mouse tracking modes such as
//! [`DecPrivateModeCode::MouseTracking`] for you. Those are protocol choices the application
//! writes explicitly with [`crate::escape`].
//!
//! # Examples
//!
//! ```no_run
//! use std::{io, time::Duration};
//!
//! use termina::{
//! event::{Event, KeyEventKind},
//! PlatformTerminal, Terminal,
//! };
//!
//! fn main() -> io::Result<()> {
//! let mut terminal = PlatformTerminal::new()?;
//! terminal.enter_raw_mode()?;
//!
//! if terminal.poll(|_| true, Some(Duration::from_millis(250)))? {
//! let event = terminal.read(|event| {
//! matches!(event, Event::Key(key) if key.kind == KeyEventKind::Press)
//! })?;
//! if let Event::Key(key) = event {
//! println!("received {:?}", key.code);
//! }
//! }
//!
//! terminal.enter_cooked_mode()
//! }
//! ```
use ;
pub use *;
pub use *;
use crate::;
use crate;
/// The terminal implementation for the current platform.
///
/// On Unix this aliases `UnixTerminal`. On Windows this aliases `WindowsTerminal`.
pub type PlatformTerminal = UnixTerminal;
pub type PlatformTerminal = WindowsTerminal;
/// The output handle type passed to panic hooks on the current platform.
///
/// The hook receives this lower-level handle instead of `PlatformTerminal` so cleanup code can
/// write terminal reset sequences even while the higher-level terminal value is unwinding.
pub type PlatformHandle = FileDescriptor;
pub type PlatformHandle = OutputHandle;
/// Platform-agnostic terminal I/O surface.
///
/// The trait is implemented by the Unix and Windows backends and also requires [`io::Write`], so a
/// terminal value is both an output sink and an input/event source. `enter_raw_mode` and
/// `enter_cooked_mode` only manage the platform terminal mode. Application-level terminal features
/// such as alternate screen, bracketed paste, focus tracking, mouse tracking, and keyboard
/// protocol flags are CSI/OSC writes and remain the caller's responsibility. See
/// [`DecPrivateModeCode::ClearAndEnableAlternateScreen`],
/// [`DecPrivateModeCode::BracketedPaste`], [`DecPrivateModeCode::FocusTracking`],
/// [`DecPrivateModeCode::MouseTracking`], and [`Keyboard`] for the typed escape values.
///
/// `poll` and `read` use filters because the terminal stream may include responses that the caller
/// is not currently waiting for. Rejected events stay buffered in [`EventReader`] so later reads
/// can still observe them.
///
/// # Implementation Notes
///
/// This trait is based on [termwiz's terminal API], but Termina keeps feature setup outside the
/// terminal type and mirrors crossterm's synchronous event-reader shape for `poll` and `read`.
///
/// [termwiz's terminal API]: https://docs.rs/termwiz/latest/termwiz/terminal/index.html