Class: Test::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/test-unit-ext/color.rb

Constant Summary collapse

NAMES =
["black", "red", "green", "yellow",
"blue", "magenta", "cyan", "white"]

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Color

Returns a new instance of Color.



5
6
7
8
9
10
11
12
13
# File 'lib/test-unit-ext/color.rb', line 5

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

Instance Method Details

#+(other) ⇒ Object



35
36
37
# File 'lib/test-unit-ext/color.rb', line 35

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

#escape_sequenceObject



31
32
33
# File 'lib/test-unit-ext/color.rb', line 31

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

#sequenceObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/test-unit-ext/color.rb', line 15

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