prettytty

Trait Scan

Source
pub trait Scan: BufRead {
    // Required methods
    fn in_flight(&self) -> bool;
    fn read_token(&mut self) -> Result<Token<'_>>;

    // Provided method
    fn read_sequence(&mut self, control: Control) -> Result<&[u8]> { ... }
}
Expand description

A scanner for UTF-8 characters and control sequences.

An implementation of this trait provides the state machine necessary for scanning UTF-8 characters and control sequences. Since scanning control sequences requires one byte lookahead, an implementation also buffers the data it reads from the terminal.

Some terminal emulators may require more than one read from terminal input to consume a complete ANSI escape sequence serving as query response. Hence Scan::read_token may perform an arbitrary number of reads from the underlying input, including none, to recognize a complete control sequence. However, an implementation must not issue reads after it has started recognizing a text token. In other words, when reading a text token, the end of buffered data also is the end of the text token.

This trait is object-safe.

Required Methods§

Source

fn in_flight(&self) -> bool

Determine if the state machine currently is in-flight.

Using a scanner as a reader is only safe if this method returns false.

Source

fn read_token(&mut self) -> Result<Token<'_>>

Read the next token.

If the internal buffer has been exhausted, this method may read from the connection upon invocation. For text tokens, it performs no further reads. That is, a text token always ends with the currently buffered data.

Provided Methods§

Source

fn read_sequence(&mut self, control: Control) -> Result<&[u8]>

Read the next token as a control sequence.

This method reads the next token and, after making sure it is a control sequence starting with the given control, returns the payload.

Implementations on Foreign Types§

Source§

impl<S: Scan + ?Sized> Scan for &mut S

A mutably borrowed scanner is a scanner.

Source§

fn in_flight(&self) -> bool

Source§

fn read_token(&mut self) -> Result<Token<'_>>

Source§

impl<S: Scan + ?Sized> Scan for Box<S>

A boxed scanner is a scanner.

Source§

fn in_flight(&self) -> bool

Source§

fn read_token(&mut self) -> Result<Token<'_>>

Implementors§

Source§

impl Scan for Input<'_>