Class: TTY2::Reader::KeyEvent
- Inherits:
-
Struct
- Object
- Struct
- TTY2::Reader::KeyEvent
- Defined in:
- lib/tty2/reader/key_event.rb
Overview
Represents key event emitted during keyboard press
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#line ⇒ Object
Returns the value of attribute line.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.from(keys, char, line = Line.new) ⇒ 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
19 20 21 |
# File 'lib/tty2/reader/key_event.rb', line 19 def key @key end |
#line ⇒ Object
Returns the value of attribute line
19 20 21 |
# File 'lib/tty2/reader/key_event.rb', line 19 def line @line end |
#value ⇒ Object
Returns the value of attribute value
19 20 21 |
# File 'lib/tty2/reader/key_event.rb', line 19 def value @value end |
Class Method Details
.from(keys, char, line = Line.new) ⇒ KeyEvent
Create key event from read input codes
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tty2/reader/key_event.rb', line 29 def self.from(keys, char, line = Line.new) 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(key, char, line) end |
Instance Method Details
#trigger? ⇒ Boolean
Check if key event can be triggered
53 54 55 |
# File 'lib/tty2/reader/key_event.rb', line 53 def trigger? !key.nil? && !key.name.nil? end |