Method: Keybox::HighLineUtil#prompt

Defined in:
lib/keybox/highline_util.rb

#prompt(p, options) ⇒ Object

Prompt for input, returning what was typed. Options can be passed in.

If echo is false, then ‘*’ is printed out for each character typed in. If it is any other character then that is output instead.

If validate is set to true, then it will prompt twice and make sure that the two values match



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/keybox/highline_util.rb', line 57

def prompt(p,options)
    validated = false
    line = ""
    extra_prompt = " (again)"
    original_prompt = p
    validation_prompt = original_prompt + extra_prompt

    echo     = options[:echo].nil? ? true : options[:echo]
    width    = options[:width] || 30
    validate = options[:validate] || false

    until validated do
        line = @highline.ask("<%= color(%Q{#{original_prompt.rjust(width)}},:prompt) %> : ") { |q| q.echo = echo }

        # if we are validating then prompt again to validate
        if validate then
            v = @highline.ask("<%= color(%Q{#{validation_prompt.rjust(width)}}, :prompt) %> : ") { |q| q.echo = echo }
           
            # line on some terminals
            if v != line then
                @highline.say("<%= color('Entries do not match, try again.', :error) %>")
            else
                validated = true
            end
        else 
            validated = true
        end
    end
    return line
end