Class: Terminal::KeyEvent
- Inherits:
-
Object
- Object
- Terminal::KeyEvent
- Defined in:
- lib/terminal/input/key_event.rb
Overview
Key event reported from read_key_event.
Class Attribute Summary collapse
-
.caching ⇒ true, false
Whether KeyCodes should be cached.
Instance Attribute Summary collapse
-
#key ⇒ String, Symbol
readonly
Pressed key without any modifiers.
-
#modifier ⇒ Integer
readonly
Modifier key code.
-
#modifier? ⇒ true, false
readonly
Whether a key modifier was pressed.
-
#name ⇒ String
readonly
Name of the key event.
-
#raw ⇒ String
readonly
Event string received from standard input.
-
#simple? ⇒ true, false
readonly
Whether a simple key was pressed.
Class Method Summary collapse
-
.[](raw) ⇒ KeyEvent
Translate a keyboard input string into a related KeyEvent.
Instance Method Summary collapse
-
#to_a ⇒ Array<Symbol, String>
All pressed keys.
Class Attribute Details
.caching ⇒ true, false
Returns whether KeyCodes should be cached.
11 |
# File 'lib/terminal/input/key_event.rb', line 11 def caching = !!@cache |
Instance Attribute Details
#key ⇒ String, Symbol (readonly)
Pressed key without any modifiers.
This can be a string for simple keys like "a"
or a Symbol like :F12
.
158 159 160 |
# File 'lib/terminal/input/key_event.rb', line 158 def key @key end |
#modifier ⇒ Integer (readonly)
Modifier key code. This represents the encoded key modifier like Shift
or Alt
.
164 165 166 |
# File 'lib/terminal/input/key_event.rb', line 164 def modifier @modifier end |
#modifier? ⇒ true, false (readonly)
Returns whether a key modifier was pressed.
179 |
# File 'lib/terminal/input/key_event.rb', line 179 def modifier? = @modifier != 0 |
#name ⇒ String (readonly)
Name of the key event.
This can be a simple name like "a"
or "Shift+Ctrl+F12"
for combined
keys.
175 176 177 |
# File 'lib/terminal/input/key_event.rb', line 175 def name @name end |
#raw ⇒ String (readonly)
Event string received from standard input.
This can be a simple value like "a"
or more complex input like
"\e[24;6~"
(for Shift+Ctrl+F12).
153 154 155 |
# File 'lib/terminal/input/key_event.rb', line 153 def raw @raw end |
#simple? ⇒ true, false (readonly)
Returns whether a simple key was pressed.
183 |
# File 'lib/terminal/input/key_event.rb', line 183 def simple? = @raw == @name |
Class Method Details
.[](raw) ⇒ KeyEvent
Translate a keyboard input string into a related KeyEvent
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/terminal/input/key_event.rb', line 26 def [](raw) return new(raw, *@single_key[raw.ord]) if raw.size == 1 return unknown(raw) if raw[0] != "\e" return esc1(raw, raw[1]) if raw.size == 2 # ESC ? case raw[1] when "\e" # ESC ESC ... return esc_esc(raw) when 'O' return new(raw, *@ss3[raw[2].ord]) if raw.size == 3 # ESC O ? when '[' return new(raw, *@ss3[raw[2].ord]) if raw.size == 3 # ESC [ ? if raw.size == 6 && raw[2] == 'M' # ESC [ M b c r return mouse_vt200(raw) end return csi1(raw) if raw.start_with?("\e[1;") # ESC [ 1 ; ... case raw[-1] when '~' # ESC [ ... ~ return legacy(raw) when 'u' # ESC [ ... u return csi_u(raw) when 'M' # ESC [ ... M return raw[2] == '<' ? mouse_sgr(raw) : mouse_urxvt(raw) when 'm' # ESC [ ... m return mouse_sgr(raw) if raw[2] == '<' end end unknown(raw) end |