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"- ESC =
"\e"- HOME =
"\e[H"- END_ =
"\e[F"- PAGE_UP =
"\e[5~"- PAGE_DOWN =
"\e[6~"- BACKSPACE =
"\u007f"- DELETE =
"\e[3~"- CTRL_H =
"\b"- BACKSPACES =
[BACKSPACE, CTRL_H].freeze
- CTRL_U =
"\u0015"- CTRL_D =
"\u0004"- ENTER =
"\u000d"
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.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tuile/keys.rb', line 49 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 |