Method: Keybox::Application::PasswordSafe#load_color_scheme
- Defined in:
- lib/keybox/application/password_safe.rb
#load_color_scheme ⇒ Object
load the given color scheme. If the scheme cannot be found it will default to the :none scheme which has no color
The color_scheme file exists either in the application data directory, or in the same directory as the configuration file.
The file name convention for the scheme file is schemename.color_scheme.yaml. So for instance the default :dark_bg color scheme file is named:
dark_bg.color_scheme.yaml
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/keybox/application/password_safe.rb', line 178 def load_color_scheme if @options.color_scheme != :none then search_directories = [ Keybox::APP_RESOURCE_DIR, File.dirname(@options.config_file) ] scheme_basename = "#{@options.color_scheme.to_s}.color_scheme.yaml" scheme_path = nil # get the path to the file search_directories.each do |sd| if File.exists?(File.join(sd,scheme_basename)) then scheme_path = File.join(sd,scheme_basename) break end end # if we have a file then load it and make sure we have # all the valid labels. if scheme_path then initial_color_scheme = YAML::load(File.read(scheme_path)) # make sure that everything is a Symbol and in the # process make sure that all of the required labels # are there. color_scheme = {} initial_color_scheme.each_pair do |label,ansi_seq| color_scheme[label.to_sym] = ansi_seq.collect { |a| a.to_sym } end # validate that all the required color labels exist if (NONE_SCHEME.keys - color_scheme.keys).size == 0 then ::HighLine.color_scheme = ::HighLine::ColorScheme.new(color_scheme) else @options.color_scheme = :none ::HighLine.color_scheme = ::HighLine::ColorScheme.new(NONE_SCHEME) @stdout.puts "The color scheme in file '#{scheme_path}' is Invalid" @stdout.puts "It is missing the following items:" (NONE_SCHEME.keys - color_scheme.keys).each do |missing_label| @stdout.puts "\t :#{missing_label}" end @stdout.puts "Not using any color scheme." end else # if we don't have a file then set the color # scheme to :none and we're done @options.color_scheme = :none ::HighLine.color_scheme = ::HighLine::ColorScheme.new(NONE_SCHEME) end else ::HighLine.color_scheme = ::HighLine::ColorScheme.new(NONE_SCHEME) end end |