Class: Gloo::App::Prompt
- Inherits:
-
Object
- Object
- Gloo::App::Prompt
- Defined in:
- lib/gloo/app/prompt.rb
Instance Method Summary collapse
-
#ask(prompt = nil, default_value = nil) ⇒ Object
Show the prompt and get input.
-
#initialize(platform) ⇒ Prompt
constructor
Set up Prompt.
-
#multiline(prompt) ⇒ Object
Prompt for multiline input.
-
#select(prompt, options) ⇒ Object
Show a selection list to choose from.
-
#yes?(prompt) ⇒ Boolean
Confirmation prompt.
Constructor Details
#initialize(platform) ⇒ Prompt
Set up Prompt.
Set up Prompt with the given platform.
20 21 22 |
# File 'lib/gloo/app/prompt.rb', line 20 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.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gloo/app/prompt.rb', line 28 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) Reline.pre_input_hook = nil # 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.
50 51 52 53 54 55 56 57 |
# File 'lib/gloo/app/prompt.rb', line 50 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.
71 72 73 74 |
# File 'lib/gloo/app/prompt.rb', line 71 def select( prompt, ) i = Ask.list prompt, return [ i ] end |
#yes?(prompt) ⇒ Boolean
Confirmation prompt. Answer is yes or no.
63 64 65 66 |
# File 'lib/gloo/app/prompt.rb', line 63 def yes?( prompt ) value = Ask.confirm "#{prompt} " return value end |