Method: App::Terminal.prompt_yes_no

Defined in:
lib/core/terminal.rb

.prompt_yes_no(title = nil, message = nil, confirmation_message = nil, preceding_blank_line = true) ⇒ Object

Gives a prompt where ‘y/Y’ will return TRUE, ‘n/N’ will return false, and ANY other key will do nothing.

Returns:

  • void



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/core/terminal.rb', line 252

def self.prompt_yes_no(title = nil, message = nil, confirmation_message = nil, preceding_blank_line = true)
    if title.nil?
        title = 'Please confirm YES or NO.'
    end
    if confirmation_message.nil?
        confirmation_message = 'Would you like to continue?';
    end
    if preceding_blank_line
        puts
    end
    puts "  \x1B[48;5;56m Confirm \x1B[0m \xe2\x86\x92 #{title}"
    parse_messages(message)
    response = ''
    until %w[y Y n N x X a A].include? response
        response = ask("     \x1B[38;5;89m#{confirmation_message} \x1B[0m[y/n]\x1B[90m => \x1B[0m")
    end
    case response.downcase
        when 'y'
            puts "\n"
            return true
        when 'n'
            puts "\n"
            return false
        when 'a'
            App::Terminal::error('Abandon ship!', ["You have chosen to \x1B[38;5;9mABORT\x1B[38;5;240m the script.", nil, 'Please note that whenever you do this, any scripted tasks which were running', 'will have been interrupted mid-script. This may (or may not) cause problems.'], true)
        when 'x'
            App::Terminal::error('Abandon ship!', ["You have chosen to \x1B[38;5;9mABORT\x1B[38;5;240m the script.", nil, 'Please note that whenever you do this, any scripted tasks which were running', 'will have been interrupted mid-script. This may (or may not) cause problems.'], true)
        else
    end
end