Class: Vedeu::Input::Mapper Private
- Inherits:
-
Object
- Object
- Vedeu::Input::Mapper
- Extended by:
- Common
- Defined in:
- lib/vedeu/input/mapper.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Maps keys to keymaps.
Instance Attribute Summary collapse
- #key ⇒ NilClass|String|Symbol|Vedeu::Cursors::Cursor readonly protected private
- #repository ⇒ Vedeu::Repositories::Repository readonly protected private
Class Method Summary collapse
-
.keypress(key = nil, name = nil) ⇒ Boolean
private
Takes a key as a keypress and sends it to registered keymaps.
- .registered?(key = nil, name = nil) ⇒ Boolean private
-
.valid?(key = nil, name = nil) ⇒ Boolean
private
Checks a key is valid; i.e.
Instance Method Summary collapse
-
#global_key? ⇒ Boolean
private
private
Is the key a global key?.
-
#initialize(key = nil, name = nil, repository = nil) ⇒ Vedeu::Input::Mapper
constructor
private
Returns a new instance of Vedeu::Input::Mapper.
-
#key_defined?(named = name) ⇒ Boolean
(also: #registered?)
private
Is the key defined in the named keymap?.
-
#keymap(named = name) ⇒ Vedeu::Input::Keymap
private
private
Fetch the named keymap from the repository.
-
#keymap?(named = name) ⇒ Boolean
private
private
Does the keymaps repository have the named keymap already registered?.
-
#keypress ⇒ Boolean
private
Returns a boolean indicating that the key is registered to the current keymap, or the global keymap.
- #log_message(key) ⇒ String private private
-
#name ⇒ String|NilClass
(also: #interface)
private
private
With a name, we check the keymap with that name, otherwise we use the name of the interface currently in focus.
-
#valid? ⇒ Boolean
private
Returns a boolean indicating that the key is not registered to the current keymap, or the global keymap.
Methods included from Common
absent?, array?, boolean, boolean?, empty_value?, escape?, falsy?, hash?, line_model?, numeric?, positionable?, present?, snake_case, stream_model?, string?, symbol?, truthy?, view_model?
Constructor Details
#initialize(key = nil, name = nil, repository = nil) ⇒ Vedeu::Input::Mapper
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Vedeu::Input::Mapper.
65 66 67 68 69 |
# File 'lib/vedeu/input/mapper.rb', line 65 def initialize(key = nil, name = nil, repository = nil) @key = key @name = name @repository = repository || Vedeu.keymaps end |
Instance Attribute Details
#key ⇒ NilClass|String|Symbol|Vedeu::Cursors::Cursor (readonly, protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
112 113 114 |
# File 'lib/vedeu/input/mapper.rb', line 112 def key @key end |
#repository ⇒ Vedeu::Repositories::Repository (readonly, protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
116 117 118 |
# File 'lib/vedeu/input/mapper.rb', line 116 def repository @repository end |
Class Method Details
.keypress(key = nil, name = nil) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Takes a key as a keypress and sends it to registered keymaps. If found, the associated action is fired, otherwise, we move to the next keymap or return false.
26 27 28 |
# File 'lib/vedeu/input/mapper.rb', line 26 def keypress(key = nil, name = nil) new(key, name).keypress end |
.registered?(key = nil, name = nil) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vedeu/input/mapper.rb', line 34 def registered?(key = nil, name = nil) raise Vedeu::Error::MissingRequired, 'Cannot check whether a key is registered to a keymap ' \ 'without the key.' if absent?(key) raise Vedeu::Error::MissingRequired, 'Cannot check whether a key is registered to a keymap ' \ 'without the keymap name.' if absent?(name) new(key, name).registered? end |
.valid?(key = nil, name = nil) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks a key is valid; i.e. not already registered to a keymap. When the key is registered, then the key is invalid and cannot be used again.
51 52 53 54 55 |
# File 'lib/vedeu/input/mapper.rb', line 51 def valid?(key = nil, name = nil) return false unless key new(key, name).valid? end |
Instance Method Details
#global_key? ⇒ Boolean (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Is the key a global key?
123 124 125 |
# File 'lib/vedeu/input/mapper.rb', line 123 def global_key? key_defined?('_global_') end |
#key_defined?(named = name) ⇒ Boolean Also known as: registered?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Is the key defined in the named keymap?
93 94 95 |
# File 'lib/vedeu/input/mapper.rb', line 93 def key_defined?(named = name) keymap?(named) && keymap(named).key_defined?(key) end |
#keymap(named = name) ⇒ Vedeu::Input::Keymap (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Fetch the named keymap from the repository.
131 132 133 |
# File 'lib/vedeu/input/mapper.rb', line 131 def keymap(named = name) repository.find(named) end |
#keymap?(named = name) ⇒ Boolean (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Does the keymaps repository have the named keymap already registered?
140 141 142 |
# File 'lib/vedeu/input/mapper.rb', line 140 def keymap?(named = name) repository.registered?(named) end |
#keypress ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating that the key is registered to the current keymap, or the global keymap.
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/vedeu/input/mapper.rb', line 75 def keypress Vedeu.trigger(:key, key) return false unless key return true if key_defined? && keymap.use(key) return true if global_key? && keymap('_global_').use(key) Vedeu.log(type: :input, message: (key)) false end |
#log_message(key) ⇒ String (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
146 147 148 149 150 151 152 153 154 |
# File 'lib/vedeu/input/mapper.rb', line 146 def (key) if key.is_a?(Vedeu::Cursors::Cursor) "Click detected: x: #{key.x} y: #{key.y}" else "Key detected: #{key.inspect}" end end |
#name ⇒ String|NilClass (private) Also known as: interface
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
With a name, we check the keymap with that name, otherwise we use the name of the interface currently in focus.
160 161 162 |
# File 'lib/vedeu/input/mapper.rb', line 160 def name @name || Vedeu.focus end |
#valid? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating that the key is not registered to the current keymap, or the global keymap.
102 103 104 105 106 |
# File 'lib/vedeu/input/mapper.rb', line 102 def valid? return false if !key || key_defined? || global_key? true end |