Import std.term.input
InputParser
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)-
A new InputParser, with nothing read.
-
Takes the first
countofbytes, as they came. Panics for a count below 0 or past whatbyteshas. -
Takes
text's bytes, as they came. -
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.
-
Whether a paste has started and waits for its end mark, which a terminal sends right after the text, however long it is.
-
The next event in what's come, or Null until all its bytes have.
-
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.