Class: Gloo::App::Prompt

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/app/prompt.rb

Instance Method Summary collapse

Constructor Details

#initialize(platform) ⇒ Prompt

Set up Prompt.



19
20
21
# File 'lib/gloo/app/prompt.rb', line 19

def initialize platform
  @platform = platform
end

Instance Method Details

#ask(prompt = nil) ⇒ Object

Show the prompt and get input. Use the default prompt if none is provided.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gloo/app/prompt.rb', line 27

def ask( prompt=nil )
  prompt ||= default_prompt

  response = Reline.readline( "#{prompt} ", true)

  # I don't like this one because it appends a ':' to the prompt.
  # response = Ask.input prompt

  # This was just the brute force way to do it.
  # puts prompt
  # return $stdin.gets.chomp

  return response
end

#multiline(prompt) ⇒ Object

Prompt for multiline input.



45
46
47
48
49
50
51
52
# File 'lib/gloo/app/prompt.rb', line 45

def multiline( prompt )
  puts 'To end input, type a period on a line by itself.'
  text = Reline.readmultiline( "#{prompt} ", true ) do |input|
    input.split.last == '.'
  end
    
  return text.lines[0..-2]
end

#select(prompt, options) ⇒ Object

Show a selection list to choose from.



66
67
68
69
# File 'lib/gloo/app/prompt.rb', line 66

def select( prompt, options )
  i = Ask.list prompt, options
  return options[ i ]
end

#yes?(prompt) ⇒ Boolean

Confirmation prompt. Answer is yes or no.

Returns:

  • (Boolean)


58
59
60
61
# File 'lib/gloo/app/prompt.rb', line 58

def yes?( prompt )
  value = Ask.confirm "#{prompt} "
  return value
end