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, default_value = 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
41
42
43
# File 'lib/gloo/app/prompt.rb', line 27

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

  if default_value
    Reline.pre_input_hook = proc { Reline.insert_text( default_value ) }
  end
  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.



48
49
50
51
52
53
54
55
# File 'lib/gloo/app/prompt.rb', line 48

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.



69
70
71
72
# File 'lib/gloo/app/prompt.rb', line 69

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)


61
62
63
64
# File 'lib/gloo/app/prompt.rb', line 61

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