Skip to content
FutureBlitz

    Install

    Import std.term.input

    std.term.input

    std.term's input: what a terminal sends as keys are typed and the mouse moves, its bytes as they come, which an InputParser turns into InputEvents: keys, with xterm's sequences for the keys that type no character, and the modifiers held with them; the mouse's reports, in SGR's form or the older X10 one; and what's pasted between bracketed paste's marks.

    std/term/input.fb

    Types

    KeyCode enum

    Public Enum KeyCode

    Which key.

    std/term/input.fb, line 14

    • CHAR enum member #

      One that types a character.

    • ENTER enum member #

      Enter.

    • TAB enum member #

      Tab.

    • BACKSPACE enum member #

      Backspace.

    • ESCAPE enum member #

      Escape.

    • UP enum member #

      The up arrow.

    • DOWN enum member #

      The down arrow.

    • LEFT enum member #

      The left arrow.

    • RIGHT enum member #

      The right arrow.

    • HOME enum member #

      Home.

    • END enum member #

      End.

    • PAGE_UP enum member #

      Page Up.

    • PAGE_DOWN enum member #

      Page Down.

    • INSERT enum member #

      Insert.

    • DELETE enum member #

      Delete.

    • F1 enum member #

      F1.

    • F2 enum member #

      F2.

    • F3 enum member #

      F3.

    • F4 enum member #

      F4.

    • F5 enum member #

      F5.

    • F6 enum member #

      F6.

    • F7 enum member #

      F7.

    • F8 enum member #

      F8.

    • F9 enum member #

      F9.

    • F10 enum member #

      F10.

    • F11 enum member #

      F11.

    • F12 enum member #

      F12.

    KeyModifiers enum

    @Flags Public Enum KeyModifiers

    The keys held with another, in any mix.

    std/term/input.fb, line 72

    • NONE = 0 enum member #

      None.

    • SHIFT enum member #

      Shift.

    • ALT enum member #

      Alt, or Option.

    • CONTROL enum member #

      Control.

    KeyEvent struct

    Public Struct KeyEvent Implements Hashable, Printable

    A key typed: its Code, the Character it typed for CHAR, and the Modifiers held with it. A letter typed with Ctrl is that letter, lowercase, with CONTROL, so Ctrl+C is 'c' and CONTROL, and Ctrl+Space is ' ' and CONTROL. A capital is its own Character, without SHIFT, as a terminal sends it.

    std/term/input.fb, line 88

    • Public ReadOnly Field Code: KeyCode field #

      Which key it was.

    • Public ReadOnly Field Character: Char field #

      The character it typed, for CHAR.

    • Public ReadOnly Field Modifiers: KeyModifiers field #

      The modifiers held with it.

    • Public New(code: KeyCode, modifiers: KeyModifiers = KeyModifiers.NONE) constructor #

      A key that types no character, like UP, with the modifiers held.

    • Public New(character: Char, modifiers: KeyModifiers = KeyModifiers.NONE) constructor #

      The key that types character, with the modifiers held.

    • Public Method IsChar(c: Char): Bool method #

      Whether it typed c, without Ctrl or Alt.

    • Public Method IsControl(c: Char): Bool method #

      Whether it's Ctrl and the letter c, in either case, without Alt: IsControl('c') for Ctrl+C.

    • Public Property IsText: Bool property #

      Whether it types a character that shows, without Ctrl or Alt, as text takes it.

    • Public Method ToString(): String method #

      Like "a", "Ctrl+C", "Alt+Enter", "Shift+Up", "F5", or "Space".

    MouseButton enum

    Public Enum MouseButton

    Which of the mouse's buttons, or NONE, for a move or a scroll. The others, like a mouse's back and forward buttons, aren't reported.

    std/term/input.fb, line 146

    • NONE enum member #

      None, for a move or a scroll.

    • LEFT enum member #

      The left button.

    • MIDDLE enum member #

      The middle button, or the wheel's.

    • RIGHT enum member #

      The right button.

    MouseAction enum

    Public Enum MouseAction

    What the mouse did.

    std/term/input.fb, line 158

    • PRESS enum member #

      A button pressed.

    • RELEASE enum member #

      A button released.

    • DRAG enum member #

      A move with a button held.

    • MOVE enum member #

      A move with none held, which a terminal reports only where it's asked for every move.

    • SCROLL_UP enum member #

      Its wheel scrolled up.

    • SCROLL_DOWN enum member #

      Its wheel scrolled down.

    • SCROLL_LEFT enum member #

      Its wheel scrolled left.

    • SCROLL_RIGHT enum member #

      Its wheel scrolled right.

    MouseEvent struct

    Public Struct MouseEvent Implements Hashable, Printable

    What the mouse did, with which Button, at a Column and Row from 0, with the Modifiers held.

    std/term/input.fb, line 178

    • Public ReadOnly Field Action: MouseAction field #

      What the mouse did.

    • Public ReadOnly Field Button: MouseButton field #

      Which button it did it with.

    • Public ReadOnly Field Column: Int field #

      The column it was at, from 0.

    • Public ReadOnly Field Row: Int field #

      The row it was at, from 0.

    • Public ReadOnly Field Modifiers: KeyModifiers field #

      The modifiers held.

    • Public New(action: MouseAction, button: MouseButton, column: Int, row: Int, modifiers: KeyModifiers = KeyModifiers.NONE) constructor #

      A MouseEvent of action with button at column and row, with modifiers held.

    • Public Method ToString(): String method #

      Like "PRESS LEFT at 3, 4", or "Ctrl+SCROLL_UP at 0, 0".

    InputKind enum

    Public Enum InputKind

    What an InputEvent is.

    std/term/input.fb, line 212

    • KEY enum member #

      A key.

    • MOUSE enum member #

      The mouse.

    • RESIZE enum member #

      A resize of the terminal.

    • PASTE enum member #

      Text pasted.

    InputEvent struct

    Public Struct InputEvent Implements Printable

    Something that came from a terminal: a Key, what the Mouse did, the Columns and Rows it has after a RESIZE, or the Text PASTEd, by its Kind.

    std/term/input.fb, line 225

    • Public ReadOnly Field Kind: InputKind field #

      What it is.

    • Public ReadOnly Field Key: KeyEvent field #

      A KEY's key.

    • Public ReadOnly Field Mouse: MouseEvent field #

      A MOUSE's mouse event.

    • Public ReadOnly Field Columns: Int field #

      How many columns the terminal has after a RESIZE.

    • Public ReadOnly Field Rows: Int field #

      How many rows the terminal has after a RESIZE.

    • Public ReadOnly Field Text: String field #

      A PASTE's text.

    • Public New(key: KeyEvent) constructor #

      A key typed.

    • Public New(mouse: MouseEvent) constructor #

      What the mouse did.

    • Public New(columns: Int, rows: Int) constructor #

      The terminal's size once it's changed.

    • Public New(pasted: String) constructor #

      Text pasted.

    • Public Method IsChar(c: Char): Bool method #

      Whether it's the key that types c, as KeyEvent's IsChar says.

    • Public Method IsKey(code: KeyCode): Bool method #

      Whether it's that key without a character, with no modifiers.

    • Public Method ToString(): String method #

      Like "key Ctrl+C", "mouse PRESS LEFT at 3, 4", "resize 80x24", or "paste "text"".

    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.

    std/term/input.fb, line 292

    • Public New() constructor #

      A new InputParser, with nothing read yet.

    • @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 yet. 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 as soon as 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.