gsh/input/key
The key module defines the domain model for terminal input events.
When the TTY operates in raw mode, user keystrokes—ranging from single UTF-8 graphemes to multi-byte ANSI escape sequences (e.g., arrow keys, word navigation)— are captured as raw byte streams. This module provides an algebraic data type to abstract low-level TTY sequences into structured events for the editor.
Types
Represents a parsed keystroke or control sequence captured from raw terminal input.
pub type Key {
Character(String)
Enter
Backspace
Tab
ArrowUp
ArrowDown
ArrowLeft
ArrowRight
CtrlL
End
Home
CtrlLeft
CtrlRight
Unknown
}
Constructors
-
Character(String)A printable UTF-8 character grapheme (e.g.,
"a","Z","5"," "). -
EnterThe Return/Enter key, signaling prompt submission or line insertion.
-
BackspaceThe Backspace key, used to remove the character grapheme preceding the cursor.
-
TabThe Tab key, used to trigger predictive autocompletion and candidate grid menus.
-
ArrowUpThe Up Arrow key, used for upward 2D cursor traversal or history retrieval.
-
ArrowDownThe Down Arrow key, used for downward 2D cursor traversal or history retrieval.
-
ArrowLeftThe Left Arrow key, used to move the cursor backward by one grapheme.
-
ArrowRightThe Right Arrow key, used to move the cursor forward by one grapheme.
-
CtrlLThe
Ctrl+Lchord, triggering a screen clear while preserving active buffer state. -
EndThe Home key (or
Fn+Left), repositioning the cursor to the start of the current line. -
HomeThe End key (or
Fn+Right), repositioning the cursor to the end of the current line. -
CtrlLeftThe
Ctrl+Leftchord, jumping the cursor backward across word boundaries. -
CtrlRightThe
Ctrl+Rightchord, jumping the cursor forward across word boundaries. -
UnknownUnrecognized or unhandled ANSI escape sequences (e.g., function keys, scroll lock).