Class: TTY::Reader::KeyEvent
- Inherits:
-
Struct
- Object
- Struct
- TTY::Reader::KeyEvent
- Defined in:
- lib/tty/reader/key_event.rb
Overview
Represents key event emitted during keyboard press
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.from(keys, char) ⇒ KeyEvent
Create key event from read input codes.
Instance Method Summary collapse
-
#trigger? ⇒ Boolean
Check if key event can be triggered.
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key
20 21 22 |
# File 'lib/tty/reader/key_event.rb', line 20 def key @key end |
#value ⇒ Object
Returns the value of attribute value
20 21 22 |
# File 'lib/tty/reader/key_event.rb', line 20 def value @value end |
Class Method Details
.from(keys, char) ⇒ KeyEvent
Create key event from read input codes
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tty/reader/key_event.rb', line 30 def self.from(keys, char) key = Key.new key.name = (name = keys[char]) ? name : :ignore case char when proc { |c| c =~ /^[a-z]{1}$/ } key.name = :alpha when proc { |c| c =~ /^[A-Z]{1}$/ } key.name = :alpha key.shift = true when proc { |c| c =~ /^\d+$/ } key.name = :num when proc { |cs| !Keys.ctrl_keys[cs].nil? } key.ctrl = true end new(char, key) end |
Instance Method Details
#trigger? ⇒ Boolean
Check if key event can be triggered
54 55 56 |
# File 'lib/tty/reader/key_event.rb', line 54 def trigger? !key.nil? && !key.name.nil? end |