Class: Kitsune::Kit::Tui::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/kitsune/kit/tui/controller.rb

Constant Summary collapse

CONFIRMATIONS =
{
  apply: "Apply the visible plan?",
  resume: "Resume the latest incomplete run?"
}.freeze
SCREEN_KEYS =
{ "p" => %i[plan plan], "d" => %i[doctor doctor] }.freeze
SIMPLE_KEYS =
{ "l" => :logs, "?" => :help, "a" => :apply, "r" => :resume }.freeze
{ "j" => 1, down: 1, "k" => -1, up: -1 }.freeze
SCROLL_KEYS =
{ page_up: 5, page_down: -5 }.freeze
SCREENS =
%i[dashboard plan doctor logs help].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store:, actions:) ⇒ Controller

Returns a new instance of Controller.



19
20
21
22
23
24
25
# File 'lib/kitsune/kit/tui/controller.rb', line 19

def initialize(store:, actions:)
  @store = store
  @actions = actions
  @exit_requested = false
  @worker = nil
  @pending_action = nil
end

Instance Attribute Details

#exit_requestedObject (readonly)

Returns the value of attribute exit_requested.



17
18
19
# File 'lib/kitsune/kit/tui/controller.rb', line 17

def exit_requested
  @exit_requested
end

Instance Method Details

#busy?Boolean

Returns:

  • (Boolean)


42
# File 'lib/kitsune/kit/tui/controller.rb', line 42

def busy? = @worker&.alive? || false

#handle(key) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kitsune/kit/tui/controller.rb', line 27

def handle(key)
  return if key.nil?
  return handle_modal(key) if store.snapshot.modal
  return run_screen_action(key) if SCREEN_KEYS.key?(key)
  return handle_simple(SIMPLE_KEYS.fetch(key)) if SIMPLE_KEYS.key?(key)
  return navigate(NAVIGATION_KEYS.fetch(key)) if NAVIGATION_KEYS.key?(key)
  return store.scroll(SCROLL_KEYS.fetch(key)) if SCROLL_KEYS.key?(key)

  case key
  when "q" then request_exit
  when "\u0003" then cancel_or_exit
  when "\t" then cycle_screen
  end
end

#startObject



44
# File 'lib/kitsune/kit/tui/controller.rb', line 44

def start = run(:status, screen: :dashboard)

#waitObject



46
47
48
# File 'lib/kitsune/kit/tui/controller.rb', line 46

def wait
  @worker&.join
end