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.
-
One that types a character.
-
Enter.
-
Tab.
-
Backspace.
-
Escape.
-
The up arrow.
-
The down arrow.
-
The left arrow.
-
The right arrow.
-
Home.
-
End.
-
Page Up.
-
Page Down.
-
Insert.
-
Delete.
-
F1.
-
F2.
-
F3.
-
F4.
-
F5.
-
F6.
-
F7.
-
F8.
-
F9.
-
F10.
-
F11.
-
F12.
KeyModifiers
enum
@Flags Public Enum KeyModifiers
The keys held with another, in any mix.
-
None.
-
Shift.
-
Alt, or Option.
-
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.
-
Which key it was.
-
The character it typed, for CHAR.
-
The modifiers held with it.
-
A key that types no character, like UP, with the
modifiersheld. -
The key that types
character, with themodifiersheld. -
Whether it typed
c, without Ctrl or Alt. -
Whether it's Ctrl and the letter
c, in either case, without Alt: IsControl('c') for Ctrl+C. -
Whether it types a character that shows, without Ctrl or Alt, as text takes it.
-
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.
-
None, for a move or a scroll.
-
The left button.
-
The middle button, or the wheel's.
-
The right button.
MouseAction
enum
Public Enum MouseAction
What the mouse did.
-
A button pressed.
-
A button released.
-
A move with a button held.
-
A move with none held, which a terminal reports only where it's asked for every move.
-
Its wheel scrolled up.
-
Its wheel scrolled down.
-
Its wheel scrolled left.
-
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.
-
What the mouse did.
-
Which button it did it with.
-
The column it was at, from 0.
-
The row it was at, from 0.
-
The modifiers held.
-
Public New(action: MouseAction, button: MouseButton, column: Int, row: Int, modifiers: KeyModifiers = KeyModifiers.NONE)constructor #A MouseEvent of
actionwithbuttonatcolumnandrow, withmodifiersheld. -
Like "PRESS LEFT at 3, 4", or "Ctrl+SCROLL_UP at 0, 0".
InputKind
enum
Public Enum InputKind
What an InputEvent is.
-
A key.
-
The mouse.
-
A resize of the terminal.
-
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.
-
What it is.
-
A KEY's key.
-
A MOUSE's mouse event.
-
How many columns the terminal has after a RESIZE.
-
How many rows the terminal has after a RESIZE.
-
A PASTE's text.
-
A key typed.
-
What the
mousedid. -
The terminal's size once it's changed.
-
Text
pasted. -
Whether it's the key that types
c, as KeyEvent's IsChar says. -
Whether it's that key without a character, with no modifiers.
-
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.
-
A new InputParser, with nothing read yet.
-
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 yet. 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 as soon as 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.