Skip to content
FutureBlitz

    Install

    Import std.term.input

    InputParser

    std.term.input

    class

    Public Class InputParser

    Turns the bytes a terminal sends into InputEvents. Feed it bytes as they come, and Next gives each event once all its bytes have. An escape alone may be ESCAPE or the start of a longer sequence, so it waits: IsWaiting says so, and Flush takes it as ESCAPE when nothing more has come for a moment. A sequence it doesn't know is skipped. "\r\n" is one ENTER, as a line from a pipe or a file ends.

    Examples

    Local parser = InputParser()
    parser.Feed("a\x1B[A")
    Expect(parser.Next()?.IsChar('a') == True)
    Expect(parser.Next()?.IsKey(KeyCode.UP) == True)
    Expect(parser.Next() == Null)

    std/term/input.fb, line 313

    • Public New() constructor #

      A new InputParser, with nothing read.

    • @PanicsAtCaller Public Method Feed(bytes: UInt8[], count: Int) method #

      Takes the first count of bytes, as they came. Panics for a count below 0 or past what bytes has.

    • Public Method Feed(text: String) method #

      Takes text's bytes, as they came.

    • Public Property IsWaiting: Bool property #

      Whether it has bytes Next hasn't made events of. Once Next gives Null, they wait for more, like an escape alone, which Flush takes as ESCAPE.

    • Public Property IsPasting: Bool property #

      Whether a paste has started and waits for its end mark, which a terminal sends right after the text, however long it is.

    • Public Method Next(): InputEvent? method #

      The next event in what's come, or Null until all its bytes have.

    • Public Method Flush(): InputEvent? method #

      The next event, taking what waits as it is, since no more of it is coming: an escape alone as ESCAPE, a sequence cut short as the keys its bytes are, and a paste without its end as all of it. Null once nothing is left.

    Report an issue with this page or with FutureBlitz on GitHub.