Module: Tuile::Keys
- Defined in:
- lib/tuile/keys.rb
Overview
Constants for keys returned by Keys.getkey and helpers for reading them from stdin. The constants are the raw escape sequences emitted by the terminal; see en.wikipedia.org/wiki/ANSI_escape_code for the encoding.
Constant Summary collapse
- DOWN_ARROW =
"\e[B"- UP_ARROW =
"\e[A"- DOWN_ARROWS =
[DOWN_ARROW, "j"].freeze
- UP_ARROWS =
[UP_ARROW, "k"].freeze
- LEFT_ARROW =
"\e[D"- RIGHT_ARROW =
"\e[C"- CTRL_LEFT_ARROW =
"\e[1;5D"- CTRL_RIGHT_ARROW =
"\e[1;5C"- ESC =
"\e"- HOME =
"\e[H"- END_ =
"\e[F"- HOMES =
Home-key sequences. xterm-style (‘HOME`) is the modern default, but the Linux console, rxvt, and tmux/screen in their default configuration emit the VT220-style `e[1~` instead. Components that handle Home should match against this array so users see consistent behavior regardless of which sequence their terminal emits.
[HOME, "\e[1~"].freeze
- ENDS_ =
End-key sequences. See HOMES for why two are recognized.
[END_, "\e[4~"].freeze
- PAGE_UP =
"\e[5~"- PAGE_DOWN =
"\e[6~"- BACKSPACE =
""- DELETE =
"\e[3~"- CTRL_H =
"\b"- BACKSPACES =
[BACKSPACE, CTRL_H].freeze
- CTRL_U =
""- CTRL_D =
""- ENTER =
" "- TAB =
"\t"- SHIFT_TAB =
The terminal sequence emitted by Shift+Tab in xterm-style terminals (CSI Z). Used by Screen for reverse focus traversal.
"\e[Z"
Class Method Summary collapse
-
.getkey ⇒ String
Grabs a key from stdin and returns it.
Class Method Details
.getkey ⇒ String
Grabs a key from stdin and returns it. Blocks until the key is obtained. Reads a full ESC key sequence; see constants above for some values returned by this function.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/tuile/keys.rb', line 69 def self.getkey char = $stdin.getch return char unless char == Keys::ESC # Escape sequence. Try to read more data. begin # Read 6 chars: mouse events are e.g. `\e[Mxyz` char += $stdin.read_nonblock(6) rescue IO::EAGAINWaitReadable # The "ESC" key pressed => only the \e char is emitted. end char end |