Method: Blufin::Terminal.prompt_for_input

Defined in:
lib/core/terminal.rb

.prompt_for_input(title = 'Input Required', message = nil, subtitle_array = nil, validation_proc = nil, validation_message = 'Invalid value', clear_screen = true, preceding_blank_line = true) ⇒ Object

Deprecated.

Shows a prompt waiting for user input. If validation_proc is passed, the Proc must return TRUE in order for validation to pass.

Returns:

  • string



365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/core/terminal.rb', line 365

def self.prompt_for_input(title = 'Input Required', message = nil, subtitle_array = nil, validation_proc = nil, validation_message = 'Invalid value', clear_screen = true, preceding_blank_line = true)
    system('clear') if clear_screen
    puts if preceding_blank_line
    puts "  \x1B[38;5;231m\x1B[48;5;125m #{title.upcase} \x1B[0m \xe2\x86\x92 #{message} \x1B[38;5;240m\xe2\x80\x94 \x1B[38;5;160m(or 'X' to cancel)\x1B[0m\n"
    parse_messages(subtitle_array) unless subtitle_array.nil?
    puts if subtitle_array.nil?
    response = nil
    while response.nil?
        response = Readline::readline("     \x1B[38;5;245m=>\x1B[0m ", true)
        unless validation_proc.nil?
            raise RuntimeError, "Expected validation_proc to be an instance of Proc, instead got: #{validation_proc.class}" unless validation_proc.is_a?(Proc)
            unless response.upcase == 'X' || validation_proc.call(response)
                puts "     \x1B[38;5;245m=>\x1B[0m \x1B[38;5;196mERROR\x1B[0m \xe2\x80\x94 #{validation_message}\n"
                response = nil
            end
        end
    end
    abort if response.upcase == 'X'
    puts
    response
end