Class: Legion::TTY::Hotkeys

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/tty/hotkeys.rb

Instance Method Summary collapse

Constructor Details

#initializeHotkeys

Returns a new instance of Hotkeys.



6
7
8
# File 'lib/legion/tty/hotkeys.rb', line 6

def initialize
  @bindings = {}
end

Instance Method Details

#handle(key) ⇒ Object

rubocop:disable Naming/PredicateMethod



15
16
17
18
19
20
21
# File 'lib/legion/tty/hotkeys.rb', line 15

def handle(key)
  binding_entry = @bindings[key]
  return false unless binding_entry

  binding_entry[:action].call
  true
end

#listObject

rubocop:enable Naming/PredicateMethod



24
25
26
# File 'lib/legion/tty/hotkeys.rb', line 24

def list
  @bindings.map { |key, b| { key: key, description: b[:description] } }
end

#register(key, description, &block) ⇒ Object



10
11
12
# File 'lib/legion/tty/hotkeys.rb', line 10

def register(key, description, &block)
  @bindings[key] = { description: description, action: block }
end