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 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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.