Sha256: 8e099b7ea21c87133c473abd36605787846155ea9b2ad6f2d74bced8ffa22af0

Contents?: true

Size: 1.39 KB

Versions: 15

Compression:

Stored size: 1.39 KB

Contents

module Test
  module Unit
    class Color
      NAMES = ["black", "red", "green", "yellow",
               "blue", "magenta", "cyan", "white"]
      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

      def sequence
        sequence = []
        if @name == "none"
        elsif @name == "reset"
          sequence << "0"
        else
          foreground_parameter = @foreground ? 3 : 4
          foreground_parameter += 6 if @intensity
          sequence << "#{foreground_parameter}#{NAMES.index(@name)}"
        end
        sequence << "1" if @bold
        sequence << "3" if @italic
        sequence << "4" if @underline
        sequence
      end

      def escape_sequence
        "\e[#{sequence.join(';')}m"
      end

      def +(other)
        MixColor.new([self, other])
      end
    end

    class MixColor
      def initialize(colors)
        @colors = colors
      end

      def sequence
        @colors.inject([]) do |result, color|
          result + color.sequence
        end
      end

      def escape_sequence
        "\e[#{sequence.join(';')}m"
      end

      def +(other)
        self.class.new([self, other])
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 4 rubygems

Version Path
cairo-1.8.5-x86-mingw32 test-unit/lib/test/unit/color.rb
cairo-1.8.5 test-unit/lib/test/unit/color.rb
cairo-1.8.4 test-unit/lib/test/unit/color.rb
cairo-1.8.4-x86-mingw32 test-unit/lib/test/unit/color.rb
cairo-1.8.3-x86-mingw32 test-unit/lib/test/unit/color.rb
cairo-1.8.3 test-unit/lib/test/unit/color.rb
cairo-1.8.1-x86-mswin32 test-unit/lib/test/unit/color.rb
cairo-1.8.1 test-unit/lib/test/unit/color.rb
activeldap-1.0.1 test-unit/lib/test/unit/color.rb
activesambaldap-0.0.6 test-unit/lib/test/unit/color.rb
cairo-1.8.0-x86-mswin32 test-unit/lib/test/unit/color.rb
cairo-1.7.0 test-unit/lib/test/unit/color.rb
cairo-1.7.0-x86-mswin32 test-unit/lib/test/unit/color.rb
cairo-1.8.0 test-unit/lib/test/unit/color.rb
test-unit-2.0.0 lib/test/unit/color.rb