Class: Test::Unit::ColorScheme

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

Constant Summary collapse

@@default_for_8_colors =
nil
@@default_for_256_colors =
nil
@@schemes =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scheme_spec) ⇒ ColorScheme

Returns a new instance of ColorScheme.



106
107
108
109
110
111
# File 'lib/test/unit/color-scheme.rb', line 106

def initialize(scheme_spec)
  @scheme = {}
  scheme_spec.each do |key, color_spec|
    self[key] = color_spec
  end
end

Class Method Details

.[](id) ⇒ Object



78
79
80
# File 'lib/test/unit/color-scheme.rb', line 78

def [](id)
  @@schemes[id.to_s]
end

.[]=(id, scheme_or_spec) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/test/unit/color-scheme.rb', line 82

def []=(id, scheme_or_spec)
  if scheme_or_spec.is_a?(self)
    scheme = scheme_or_spec
  else
    scheme = new(scheme_or_spec)
  end
  @@schemes[id.to_s] = scheme
end

.allObject



74
75
76
# File 'lib/test/unit/color-scheme.rb', line 74

def all
  @@schemes.merge("default" => default)
end

.available_colorsObject



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/test/unit/color-scheme.rb', line 91

def available_colors
  case ENV["COLORTERM"]
  when "gnome-terminal"
    256
  else
    case ENV["TERM"]
    when "xterm-256color"
      256
    else
      8
    end
  end
end

.defaultObject



9
10
11
12
13
14
15
# File 'lib/test/unit/color-scheme.rb', line 9

def default
  if available_colors == 256
    default_for_256_colors
  else
    default_for_8_colors
  end
end

.default_for_256_colorsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/test/unit/color-scheme.rb', line 43

def default_for_256_colors
  @@default_for_256_colors ||=
    new("pass" => Color.new("030", :foreground => false) +
                  Color.new("555", :bold => true),
        "failure" => Color.new("300", :foreground => false) +
                     Color.new("555", :bold => true),
        "pending" => Color.new("303", :foreground => false) +
                      Color.new("555", :bold => true),
        "omission" => Color.new("001", :foreground => false) +
                      Color.new("555", :bold => true),
        "notification" => Color.new("011", :foreground => false) +
                          Color.new("555", :bold => true),
        "error" => Color.new("550", :bold => true) +
                   Color.new("000", :foreground => false),
        "case" => Color.new("220", :foreground => false) +
                  Color.new("555", :bold => true),
        "suite" => Color.new("110", :foreground => false) +
                   Color.new("555", :bold => true),
        "diff-inserted-tag" => Color.new("500", :foreground => false) +
                               Color.new("000", :bold => true),
        "diff-deleted-tag" => Color.new("050", :foreground => false) +
                              Color.new("000", :bold => true),
        "diff-difference-tag" => Color.new("005", :foreground => false) +
                                 Color.new("555", :bold => true),
        "diff-inserted" => Color.new("300", :foreground => false) +
                           Color.new("555", :bold => true),
        "diff-deleted" =>  Color.new("030", :foreground => false) +
                           Color.new("555", :bold => true))
end

.default_for_8_colorsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/test/unit/color-scheme.rb', line 18

def default_for_8_colors
  @@default_for_8_colors ||=
    new("pass" => Color.new("green", :foreground => false) +
                  Color.new("white", :bold => true),
        "failure" => Color.new("red", :foreground => false) +
                     Color.new("white", :bold => true),
        "pending" => Color.new("magenta", :bold => true),
        "omission" => Color.new("blue", :bold => true),
        "notification" => Color.new("cyan", :bold => true),
        "error" => Color.new("yellow", :bold => true) +
                   Color.new("black", :foreground => false),
        "case" => Color.new("white", :bold => true) +
                  Color.new("blue", :foreground => false),
        "suite" => Color.new("white", :bold => true) +
                   Color.new("green", :foreground => false),
        "diff-inserted-tag" => Color.new("red", :bold => true),
        "diff-deleted-tag" => Color.new("green", :bold => true),
        "diff-difference-tag" => Color.new("cyan", :bold => true),
        "diff-inserted" => Color.new("red", :foreground => false) +
                           Color.new("white", :bold => true),
        "diff-deleted" =>  Color.new("green", :foreground => false) +
                           Color.new("white", :bold => true))
end

Instance Method Details

#[](name) ⇒ Object



113
114
115
# File 'lib/test/unit/color-scheme.rb', line 113

def [](name)
  @scheme[name.to_s]
end

#[]=(name, color_spec) ⇒ Object



117
118
119
# File 'lib/test/unit/color-scheme.rb', line 117

def []=(name, color_spec)
  @scheme[name.to_s] = make_color(color_spec)
end

#each(&block) ⇒ Object



121
122
123
# File 'lib/test/unit/color-scheme.rb', line 121

def each(&block)
  @scheme.each(&block)
end

#to_hashObject



125
126
127
128
129
130
131
# File 'lib/test/unit/color-scheme.rb', line 125

def to_hash
  hash = {}
  @scheme.each do |key, color|
    hash[key] = color
  end
  hash
end