Class: Dev::UI::InteractivePrompt

Inherits:
Object
  • Object
show all
Defined in:
lib/dev/ui/interactive_prompt.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ InteractivePrompt

Returns a new instance of InteractivePrompt.



11
12
13
14
15
16
# File 'lib/dev/ui/interactive_prompt.rb', line 11

def initialize(options)
  @options = options
  @active = 1
  @marker = '>'
  @answer = nil
end

Class Method Details

.call(options) ⇒ Object



6
7
8
9
# File 'lib/dev/ui/interactive_prompt.rb', line 6

def self.call(options)
  list = new(options)
  options[list.call - 1]
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dev/ui/interactive_prompt.rb', line 18

def call
  Dev::UI.raw { print(ANSI.hide_cursor) }
  while @answer.nil?
    render_options
    wait_for_user_input

    # This will put us back at the beginning of the options
    # When we redraw the options, they will be overwritten
    Dev::UI.raw do
      @options.size.times { print(ANSI.previous_line) }
      print(ANSI.previous_line + ANSI.end_of_line + "\n")
    end
  end
  render_options
  @answer
ensure
  Dev::UI.raw do
    print(ANSI.show_cursor)
    puts(ANSI.previous_line + ANSI.end_of_line)
  end
end