### Home Classes Methods

### In Files

- lib/highline/color_scheme.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=
- #definition
- #include?
- #keys
- #load_from_hash
- #to_hash

### Files

- CHANGELOG
- INSTALL
- LICENSE
- README.rdoc
- TODO

### Class/Module Index

Quicksearch

- HighLine
- HighLine::ColorScheme
- HighLine::HighLine
- HighLine::HighLine::HighLine
- HighLine::HighLine::HighLine::String
- HighLine::Menu
- HighLine::Question
- HighLine::Question::NoAutoCompleteMatch
- HighLine::QuestionError
- HighLine::SampleColorScheme
- HighLine::Simulate
- HighLine::StringExtensions
- HighLine::Style
- HighLine::SystemExtensions
- HighLine::SystemExtensions::WinAPI
- IO
- Kernel
- Object
- String
- StringIO

No matching classes.

# 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. Keys are converted to `:symbols` and values are converted to HighLine constants.

    # File lib/highline/color_scheme.rb, line 49
    def initialize( h = nil )
      @scheme = Hash.new
      load_from_hash(h) unless h.nil?
      yield self if block_given?
    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 68
    def []( color_tag )
      @scheme[to_symbol(color_tag)]
    end

[]=( color_tag, constants ) click to toggle source

Allow the scheme to be set like a Hash.

    # File lib/highline/color_scheme.rb, line 84
    def []=( color_tag, constants )
      @scheme[to_symbol(color_tag)] = HighLine::Style.new(:name=>color_tag.to_s.downcase.to_sym,
                                                          :list=>constants, :no_index=>true)
    end

definition( color_tag ) click to toggle source

Retrieve the original form of the scheme

    # File lib/highline/color_scheme.rb, line 73
    def definition( color_tag )
      style = @scheme[to_symbol(color_tag)]
      style && style.list
    end

include?( color_tag ) click to toggle source

Does this color scheme include the given tag name?

    # File lib/highline/color_scheme.rb, line 63
    def include?( color_tag )
      @scheme.keys.include?(to_symbol(color_tag))
    end

keys() click to toggle source

Retrieve the keys in the scheme

    # File lib/highline/color_scheme.rb, line 79
    def keys
      @scheme.keys
    end

load_from_hash( h ) click to toggle source

Load multiple colors from key/value pairs.

    # File lib/highline/color_scheme.rb, line 56
    def load_from_hash( h )
      h.each_pair do |color_tag, constants|
        self[color_tag] = constants
      end
    end

to_hash() click to toggle source

Retrieve the color scheme hash (in original definition format)

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.