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



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

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

  binding_entry[:action].call
end

#listObject



21
22
23
# File 'lib/legion/tty/hotkeys.rb', line 21

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