Skip to main content

InputParser

Struct InputParser 

Source
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

Source

pub fn new() -> Self

Create a new input parser.

Source

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.

Source

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.

Source

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).

Source

pub const fn with_pixel_mouse(self, enabled: bool) -> Self

Builder variant of Self::set_pixel_mouse.

Source

pub const fn pixel_mouse(&self) -> bool

Whether SGR-Pixels (?1016h) mouse mode is enabled.

Source

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.

Source

pub const fn cell_size_px(&self) -> Option<(u16, u16)>

Current cell size in pixels (width, height), if known.

Source

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 { .. }).

Source

pub const fn with_capture_apc(self, enabled: bool) -> Self

Builder variant of Self::set_capture_apc.

Source

pub const fn capture_apc(&self) -> bool

Whether APC (ESC _ ... ST) capture is enabled.

Source

pub fn dcs_buffer_len(&self) -> usize

Current length of the internal DCS/APC accumulation buffer (for fuzzing/tests).

Source

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).

Source

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.

Source

pub fn parse(&mut self, input: &[u8]) -> Vec<Event>

Parse input bytes and return any completed events.

Source

pub fn parse_with<F>(&mut self, input: &[u8], emit: F)
where F: FnMut(Event),

Parse input bytes and emit each completed event through emit.

Source

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.

Trait Implementations§

Source§

impl Debug for InputParser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for InputParser

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.