Class: DevSystem::TtyInputCommand

Inherits:
InputCommand show all
Defined in:
lib/dev_system/sub/command/input_commands/tty_input_command.rb

Class Method Summary collapse

Methods inherited from InputCommand

call

Methods inherited from Command

call, #call, get_command_signatures

Methods inherited from Liza::Controller

color, inherited, on_connected

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Class Method Details

.multi_select(title, choices) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dev_system/sub/command/input_commands/tty_input_command.rb', line 35

def self.multi_select title, choices
  raise "choices must be a hash" unless choices.is_a? Hash
  return choices if choices.empty?
  
  options = {
    enum: ")",
    per_page: 20,
    help: "(space to select, enter to finish)",
    show_help: :always,
    default: 1..choices.count
  }
  prompt.multi_select title, choices, options
rescue TTY::Reader::InputInterrupt
  puts
  puts
  log "Control-C"
  exit
end

.pick_color(title = "Pick a color", string: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dev_system/sub/command/input_commands/tty_input_command.rb', line 19

def self.pick_color title = "Pick a color", string: nil
  options = ColorShell.colors.map { [(stick _2, "#{string} # #{_1}", :b), _1] }.to_h

  prompt.select \
    title,
    options,
    filter: true, show_help: :always, per_page: 28
rescue TTY::Reader::InputInterrupt
  puts
  puts
  log "Control-C"
  exit
end

.pick_one(title, options = ["Yes", "No"]) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/dev_system/sub/command/input_commands/tty_input_command.rb', line 8

def self.pick_one title, options = ["Yes", "No"]
  prompt.select title, options, filter: true, show_help: :always, per_page: 20
rescue TTY::Reader::InputInterrupt
  puts
  puts
  log "Control-C"
  exit
end

.promptObject



3
4
5
6
# File 'lib/dev_system/sub/command/input_commands/tty_input_command.rb', line 3

def self.prompt
  require "tty-prompt"
  @prompt ||= TTY::Prompt.new symbols: {marker: ">", radio_on: "x", radio_off: " "}
end