1pub(crate) mod base64;
2pub mod escape;
3pub mod event;
4pub(crate) mod parse;
5pub mod style;
6mod terminal;
7
8use std::{fmt, num::NonZeroU16};
9
10pub use event::{reader::EventReader, Event};
11#[cfg(windows)]
12pub use parse::windows;
13pub use parse::Parser;
14
15pub use terminal::{PlatformHandle, PlatformTerminal, Terminal};
16
17#[cfg(feature = "event-stream")]
18pub use event::stream::EventStream;
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24pub struct OneBased(NonZeroU16);
27
28impl OneBased {
29 pub const fn new(n: u16) -> Option<Self> {
30 match NonZeroU16::new(n) {
31 Some(n) => Some(Self(n)),
32 None => None,
33 }
34 }
35
36 pub const fn from_zero_based(n: u16) -> Self {
37 Self(unsafe { NonZeroU16::new_unchecked(n + 1) })
38 }
39
40 pub const fn get(self) -> u16 {
41 self.0.get()
42 }
43
44 pub const fn get_zero_based(self) -> u16 {
45 self.get() - 1
46 }
47}
48
49impl Default for OneBased {
50 fn default() -> Self {
51 Self(unsafe { NonZeroU16::new_unchecked(1) })
52 }
53}
54
55impl fmt::Display for OneBased {
56 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57 self.0.fmt(f)
58 }
59}
60
61impl From<NonZeroU16> for OneBased {
62 fn from(n: NonZeroU16) -> Self {
63 Self(n)
64 }
65}
66
67#[derive(Debug, Clone, Copy, PartialEq, Eq)]
72pub struct WindowSize {
73 #[doc(alias = "width")]
75 pub cols: u16,
76 #[doc(alias = "height")]
78 pub rows: u16,
79 pub pixel_width: Option<u16>,
81 pub pixel_height: Option<u16>,
83}