summaryrefslogtreecommitdiff
path: root/tool/lib
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-12-10 00:14:10 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-12-10 20:43:47 +0900
commitd9dbcd848f4903921d985cec570d46a4c601073c (patch)
tree03fdf23b4eed0e16458175e993275f370d2607eb /tool/lib
parent0096d6a809085820a0532f755b4fedd631c7e3f1 (diff)
Add bright colors and multiple attributes [ci skip]
Not only: ``` $ ruby colorize.rb fail foo ``` Also: ``` $ ruby colorize.rb 'bright_blue;bold' foo ```
Diffstat (limited to 'tool/lib')
-rw-r--r--tool/lib/colorize.rb23
1 files changed, 20 insertions, 3 deletions
diff --git a/tool/lib/colorize.rb b/tool/lib/colorize.rb
index 688a51525f..5c3b43f3fa 100644
--- a/tool/lib/colorize.rb
+++ b/tool/lib/colorize.rb
@@ -27,10 +27,15 @@ class Colorize
end
DEFAULTS = {
- "pass"=>"32", "fail"=>"31;1", "skip"=>"33;1",
+ # color names
"black"=>"30", "red"=>"31", "green"=>"32", "yellow"=>"33",
"blue"=>"34", "magenta"=>"35", "cyan"=>"36", "white"=>"37",
"bold"=>"1", "underline"=>"4", "reverse"=>"7",
+ "bright_black"=>"90", "bright_red"=>"91", "bright_green"=>"92", "bright_yellow"=>"93",
+ "bright_blue"=>"94", "bright_magenta"=>"95", "bright_cyan"=>"96", "bright_white"=>"97",
+
+ # abstract decorations
+ "pass"=>"green", "fail"=>"red;bold", "skip"=>"yellow;bold", "note"=>"bright_yellow",
}
def coloring?
@@ -46,9 +51,21 @@ class Colorize
end
end
- def resolve_color(name = @color, seen = {})
+ def resolve_color(color = @color, seen = {}, colors = nil)
return unless @colors
- @colors[name] || DEFAULTS[name]
+ color.gsub(/\b[a-z][\w ]+/) do |n|
+ n.gsub!(/\W+/, "_")
+ n.downcase!
+ c = seen[n] and next c
+ if colors
+ c = colors[n]
+ elsif (c = (tbl = @colors)[n] || (tbl = DEFAULTS)[n])
+ colors = tbl
+ else
+ next n
+ end
+ seen[n] = resolve_color(c, seen, colors)
+ end
end
DEFAULTS.each_key do |name|