Class: FunCi::Tui::KeyHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/fun_ci/tui/key_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(board_data:) ⇒ KeyHandler

Returns a new instance of KeyHandler.



8
9
10
11
12
# File 'lib/fun_ci/tui/key_handler.rb', line 8

def initialize(board_data:)
  @board_data = board_data
  @cursor_index = nil
  @confirm_cancel = nil
end

Instance Attribute Details

#cursor_indexObject (readonly)

Returns the value of attribute cursor_index.



6
7
8
# File 'lib/fun_ci/tui/key_handler.rb', line 6

def cursor_index
  @cursor_index
end

Instance Method Details

#confirmation_runObject



36
37
38
# File 'lib/fun_ci/tui/key_handler.rb', line 36

def confirmation_run
  @confirm_cancel
end

#confirming?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/fun_ci/tui/key_handler.rb', line 32

def confirming?
  !@confirm_cancel.nil?
end

#handle_key(key) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fun_ci/tui/key_handler.rb', line 14

def handle_key(key)
  if @confirm_cancel
    handle_confirm_key(key)
    return
  end

  case key
  when "q"
    :quit
  when "j", :down
    move_cursor_down
  when "k", :up
    move_cursor_up
  when "c"
    initiate_cancel
  end
end