Parent

Files

Class/Module Index [+]

Quicksearch

Term::ANSIColor::Attribute

Attributes

name[R]
rgb[R]

Public Class Methods

[](name) click to toggle source
# File lib/term/ansicolor/attribute.rb, line 13
def self.[](name)
  case
  when self === name                              then name
  when name.to_s =~ /\A(on_)?(\d+)\z/             then get "#$1color#$2"
  when name.to_s =~ /\A#([0-9a-f]{3}){1,2}\z/    then nearest_rgb_color name
  when name.to_s =~ /\Aon_#([0-9a-f]{3}){1,2}\z/ then nearest_rgb_on_color name
  else                                            get name
  end
end
attributes(&block) click to toggle source
# File lib/term/ansicolor/attribute.rb, line 27
def self.attributes(&block)
  @__store__.each_value(&block)
end
get(name) click to toggle source
# File lib/term/ansicolor/attribute.rb, line 23
def self.get(name)
  @__store__[name.to_sym]
end
named_attributes(&block) click to toggle source
# File lib/term/ansicolor/attribute.rb, line 35
def self.named_attributes(&block)
  @named_attributes ||= attributes.reject(&:rgb_color?).each(&block)
end
nearest_rgb_color(color) click to toggle source
# File lib/term/ansicolor/attribute.rb, line 39
def self.nearest_rgb_color(color)
  rgb = RGBTriple[color]
  rgb_colors.reject(&:background?).min_by { |c| c.distance_to(rgb) }
end
nearest_rgb_on_color(color) click to toggle source
# File lib/term/ansicolor/attribute.rb, line 44
def self.nearest_rgb_on_color(color)
  rgb = RGBTriple[color]
  rgb_colors.select(&:background?).min_by { |c| c.distance_to(rgb) }
end
new(name, code, options = {}) click to toggle source
# File lib/term/ansicolor/attribute.rb, line 49
def initialize(name, code, options = {})
  @name = name.to_sym
  @code = code.to_s
  if html = options[:html]
    @rgb = RGBTriple.from_html(html)
  elsif !options.empty?
    @rgb = RGBTriple.from_hash(options)
  end
end
rgb_colors(&block) click to toggle source
# File lib/term/ansicolor/attribute.rb, line 31
def self.rgb_colors(&block)
  @rgb_colors ||= attributes.select(&:rgb_color?).each(&block)
end
set(name, code, options = {}) click to toggle source
# File lib/term/ansicolor/attribute.rb, line 6
def self.set(name, code, options = {})
  name = name.to_sym
  result = @__store__[name] = new(name, code, options)
  @rgb_colors = nil
  result
end

Public Instance Methods

background?() click to toggle source
# File lib/term/ansicolor/attribute.rb, line 69
def background?
  @name.to_s.start_with?('on_')
end
code() click to toggle source
# File lib/term/ansicolor/attribute.rb, line 61
def code
  if rgb_color?
    background? ? "48;5;#{@code}" : "38;5;#{@code}"
  else
    @code
  end
end
distance_to(other) click to toggle source
# File lib/term/ansicolor/attribute.rb, line 83
def distance_to(other)
  if our_rgb = to_rgb_triple and
    other.respond_to?(:to_rgb_triple) and
    other_rgb = other.to_rgb_triple
  then
    our_rgb.distance_to other_rgb
  else
    1 / 0.0
  end
end
rgb_color?() click to toggle source
# File lib/term/ansicolor/attribute.rb, line 75
def rgb_color?
  !!@rgb
end
to_rgb_triple() click to toggle source
# File lib/term/ansicolor/attribute.rb, line 79
def to_rgb_triple
  @rgb
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.