pub struct TermInputParser { /* private fields */ }event and term only.Expand description
๐ฎ ๐ซ ::= Parses terminal input bytes into normalized events.
๐ sys/os/term
๐ฆ size_of::<TermInputParser>() == 19 bytes / 152 bits
TermInputParser is a byte-fed state machine. It accepts ordinary bytes,
UTF-8 text, and terminal escape sequences, returning an EventKind when
a complete input event has been recognized.
It is intentionally independent from any concrete terminal backend. Linux, Windows, web-terminal, pseudo-terminal, and test backends can all feed bytes into the same parser.
ยงPublic output
The public feed method returns only normalized user-facing events.
Terminal replies used for probing capabilities are parsed internally and are exposed only inside the crate.
ยงEscape handling
A lone ESC byte is ambiguous: it may be the Escape key, or it may begin a
longer escape sequence. Backends should call flush_escape
after their escape timeout expires.
ยงSupported seed grammar
The first parser layer recognizes:
- printable ASCII
- UTF-8 scalar values
- Enter, Tab, Backspace, Escape
- basic Control-letter combinations
- common CSI navigation and editing keys
- cursor-position and device-attribute replies, internally
ยงTerminal limits
Terminal input is normalized from the byte stream reported by the active terminal emulator. Some information may be unavailable because terminals often reserve key or mouse combinations for selection, menus, shortcuts, or scrollback behavior before the application receives them.
In SGR mouse mode, terminal reports can encode Shift, Alt/Meta, and Control
modifier bits. TermInputParser preserves those bits when present, but
applications should not assume every terminal will report every modifier
combination. In particular, Shift-click and Control-click are commonly
intercepted or repurposed by terminal emulators.
Implementationsยง
Sourceยงimpl TermInputParser
impl TermInputParser
Sourcepub fn feed(&mut self, byte: u8) -> Option<EventKind> โ
pub fn feed(&mut self, byte: u8) -> Option<EventKind> โ
Feeds one byte into the parser.
Returns Some(EventKind) when the byte completes a user-facing event.
Returns None while a multi-byte sequence is still pending, or when the
completed sequence is an internal terminal reply.
Use flush_escape to resolve a pending lone ESC
after the backendโs escape timeout expires.
Sourcepub const fn flush_escape(&mut self) -> Option<EventKind> โ
pub const fn flush_escape(&mut self) -> Option<EventKind> โ
Flushes a pending lone ESC as an Escape key press.
Returns None unless the parser is currently waiting after an ESC byte.
This is needed because terminal escape sequences and the Escape key share the same leading byte.
Trait Implementationsยง
Sourceยงimpl Clone for TermInputParser
impl Clone for TermInputParser
Sourceยงfn clone(&self) -> TermInputParser
fn clone(&self) -> TermInputParser
1.0.0 (const: unstable) ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSourceยงimpl ConstInit for TermInputParser
impl ConstInit for TermInputParser
Sourceยงimpl Debug for TermInputParser
impl Debug for TermInputParser
Sourceยงimpl Default for TermInputParser
impl Default for TermInputParser
Sourceยงfn default() -> TermInputParser
fn default() -> TermInputParser
Auto Trait Implementationsยง
impl Freeze for TermInputParser
impl RefUnwindSafe for TermInputParser
impl Send for TermInputParser
impl Sync for TermInputParser
impl Unpin for TermInputParser
impl UnsafeUnpin for TermInputParser
impl UnwindSafe for TermInputParser
Blanket Implementationsยง
Sourceยงimpl<T> AnyExt for T
impl<T> AnyExt for T
Sourceยงfn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId of Self using a custom hasher.Sourceยงfn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Sourceยงfn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
alloc only.Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<T> ByteSized for T
impl<T> ByteSized for T
Sourceยงconst BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Sourceยงfn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Sourceยงfn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<T> MemExt for Twhere
T: ?Sized,
impl<T> MemExt for Twhere
T: ?Sized,
Sourceยงconst NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Sourceยงfn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Sourceยงfn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Sourceยงfn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Sourceยงfn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Sourceยงfn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true if dropping values of this type matters. Read moreSourceยงfn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self without running its destructor. Read moreSourceยงfn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Sourceยงunsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSourceยงunsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSourceยงfn mem_as_bytes(&self) -> &[u8] โ
fn mem_as_bytes(&self) -> &[u8] โ
unsafe_slice only.