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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//! Terminal I/O, escape-sequence types, styling, and input parsing.
//!
//! Termina keeps the terminal protocol visible. Applications write typed CSI, OSC, and DCS values
//! from [`escape`] instead of assembling byte strings, and read typed [`Event`] values instead of
//! decoding terminal input by hand. [`PlatformTerminal`] opens the current process terminal,
//! switches raw/cooked mode, writes bytes, and creates an [`EventReader`] for synchronous input.
//!
//! Code that already has terminal bytes can use [`Parser`] directly. That is useful for PTY tests,
//! terminal multiplexers, or callers that own the input source and only need Termina's parser.
//!
//! # Examples
//!
//! ```no_run
//! use std::io::{self, Write};
//!
//! use termina::{
//! event::{KeyCode, KeyEventKind},
//! Event, PlatformTerminal, Terminal,
//! };
//!
//! fn main() -> io::Result<()> {
//! let mut terminal = PlatformTerminal::new()?;
//! terminal.enter_raw_mode()?;
//! writeln!(terminal, "Press q to exit.")?;
//!
//! let reader = terminal.event_reader();
//! loop {
//! let event = reader.read(|_| true)?;
//! if matches!(
//! event,
//! Event::Key(key)
//! if key.kind == KeyEventKind::Press && key.code == KeyCode::Char('q')
//! ) {
//! break;
//! }
//! }
//!
//! terminal.enter_cooked_mode()
//! }
//! ```
//!
//! Parsing PTY bytes directly does not require opening a terminal handle:
//!
//! ```
//! use termina::{Event, Parser};
//!
//! let mut parser = Parser::default();
//! parser.parse(b"\x1b[5~", false);
//! assert!(matches!(parser.pop(), Some(Event::Key(_))));
//! ```
pub
pub
use ;
pub use ;
pub use windows;
pub use Parser;
pub use ;
pub use EventStream;
/// A one-based terminal coordinate or dimension.
///
/// Terminal protocols generally count rows and columns from 1, while Rust collections and many
/// application models count from 0. `OneBased` stores the protocol value and rejects zero. Use
/// [`Self::from_zero_based`] when converting from an application index and [`Self::get_zero_based`]
/// when converting back.
///
/// # Examples
///
/// ```
/// use termina::OneBased;
///
/// let column = OneBased::from_zero_based(4);
/// assert_eq!(column.get(), 5);
/// assert_eq!(column.get_zero_based(), 4);
/// assert!(OneBased::new(0).is_none());
/// ```
///
/// # Implementation Notes
///
/// This reimplements the coordinate helper from [termwiz escape helpers] on top of
/// [`NonZeroU16`].
///
/// [termwiz escape helpers]: https://docs.rs/termwiz/latest/termwiz/escape/index.html
;
/// The dimensions of a terminal window.
///
/// `cols` and `rows` describe the terminal window in character cells, which is the size used by
/// cursor positioning and layout code. Pixel dimensions are available when the platform reports
/// them. On Unix, Termina reads those optional pixel fields from the `TIOCGWINSZ` window-size
/// query when the terminal fills them in. Windows currently reports `None` for both pixel fields.