Class: RubyTUI::KeyEvent
Overview
A keyboard event: key code, optional character and modifier flags.
Instance Attribute Summary collapse
-
#char ⇒ Object
readonly
Returns the value of attribute char.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#modifiers ⇒ Object
readonly
Returns the value of attribute modifiers.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Value equality: same code, character and modifiers.
-
#alt? ⇒ Boolean
True if the Input::Key::ALT flag is set.
-
#ctrl? ⇒ Boolean
True if the Input::Key::CTRL flag is set.
-
#initialize(code:, char: nil, modifiers: Input::Key::NONE) ⇒ KeyEvent
constructor
A new instance of KeyEvent.
-
#shift? ⇒ Boolean
True if the Input::Key::SHIFT flag is set.
-
#to_s ⇒ String
(also: #inspect)
Human-readable form: modifier names, then the character (or the key code when there is no character), joined by +.
Constructor Details
Instance Attribute Details
#char ⇒ Object (readonly)
Returns the value of attribute char.
16 17 18 |
# File 'lib/rubytui/event.rb', line 16 def char @char end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
16 17 18 |
# File 'lib/rubytui/event.rb', line 16 def code @code end |
#modifiers ⇒ Object (readonly)
Returns the value of attribute modifiers.
16 17 18 |
# File 'lib/rubytui/event.rb', line 16 def modifiers @modifiers end |
Instance Method Details
#==(other) ⇒ Boolean
Value equality: same code, character and modifiers.
41 42 43 44 |
# File 'lib/rubytui/event.rb', line 41 def ==(other) other.is_a?(KeyEvent) && @code == other.code && @char == other.char && @modifiers == other.modifiers end |
#alt? ⇒ Boolean
Returns true if the Input::Key::ALT flag is set.
32 33 |
# File 'lib/rubytui/event.rb', line 32 def alt? = (@modifiers & Input::Key::ALT) != 0 # @return [Boolean] true if the {Input::Key::SHIFT} flag is set |
#ctrl? ⇒ Boolean
Returns true if the Input::Key::CTRL flag is set.
30 31 |
# File 'lib/rubytui/event.rb', line 30 def ctrl? = (@modifiers & Input::Key::CTRL) != 0 # @return [Boolean] true if the {Input::Key::ALT} flag is set |
#shift? ⇒ Boolean
Returns true if the Input::Key::SHIFT flag is set.
34 |
# File 'lib/rubytui/event.rb', line 34 def shift? = (@modifiers & Input::Key::SHIFT) != 0 |
#to_s ⇒ String Also known as: inspect
Human-readable form: modifier names, then the character (or the key code when there is no character), joined by +.
50 51 52 53 54 55 56 57 |
# File 'lib/rubytui/event.rb', line 50 def to_s parts = [] parts << "Ctrl" if ctrl? parts << "Alt" if alt? parts << "Shift" if shift? parts << (@char || @code.to_s) "KeyEvent(#{parts.join("+")})" end |