Module: AiCli::Helpers::ScriptActionMenu

Defined in:
lib/aicli/helpers/script_action_menu.rb

Defined Under Namespace

Classes: Menu

Constant Summary collapse

MARKER =
''

Class Method Summary collapse

Class Method Details

.build_choices(config, silent_mode, empty_script) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/aicli/helpers/script_action_menu.rb', line 15

def build_choices(config, silent_mode, empty_script)
  items = []
  unless empty_script
    items << choice('y', :yes, I18n.t('Yes'))
    items << choice('m', :edit, I18n.t('Modify'))
    unless silent_mode || config['SILENT_MODE']
      items << choice('e', :explain, I18n.t('Explain'))
    end
  end
  items << choice('r', :revise, I18n.t('Revise'))
  items << choice('c', :copy, I18n.t('Copy'))
  items << choice('x', :cancel, I18n.t('Exit'))
  items
end

.choice(key, value, label) ⇒ Object



30
31
32
# File 'lib/aicli/helpers/script_action_menu.rb', line 30

def choice(key, value, label)
  { key: key, value: value, label: shortcut_label(label, key) }
end

.select(question:, config:, silent_mode:, empty_script: false) ⇒ Object



10
11
12
13
# File 'lib/aicli/helpers/script_action_menu.rb', line 10

def select(question:, config:, silent_mode:, empty_script: false)
  choices = build_choices(config, silent_mode, empty_script)
  Menu.new(question, choices).ask
end

.shortcut_label(text, key) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/aicli/helpers/script_action_menu.rb', line 34

def shortcut_label(text, key)
  idx = text.downcase.index(key.downcase)
  return text unless idx

  result = text.downcase
  result[idx] = result[idx].upcase
  result
end