pub struct InputParser { /* private fields */ }Expand description
Terminal input parser with DoS protection.
Parse terminal input bytes into events:
let mut parser = InputParser::new();
let events = parser.parse(b"\x1b[A"); // Up arrow
assert_eq!(events.len(), 1);Implementations§
Source§impl InputParser
impl InputParser
Sourcepub fn set_expect_x10_mouse(&mut self, enabled: bool)
pub fn set_expect_x10_mouse(&mut self, enabled: bool)
Enable or disable X10 mouse event parsing.
When enabled, bare CSI M triggers X10 coordinate collection
(3 raw bytes). This should generally follow mouse-capture state.
Sourcepub fn set_allow_legacy_mouse(&mut self, enabled: bool)
pub fn set_allow_legacy_mouse(&mut self, enabled: bool)
Enable or disable legacy numeric mouse fallback parsing.
When enabled, parse CSI Cb;Cx;Cy M as mouse input. This is useful when
mouse capture is active but the terminal does not honor SGR 1006 mode.
Default: false.
Sourcepub fn set_pixel_mouse(&mut self, enabled: bool)
pub fn set_pixel_mouse(&mut self, enabled: bool)
Enable or disable SGR-Pixels (?1016h) mouse coordinate conversion.
When enabled, CSI < Cb ; Px ; Py M|m coordinates are treated as
pixel coordinates, stored in MouseEvent::pixel, and converted to
0-indexed cell coordinates using Self::cell_size_px (or (0, 0)
if the cell size is not yet known).
Sourcepub const fn with_pixel_mouse(self, enabled: bool) -> Self
pub const fn with_pixel_mouse(self, enabled: bool) -> Self
Builder variant of Self::set_pixel_mouse.
Sourcepub const fn pixel_mouse(&self) -> bool
pub const fn pixel_mouse(&self) -> bool
Whether SGR-Pixels (?1016h) mouse mode is enabled.
Sourcepub fn set_cell_size_px(&mut self, width: u16, height: u16)
pub fn set_cell_size_px(&mut self, width: u16, height: u16)
Set the cell dimensions in pixels (width, height) used to convert
SGR-Pixels (?1016h) coordinates into cell coordinates.
Passing a zero width or height clears the stored cell size.
Sourcepub const fn cell_size_px(&self) -> Option<(u16, u16)>
pub const fn cell_size_px(&self) -> Option<(u16, u16)>
Current cell size in pixels (width, height), if known.
Sourcepub fn set_capture_apc(&mut self, enabled: bool)
pub fn set_capture_apc(&mut self, enabled: bool)
Enable or disable APC (ESC _ ... ST) control-string capture.
Defaults to false so ESC _ continues to decode as Alt+_.
When true, ESC _ ... ST is captured up to MAX_DCS_LEN bytes
and emitted as Event::TerminalResponse(TerminalResponse::Apc { .. }).
Sourcepub const fn with_capture_apc(self, enabled: bool) -> Self
pub const fn with_capture_apc(self, enabled: bool) -> Self
Builder variant of Self::set_capture_apc.
Sourcepub const fn capture_apc(&self) -> bool
pub const fn capture_apc(&self) -> bool
Whether APC (ESC _ ... ST) capture is enabled.
Sourcepub fn dcs_buffer_len(&self) -> usize
pub fn dcs_buffer_len(&self) -> usize
Current length of the internal DCS/APC accumulation buffer (for fuzzing/tests).
Sourcepub const fn has_pending_timeout_state(&self) -> bool
pub const fn has_pending_timeout_state(&self) -> bool
Whether the parser is currently waiting on additional bytes for a timeout-resolved sequence (bare ESC or partial UTF-8).
Sourcepub fn timeout(&mut self) -> Option<Event>
pub fn timeout(&mut self) -> Option<Event>
Handle a timeout in the input stream.
If the parser is waiting for more bytes to complete an ambiguous sequence (specifically a bare ESC), a timeout indicates the sequence has ended.
Sourcepub fn parse(&mut self, input: &[u8]) -> Vec<Event>
pub fn parse(&mut self, input: &[u8]) -> Vec<Event>
Parse input bytes and return any completed events.
Sourcepub fn parse_with<F>(&mut self, input: &[u8], emit: F)
pub fn parse_with<F>(&mut self, input: &[u8], emit: F)
Parse input bytes and emit each completed event through emit.
Sourcepub fn parse_into(&mut self, input: &[u8], events: &mut Vec<Event>)
pub fn parse_into(&mut self, input: &[u8], events: &mut Vec<Event>)
Parse input bytes and append completed events to events.
This variant lets callers reuse a scratch buffer across parses to avoid repeated allocations on hot input paths.