Class: GitWaybackMachine::Controls

Inherits:
Object
  • Object
show all
Defined in:
lib/git_wayback_machine/controls.rb

Instance Method Summary collapse

Constructor Details

#initializeControls

Returns a new instance of Controls.



5
6
# File 'lib/git_wayback_machine/controls.rb', line 5

def initialize
end

Instance Method Details

#on_event(&callback) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/git_wayback_machine/controls.rb', line 8

def on_event(&callback)
  while true
    case read_key
    when "\e[A"      then callback.call(:up)    # UP
    when "\e[B"      then callback.call(:down)  # DOWN
    when "\r", "\n"  then callback.call(:enter) # ENTER
    when "\u0003", "\e" # Ctrl+C, ESC
      exit(0)
    end
  end
end