Object
# File lib/test/unit/color.rb, line 28 def initialize(name, options={}) @name = name @foreground = options[:foreground] @foreground = true if @foreground.nil? @intensity = options[:intensity] @bold = options[:bold] @italic = options[:italic] @underline = options[:underline] end
# File lib/test/unit/color.rb, line 11 def parse_256_color(string) case string when /\A([0-5])([0-5])([0-5])\z/ red, green, blue = $1, $2, $3 red.to_i * 36 + green.to_i * 6 + blue.to_i + 16 else message = "must be 'RGB' format and R, G and B " + "are in 0-5: #{string.inspect}" raise ParseError, message end end
# File lib/test/unit/color.rb, line 93 def +(other) MixColor.new([self, other]) end
# File lib/test/unit/color.rb, line 58 def ==(other) self.class === other and [name, foreground?, intensity?, bold?, italic?, underline?] == [other.name, other.foreground?, other.intensity?, other.bold?, other.italic?, other.underline?] end
# File lib/test/unit/color.rb, line 89 def escape_sequence "\e[#{sequence.join(';')}m" end
# File lib/test/unit/color.rb, line 38 def foreground? @foreground end
# File lib/test/unit/color.rb, line 42 def intensity? @intensity end
# File lib/test/unit/color.rb, line 66 def sequence sequence = [] if @name == "none" elsif @name == "reset" sequence << "0" else if NAMES.include?(@name) foreground_parameter = foreground? ? 3 : 4 foreground_parameter += 6 if intensity? color = NAMES.index(@name) sequence << "#{foreground_parameter}#{color}" else sequence << (foreground? ? "38" : "48") sequence << "5" sequence << self.class.parse_256_color(@name).to_s end end sequence << "1" if bold? sequence << "3" if italic? sequence << "4" if underline? sequence end
Generated with the Darkfish Rdoc Generator 2.