Module: CLI

Defined in:
lib/pandoras_box/cli.rb

Class Method Summary collapse

Class Method Details

.overwrite(height) ⇒ Object



45
46
47
48
49
# File 'lib/pandoras_box/cli.rb', line 45

def overwrite(height)
  height.times do
    print "\033[1A\033[K"
  end
end

.prompt_boolean(message) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/pandoras_box/cli.rb', line 5

def prompt_boolean(message)
  prompt = "#{message.green}#{' (y/n)'.blue} "
  print "#{'[ WAIT ]'.yellow} #{prompt}"
  raw_answer = STDIN.gets.chomp
  answer     = 'y' == raw_answer
  overwrite 1
  if answer
    puts "#{'[ YES ] '.green} #{prompt}"
  else
    puts "#{'[ NO ]  '.red} #{prompt}"
  end

  answer
end

.prompt_description(title, description) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/pandoras_box/cli.rb', line 37

def prompt_description(title, description)
  puts title.green.underline
  puts description.blue
  response = prompt_boolean('Use?')
  overwrite(3)
  response
end

.prompt_multiple_choice(title, choices, custom_message = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pandoras_box/cli.rb', line 20

def prompt_multiple_choice(title, choices, custom_message=nil)
  overwrite_lines = 2
  puts title.green.underline
  unless custom_message.nil?
    puts custom_message
    overwrite_lines += 1
  end

  choices.each_with_index do |choice, i|
    puts "#{"#{i})"} #{choice.blue}"
  end

  raw_answer = STDIN.gets.chomp
  overwrite(choices.length + overwrite_lines)
  raw_answer
end