Table of Contents

Class InputParser

Namespace
Retro.Crt.Input
Assembly
Retro.Crt.dll

Pure parsers for terminal input streams: ANSI key escape sequences, SGR-encoded mouse reports (mode 1006), control bytes, and printable chars. Stateless — pass the unread tail of your input buffer in, advance by the returned consumed count on success.

public static class InputParser
Inheritance
InputParser
Inherited Members

Remarks

What's recognized:

  • Single control bytes: ESC, Enter, Tab, Backspace, Ctrl+letter.
  • Alt-prefixed printables: ESC followed by a printable char.
  • CSI cursor keys: ESC[A/B/C/D/H/F, plus modified ESC[1;mod A..F.
  • CSI tilde keys: ESC[2~=Insert, 3~=Delete, 5~=PageUp, 6~=PageDown, plus F5..F12 as 15~..24~; modifiers via ESC[code;mod ~.
  • SS3 function keys: ESC O P/Q/R/S = F1..F4. Modified F1..F4 arrive as ESC[1;mod P..S.
  • SGR mouse reports: ESC[<button;x;y M/m.
  • Printable BMP chars (anything ≥ 0x20 outside control bytes).

Methods

TryParseEvent(ReadOnlySpan<char>, out InputEvent, out int)

Try to parse the next event (key or mouse) from input. The discriminator on the returned ev tells you which slot is populated.

public static InputParseStatus TryParseEvent(ReadOnlySpan<char> input, out InputEvent ev, out int consumed)

Parameters

input ReadOnlySpan<char>
ev InputEvent
consumed int

Returns

InputParseStatus

TryParseKey(ReadOnlySpan<char>, out KeyEvent, out int)

Try to parse one key event from input. Reports printable BMP chars as Glyph and decoded special keys as their named Key value. Mouse reports (CSI <…) are NOT handled here — they short-circuit to Invalid.

public static InputParseStatus TryParseKey(ReadOnlySpan<char> input, out KeyEvent key, out int consumed)

Parameters

input ReadOnlySpan<char>
key KeyEvent
consumed int

Returns

InputParseStatus

TryParseMouse(ReadOnlySpan<char>, out MouseEvent, out int)

Try to parse one SGR-encoded mouse report (xterm mode 1006) from input. The expected envelope is ESC [ < button ; x ; y M_or_m.

public static InputParseStatus TryParseMouse(ReadOnlySpan<char> input, out MouseEvent mouse, out int consumed)

Parameters

input ReadOnlySpan<char>
mouse MouseEvent
consumed int

Returns

InputParseStatus