Class: Vedeu::Input::Mapper Private

Inherits:
Object
  • Object
show all
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.

API:

  • private

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.

API:

  • private



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

#keyNilClass|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.

API:

  • private



112
113
114
# File 'lib/vedeu/input/mapper.rb', line 112

def key
  @key
end

#repositoryVedeu::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.

API:

  • private



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.

Examples:

Vedeu.keypress(key_name, keymap_name)

API:

  • private



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.

Raises:

  • When the required argument or parameter was given but without a meaningful or usable value (e.g. nil).

API:

  • private



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.

API:

  • private



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?

API:

  • private



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?

API:

  • private



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.

API:

  • private



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?

API:

  • private



140
141
142
# File 'lib/vedeu/input/mapper.rb', line 140

def keymap?(named = name)
  repository.registered?(named)
end

#keypressBoolean

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.

API:

  • private



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: log_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.

API:

  • private



146
147
148
149
150
151
152
153
154
# File 'lib/vedeu/input/mapper.rb', line 146

def log_message(key)
  if key.is_a?(Vedeu::Cursors::Cursor)
    "Click detected: x: #{key.x} y: #{key.y}"

  else
    "Key detected: #{key.inspect}"

  end
end

#nameString|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.

API:

  • private



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.

API:

  • private



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