Parent

HighLine::ColorScheme

ColorScheme objects encapsulate a named set of colors to be used in the HighLine.colors() method call. For example, by applying a ColorScheme that has a :warning color then the following could be used:

  colors("This is a warning", :warning)

A ColorScheme contains named sets of HighLine color constants.

Example: Instantiating a color scheme, applying it to HighLine,

         and using it:

  ft = HighLine::ColorScheme.new do |cs|
         cs[:headline]        = [ :bold, :yellow, :on_black ]
         cs[:horizontal_line] = [ :bold, :white ]
         cs[:even_row]        = [ :green ]
         cs[:odd_row]         = [ :magenta ]
       end 

  HighLine.color_scheme = ft
  say("<%= color('Headline', :headline) %>")
  say("<%= color('-'*20, :horizontal_line) %>")
  i = true
  ("A".."D").each do |row|
     if i then
       say("<%= color('#{row}', :even_row ) %>")
     else
       say("<%= color('#{row}', :odd_row) %>")
     end 
     i = !i
  end

Public Class Methods

new( h = nil ) click to toggle source

Create an instance of HighLine::ColorScheme. The customization can happen as a passed in Hash or via the yielded block. Key’s are converted to :symbols and values are converted to HighLine constants.

    # File lib/highline/color_scheme.rb, line 51
51:     def initialize( h = nil )
52:       @scheme = Hash.new
53:       load_from_hash(h) unless h.nil?
54:       yield self if block_given?
55:     end

Public Instance Methods

[]( color_tag ) click to toggle source

Allow the scheme to be accessed like a Hash.

    # File lib/highline/color_scheme.rb, line 70
70:     def []( color_tag )
71:       @scheme[to_symbol(color_tag)]
72:     end
[]=( color_tag, constants ) click to toggle source

Allow the scheme to be set like a Hash.

    # File lib/highline/color_scheme.rb, line 86
86:     def []=( color_tag, constants )
87:       @scheme[to_symbol(color_tag)] = HighLine::Style.new(:name=>color_tag.to_s.downcase.to_sym, 
88:                                                           :list=>constants, :no_index=>true)
89:     end
definition( color_tag ) click to toggle source

Retrieve the original form of the scheme

    # File lib/highline/color_scheme.rb, line 75
75:     def definition( color_tag )
76:       style = @scheme[to_symbol(color_tag)]
77:       style && style.list
78:     end
include?( color_tag ) click to toggle source

Does this color scheme include the given tag name?

    # File lib/highline/color_scheme.rb, line 65
65:     def include?( color_tag )
66:       @scheme.keys.include?(to_symbol(color_tag))
67:     end
keys() click to toggle source

Retrieve the keys in the scheme

    # File lib/highline/color_scheme.rb, line 81
81:     def keys
82:       @scheme.keys
83:     end
load_from_hash( h ) click to toggle source

Load multiple colors from key/value pairs.

    # File lib/highline/color_scheme.rb, line 58
58:     def load_from_hash( h )
59:       h.each_pair do |color_tag, constants|
60:         self[color_tag] = constants
61:       end
62:     end
to_hash() click to toggle source

Retrieve the color scheme hash (in original definition format)

    # File lib/highline/color_scheme.rb, line 92
92:     def to_hash
93:       @scheme.inject({}) { |hsh, pair| key, value = pair; hsh[key] = value.list; hsh }
94:     end

Private Instance Methods

to_constant( v ) click to toggle source

Return a normalized representation of a color setting.

     # File lib/highline/color_scheme.rb, line 105
105:     def to_constant( v )
106:       v = v.to_s if v.is_a?(Symbol)
107:       if v.is_a?(::String) then
108:         HighLine.const_get(v.upcase)
109:       else
110:         v
111:       end
112:     end
to_symbol( t ) click to toggle source

Return a normalized representation of a color name.

     # File lib/highline/color_scheme.rb, line 100
100:     def to_symbol( t )
101:       t.to_s.downcase
102:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.