Class: Test::Unit::ColorScheme
- Inherits:
-
Object
- Object
- Test::Unit::ColorScheme
- Includes:
- Enumerable
- Defined in:
- lib/test/unit/color-scheme.rb
Constant Summary collapse
- TERM_256 =
/ [+-]256color| \A(?: alacritty| iTerm\s?\d*\.app| kitty| mintty| ms-terminal| nsterm-build\d+| nsterm| terminator| terminology(?:-[0-9.]+)?| termite| vscode )\z/x- @@schemes =
{}
Class Method Summary collapse
- .[](id) ⇒ Object
- .[]=(id, scheme_or_spec) ⇒ Object
- .all ⇒ Object
- .available_colors ⇒ Object
- .default ⇒ Object
- .default_for_256_colors ⇒ Object
- .default_for_8_colors ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](name) ⇒ Object
- #[]=(name, color_spec) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(scheme_spec) ⇒ ColorScheme
constructor
A new instance of ColorScheme.
- #to_hash ⇒ Object
Constructor Details
#initialize(scheme_spec) ⇒ ColorScheme
Returns a new instance of ColorScheme.
174 175 176 177 178 179 |
# File 'lib/test/unit/color-scheme.rb', line 174 def initialize(scheme_spec) @scheme = {} scheme_spec.each do |key, color_spec| self[key] = color_spec end end |
Class Method Details
.[](id) ⇒ Object
108 109 110 |
# File 'lib/test/unit/color-scheme.rb', line 108 def [](id) @@schemes[id.to_s] end |
.[]=(id, scheme_or_spec) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/test/unit/color-scheme.rb', line 112 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 |
.all ⇒ Object
104 105 106 |
# File 'lib/test/unit/color-scheme.rb', line 104 def all @@schemes.merge("default" => default) end |
.available_colors ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/test/unit/color-scheme.rb', line 121 def available_colors guess_available_colors_from_vte_version_env || guess_available_colors_from_colorterm_env || guess_available_colors_from_term_env || guess_available_colors_from_github_actions_env || 8 end |
.default ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/test/unit/color-scheme.rb', line 25 def default if available_colors >= 256 default_for_256_colors else default_for_8_colors end end |
.default_for_256_colors ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/test/unit/color-scheme.rb', line 68 def default_for_256_colors new("pass" => Color.new("030", :background => true) + Color.new("555", :bold => true), "pass-marker" => Color.new("050", :bold => true), "failure" => Color.new("300", :background => true) + Color.new("555", :bold => true), "failure-marker" => Color.new("500"), "pending" => Color.new("303", :background => true) + Color.new("555", :bold => true), "pending-marker" => Color.new("303"), "omission" => Color.new("001", :background => true) + Color.new("555", :bold => true), "omission-marker" => Color.new("001"), "notification" => Color.new("011", :background => true) + Color.new("555", :bold => true), "notification-marker" => Color.new("011"), "error" => Color.new("000", :background => true) + Color.new("550", :bold => true), "error-marker" => Color.new("550"), "case" => Color.new("220", :background => true) + Color.new("555", :bold => true), "suite" => Color.new("110", :background => true) + Color.new("555", :bold => true), "diff-inserted-tag" => Color.new("500", :background => true) + Color.new("000", :bold => true), "diff-deleted-tag" => Color.new("050", :background => true) + Color.new("000", :bold => true), "diff-difference-tag" => Color.new("005", :background => true) + Color.new("555", :bold => true), "diff-inserted" => Color.new("300", :background => true) + Color.new("555", :bold => true), "diff-deleted" => Color.new("030", :background => true) + Color.new("555", :bold => true)) end |
.default_for_8_colors ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/test/unit/color-scheme.rb', line 33 def default_for_8_colors new("pass" => Color.new("green", :background => true) + Color.new("white", :bold => true), "pass-marker" => Color.new("green", :bold => true), "failure" => Color.new("red", :background => true) + Color.new("white", :bold => true), "failure-marker" => Color.new("red"), "pending" => Color.new("magenta", :background => true) + Color.new("white", :bold => true), "pending-marker" => Color.new("magenta"), "omission" => Color.new("blue", :background => true) + Color.new("white", :bold => true), "omission-marker" => Color.new("blue"), "notification" => Color.new("cyan", :background => true) + Color.new("white", :bold => true), "notification-marker" => Color.new("cyan"), "error" => Color.new("black", :background => true) + Color.new("yellow", :bold => true), "error-marker" => Color.new("yellow"), "case" => Color.new("blue", :background => true) + Color.new("white", :bold => true), "suite" => Color.new("green", :background => true) + Color.new("white", :bold => true), "diff-inserted-tag" => Color.new("red", :background => true) + Color.new("black", :bold => true), "diff-deleted-tag" => Color.new("green", :background => true) + Color.new("black", :bold => true), "diff-difference-tag" => Color.new("cyan", :background => true) + Color.new("white", :bold => true), "diff-inserted" => Color.new("red", :background => true) + Color.new("white", :bold => true), "diff-deleted" => Color.new("green", :background => true) + Color.new("white", :bold => true)) end |
Instance Method Details
#==(other) ⇒ Object
201 202 203 204 |
# File 'lib/test/unit/color-scheme.rb', line 201 def ==(other) self.class === other and @scheme == other.scheme end |
#[](name) ⇒ Object
181 182 183 |
# File 'lib/test/unit/color-scheme.rb', line 181 def [](name) @scheme[name.to_s] end |
#[]=(name, color_spec) ⇒ Object
185 186 187 |
# File 'lib/test/unit/color-scheme.rb', line 185 def []=(name, color_spec) @scheme[name.to_s] = make_color(color_spec) end |
#each(&block) ⇒ Object
189 190 191 |
# File 'lib/test/unit/color-scheme.rb', line 189 def each(&block) @scheme.each(&block) end |
#to_hash ⇒ Object
193 194 195 196 197 198 199 |
# File 'lib/test/unit/color-scheme.rb', line 193 def to_hash hash = {} @scheme.each do |key, color| hash[key] = color end hash end |