### Home Classes Methods

### In Files

- lib/term/ansicolor/version.rb
- lib/term/ansicolor/rgb_color_metrics.rb
- lib/term/ansicolor/ppm_reader.rb
- lib/term/ansicolor/attribute.rb
- lib/term/ansicolor/rgb_triple.rb
- lib/term/ansicolor.rb

### Namespace

- MODULE Term::ANSIColor::RGBColorMetrics
- MODULE Term::ANSIColor::RGBColorMetricsHelpers
- CLASS Term::ANSIColor::Attribute
- CLASS Term::ANSIColor::PPMReader
- CLASS Term::ANSIColor::RGBTriple

### Methods

- ::attributes
- ::coloring=
- ::coloring?
- ::create_color_method
- ::term_ansicolor_attributes
- #attributes
- #color
- #on_color
- #support?
- #term_ansicolor_attributes
- #uncolor
- #uncolored

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Term
- Term::ANSIColor
- Term::ANSIColor::Attribute
- Term::ANSIColor::PPMReader
- Term::ANSIColor::RGBColorMetrics
- Term::ANSIColor::RGBColorMetrics::CIELab
- Term::ANSIColor::RGBColorMetrics::CIELab::CIELabTriple
- Term::ANSIColor::RGBColorMetrics::CIEXYZ
- Term::ANSIColor::RGBColorMetrics::CIEXYZ::CIEXYZTriple
- Term::ANSIColor::RGBColorMetrics::CompuPhase
- Term::ANSIColor::RGBColorMetrics::Euclidean
- Term::ANSIColor::RGBColorMetrics::NTSC
- Term::ANSIColor::RGBColorMetrics::YUV
- Term::ANSIColor::RGBColorMetrics::YUV::YUVTriple
- Term::ANSIColor::RGBColorMetricsHelpers
- Term::ANSIColor::RGBColorMetricsHelpers::NormalizeRGBTriple
- Term::ANSIColor::RGBColorMetricsHelpers::WeightedEuclideanDistance
- Term::ANSIColor::RGBTriple

No matching classes.

# Term::ANSIColor

The ANSIColor module can be used for namespacing and mixed into your own classes.

### Constants

COLORED_REGEXP

  Regular expression that is used to scan for ANSI-Attributes while uncoloring strings.

VERSION

  Term::ANSIColor version

### Public Class Methods

attributes() click to toggle source
Alias for: term_ansicolor_attributes
coloring=(val) click to toggle source

Turns the coloring on or off globally, so you can easily do this for example:

    Term::ANSIColor::coloring = STDOUT.isatty

    # File lib/term/ansicolor.rb, line 147
    def self.coloring=(val)
      @coloring = val
    end

coloring?() click to toggle source

Returns true, if the coloring function of this module is switched on, false otherwise.

    # File lib/term/ansicolor.rb, line 140
    def self.coloring?
      @coloring
    end

create_color_method(color_name, color_value) click to toggle source

    # File lib/term/ansicolor.rb, line 152
    def self.create_color_method(color_name, color_value)
      module_eval         def #{color_name}(string = nil, &block)          color(:#{color_name}, string, &block)        end
      self
    end

term_ansicolor_attributes() click to toggle source

Returns an array of all Term::ANSIColor attributes as symbols.

    # File lib/term/ansicolor.rb, line 212
    def term_ansicolor_attributes
      ::Term::ANSIColor::ATTRIBUTE_NAMES
    end

Also aliased as: attributes

### Public Instance Methods

attributes() click to toggle source
Alias for: term_ansicolor_attributes
color(name, string = nil, &block) click to toggle source

Return `string` or the result string of the given `block` colored with color `name`. If string isn't a string only the escape sequence to switch on the color `name` is returned.

    # File lib/term/ansicolor.rb, line 188
    def color(name, string = nil, &block)
      attribute = Attribute[name] or raise ArgumentError, "unknown attribute #{name.inspect}"
      result = ''
      result << "\e[#{attribute.code}m" if Term::ANSIColor.coloring?
      if block_given?
        result << yield
      elsif string.respond_to?(:to_str)
        result << string.to_str
      elsif respond_to?(:to_str)
        result << to_str
      else
        return result #only switch on
      end
      result << "\e[0m" if Term::ANSIColor.coloring?
      result
    end

on_color(name, string = nil, &block) click to toggle source

    # File lib/term/ansicolor.rb, line 205
    def on_color(name, string = nil, &block)
      attribute = Attribute[name] or raise ArgumentError, "unknown attribute #{name.inspect}"
      color("on_#{attribute.name}", string, &block)
    end

support?(feature) click to toggle source

Returns true if Term::ANSIColor supports the `feature`.

The feature :clear, that is mixing the clear color attribute into String, is only supported on ruby implementations, that do not already implement the String#clear method. It's better to use the reset color attribute instead.

    # File lib/term/ansicolor.rb, line 132
    def support?(feature)
      case feature
      when :clear
        !String.instance_methods(false).map(&:to_sym).include?(:clear)
      end
    end

term_ansicolor_attributes() click to toggle source

Returns an array of all Term::ANSIColor attributes as symbols.

    # File lib/term/ansicolor.rb, line 220
    def  term_ansicolor_attributes
      ::Term::ANSIColor.term_ansicolor_attributes
    end

Also aliased as: attributes
uncolor(string = nil) click to toggle source

Returns an uncolored version of the string, that is all ANSI-Attributes are stripped from the string.

    # File lib/term/ansicolor.rb, line 171
    def uncolor(string = nil) # :yields:
      if block_given?
        yield.to_str.gsub(COLORED_REGEXP, '')
      elsif string.respond_to?(:to_str)
        string.to_str.gsub(COLORED_REGEXP, '')
      elsif respond_to?(:to_str)
        to_str.gsub(COLORED_REGEXP, '')
      else
        ''
      end
    end

Also aliased as: uncolored
uncolored(string = nil) click to toggle source
Alias for: uncolor

[Validate]

Generated with the Darkfish Rdoc Generator 2.