Retrieve ANSI color code from RGB color.
ground is one of :foreground, :background rgb is an array of 3 values between 0 and 255.
# File lib/ansi_rgb.rb, line 9 def initialize(ground, rgb) if RGB.outside_range?(rgb) raise ArgumentError.new("RGB value outside 0-255 range") end @ground_code = { :foreground => 38, :background => 48 }[ground] @red, @green, @blue = rgb[0], rgb[1], rgb[2] end
Get the ANSI color code for this RGB color.
# File lib/ansi_rgb.rb, line 19 def code index = 16 + RGB.to_ansi_domain(@red) * 36 + RGB.to_ansi_domain(@green) * 6 + RGB.to_ansi_domain(@blue) "#{@ground_code};5;#{index}" end
Generated with the Darkfish Rdoc Generator 2.