Class: Fatty::KeyGesture
- Inherits:
-
Object
- Object
- Fatty::KeyGesture
- Defined in:
- lib/fatty/key_map.rb
Overview
This struct is used as a key into the KeyMap. It represents only those parts of the KeyEvent that are relevant for resolving bindings. It also normalizes the use of uppercase letters, like 'G' to convert them to a canonical :g with shift: true. That way the user can bind either to mean the same thing. KeyGesture = Struct.new(:key, :ctrl, :meta, :shift, keyword_init: true) do
Instance Attribute Summary collapse
-
#ctrl ⇒ Object
readonly
Returns the value of attribute ctrl.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#shift ⇒ Object
readonly
Returns the value of attribute shift.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(key:, ctrl:, meta:, shift:) ⇒ KeyGesture
constructor
A new instance of KeyGesture.
- #inspect ⇒ Object
Constructor Details
#initialize(key:, ctrl:, meta:, shift:) ⇒ KeyGesture
Returns a new instance of KeyGesture.
15 16 17 18 19 20 |
# File 'lib/fatty/key_map.rb', line 15 def initialize(key:, ctrl:, meta:, shift:) @key = key @ctrl = ctrl @meta = @shift = shift end |
Instance Attribute Details
#ctrl ⇒ Object (readonly)
Returns the value of attribute ctrl.
13 14 15 |
# File 'lib/fatty/key_map.rb', line 13 def ctrl @ctrl end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
13 14 15 |
# File 'lib/fatty/key_map.rb', line 13 def key @key end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
13 14 15 |
# File 'lib/fatty/key_map.rb', line 13 def @meta end |
#shift ⇒ Object (readonly)
Returns the value of attribute shift.
13 14 15 |
# File 'lib/fatty/key_map.rb', line 13 def shift @shift end |
Class Method Details
.from_event(ev) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fatty/key_map.rb', line 22 def self.from_event(ev) k = ev&.key ctrl = !!ev&.ctrl = !!ev&. shift = !!ev&.shift if k.is_a?(Symbol) s = k.to_s if s.length == 1 ch = s[0] if ('A'..'Z').cover?(ch) # Decoder (or config) used :G. Canonicalize to :g + shift. k = ch.downcase.to_sym shift = true elsif ('a'..'z').cover?(ch) # Decoder used :g. Keep it, but allow explicit shift to mean uppercase. k = ch.to_sym end end end new(key: k, ctrl: ctrl, meta: , shift: shift) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
46 47 48 49 50 51 52 |
# File 'lib/fatty/key_map.rb', line 46 def ==(other) other.is_a?(self.class) && key == other.key && ctrl == other.ctrl && == other. && shift == other.shift end |
#hash ⇒ Object
55 56 57 |
# File 'lib/fatty/key_map.rb', line 55 def hash [self.class, key, ctrl, , shift].hash end |
#inspect ⇒ Object
59 60 61 |
# File 'lib/fatty/key_map.rb', line 59 def inspect "#<#{self.class} key=#{key.inspect} ctrl=#{ctrl} meta=#{} shift=#{shift}>" end |