Class: Confirm
- Inherits:
-
Object
- Object
- Confirm
- Defined in:
- lib/inquirer/prompts/confirm.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(question = nil, default = nil, renderer = nil, responseRenderer = nil) ⇒ Confirm
constructor
A new instance of Confirm.
-
#run(clear, response) ⇒ Object
- Run the list selection, wait for the user to select an item and return the selected index Params:
clear
Bool
whether to clear the selection prompt once this is done defaults to true; set it to false if you want the prompt to remain after the user is done with selectingresponse
-
Bool
whether show the rendered response when this is done defaults to true; set it to false if you want the prompt to remain after the user is done with selecting.
- Run the list selection, wait for the user to select an item and return the selected index Params:
- #update_prompt ⇒ Object
- #update_response ⇒ Object
Constructor Details
#initialize(question = nil, default = nil, renderer = nil, responseRenderer = nil) ⇒ Confirm
Returns a new instance of Confirm.
48 49 50 51 52 53 54 55 |
# File 'lib/inquirer/prompts/confirm.rb', line 48 def initialize question = nil, default = nil, renderer = nil, responseRenderer = nil @question = question @value = "" @default = default @prompt = "" @renderer = renderer || ConfirmDefault.new( Inquirer::Style::Default ) @responseRenderer = responseRenderer = ConfirmResponseDefault.new() end |
Class Method Details
.ask(question = nil, opts = {}) ⇒ Object
109 110 111 112 |
# File 'lib/inquirer/prompts/confirm.rb', line 109 def self.ask question = nil, opts = {} l = Confirm.new question, opts.fetch(:default, true), opts[:renderer], opts[:rendererResponse] l.run opts.fetch(:clear, true), opts.fetch(:response, true) end |
Instance Method Details
#run(clear, response) ⇒ Object
Run the list selection, wait for the user to select an item and return the selected index Params:
clear
-
Bool
whether to clear the selection prompt once this is done
defaults to true; set it to false if you want the prompt to remain after
the user is done with selecting
response
-
Bool
whether show the rendered response when this is done
defaults to true; set it to false if you want the prompt to remain after
the user is done with selecting
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/inquirer/prompts/confirm.rb', line 75 def run clear, response # render the IOHelper.render( update_prompt ) # loop through user confirm # IOHelper.read_char IOHelper.read_key_while true do |key| raw = IOHelper.char_to_raw(key) case raw when "y","Y" @value = true false when "n","N" @value = false false when "return" @value = @default false else true end end # clear the final prompt and the line IOHelper.clear if clear # show the answer IOHelper.render( update_response ) if response # return the value @value end |
#update_prompt ⇒ Object
57 58 59 60 |
# File 'lib/inquirer/prompts/confirm.rb', line 57 def update_prompt # call the renderer @prompt = @renderer.render(@question, @default) end |
#update_response ⇒ Object
62 63 64 |
# File 'lib/inquirer/prompts/confirm.rb', line 62 def update_response @prompt = @responseRenderer.renderResponse(@question, (@value)? 'Yes' : 'No') end |