Skip to main content

parse_sequence_prefix

Function parse_sequence_prefix 

Source
pub fn parse_sequence_prefix(input: &[u8]) -> Option<(KeyMsg, usize)>
Expand description

Parse a raw ANSI escape sequence from the start of the input.

This function attempts to find the longest known ANSI escape sequence that matches the beginning of the input slice.

§Arguments

  • input - A byte slice

§Returns

Returns Some((KeyMsg, usize)) where usize is the number of bytes consumed, or None if no sequence matched the start of the input.

§Example

use bubbletea::{parse_sequence_prefix, KeyType};

let input = b"\x1b[A\x1b[B";
let (key, len) = parse_sequence_prefix(input).unwrap();
assert_eq!(key.key_type, KeyType::Up);
assert_eq!(len, 3);