pub struct Parser<'alloc>(/* private fields */);Expand description
OSC (Operating System Command) sequence parser and command handling.
The parser operates in a streaming fashion, processing input byte-by-byte to handle OSC sequences that may arrive in fragments across multiple reads. This interface makes it easy to integrate into most environments and avoids over-allocating buffers.
Implementations§
Source§impl<'alloc> Parser<'alloc>
impl<'alloc> Parser<'alloc>
Sourcepub fn new_with_alloc<'ctx: 'alloc, Ctx>(
alloc: &'alloc Allocator<'ctx, Ctx>,
) -> Result<Self>
pub fn new_with_alloc<'ctx: 'alloc, Ctx>( alloc: &'alloc Allocator<'ctx, Ctx>, ) -> Result<Self>
Create a new OSC parser with a custom allocator.
See the crate-level documentation regarding custom memory management and lifetimes.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset an OSC parser instance to its initial state.
Resets the parser state, clearing any partially parsed OSC sequences and returning the parser to its initial state. This is useful for reusing a parser instance or recovering from parse errors.
Sourcepub fn next_byte(&mut self, byte: u8)
pub fn next_byte(&mut self, byte: u8)
Parse the next byte in an OSC sequence.
Processes a single byte as part of an OSC sequence. The parser maintains internal state to track the progress through the sequence. Call this function for each byte in the sequence data.
When finished pumping the parser with bytes, call Parser::end to
get the final result.
Sourcepub fn end<'p>(&'p mut self, terminator: u8) -> Command<'p, 'alloc>
pub fn end<'p>(&'p mut self, terminator: u8) -> Command<'p, 'alloc>
Finalize OSC parsing and retrieve the parsed command.
Call this function after feeding all bytes of an OSC sequence to the parser
using Parser::next_byte with the exception of the terminating character
(ESC or ST). This function finalizes the parsing process and returns the
parsed OSC command. Invalid commands will return a command with type
CommandType::Invalid.
The terminator parameter specifies the byte that terminated the OSC sequence (typically 0x07 for BEL or 0x5C for ST after ESC). This information is preserved in the parsed command so that responses can use the same terminator format for better compatibility with the calling program. For commands that do not require a response, this parameter is ignored and the resulting command will not retain the terminator information.