Module: Keybox::HighLineUtil

Included in:
Application::PasswordSafe
Defined in:
lib/keybox/highline_util.rb

Overview

including this module assumes that the class included has an @highline variable

Constant Summary collapse

NONE_SCHEME =

the scheme to apply when no scheme is allowed so that everything works as normal

{
        :prompt         => [ :clear ], 
        :header         => [ :clear ], 
        :header_bar     => [ :clear ], 
        :line_number    => [ :clear ], 
        :even_row       => [ :clear ], 
        :odd_row        => [ :clear ], 
        :information    => [ :clear ], 
        :error          => [ :clear ], 
        :private        => [ :clear ], 
        :separator      => [ :clear ], 
        :separator_bar  => [ :clear ], 
        :name           => [ :clear ], 
        :value          => [ :clear ], 
        :normal         => [ :clear ],
}

Instance Method Summary collapse

Instance Method Details

#hagree(output) ⇒ Object



44
45
46
# File 'lib/keybox/highline_util.rb', line 44

def hagree(output)
    @highline.agree("<%= color(%Q{#{output}},:prompt) %> ")
end

#hsay(output, color_scheme) ⇒ Object

A whole line of input needs a particular color. This makes it easy to have all the ERB happening in one spot to avoid escaping issues.



40
41
42
# File 'lib/keybox/highline_util.rb', line 40

def hsay(output,color_scheme)
    @highline.say("<%= color(%Q{#{output}},'#{color_scheme}') %>")
end

#prompt(p, options) ⇒ Object

Prompt for input, returning what was typed. Options can be passed as 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



56
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
87
88
89
# File 'lib/keybox/highline_util.rb', line 56

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('#{original_prompt.rjust(width)}',:prompt) %> : ") { |q| q.echo = echo }
        # ensure we are at the beginning of the line
        @stdout.print "\r"

        # if we are validating then prompt again to validate
        if validate then
            v = @highline.ask("<%= color('#{validation_prompt.rjust(width)}', :prompt) %> : ") { |q| q.echo = echo }
            # ensure we are at the beginning of the line
            @stdout.print "\r"
           
            # 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