-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathansicolors-ruby-colorize
More file actions
executable file
·39 lines (31 loc) · 1.46 KB
/
Copy pathansicolors-ruby-colorize
File metadata and controls
executable file
·39 lines (31 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env ruby
# ansicolors-ruby-colorize2
require "colorize"
$:.unshift File.expand_path("~/bin/lib")
require "tiny_table"
colors = %i[black red green yellow blue magenta cyan white light_black light_red light_green light_yellow light_blue light_magenta light_cyan light_white]
table = TinyTable.new
table.head = ["Foreground"] + colors
colors.each do |color|
row = [color]
colors.each do |background|
row << color.to_s.ljust(13).colorize({color:, background:})
end
table.rows << row
row = [" bold"]
colors.each do |background|
row << color.to_s.ljust(13).colorize({color:, background:, mode: :bold})
end
table.rows << row
end
puts table.to_s
puts
puts <<EXAMPLES
Examples:
'Message'.bold.white.on_green -> #{'Message'.bold.white.on_green}
'Message'.colorize({mode: :bold, color: :white, background: :green}) -> #{'Message'.colorize({mode: :bold, color: :white, background: :green})}
IMPORTANT: colorize() is tetchy. It likes to fail silently! Check for:
1. Exactly one argument, a Hash. NOT keyword args! | Bad: #{'s.colorize(color: :red)'.red} | Good: #{'s.colorize({color: :red})'.green}
2. All values are symbols. NOT strings! | Bad: #{'s.colorize(color: "red")'.red} | Good: #{'s.colorize(color: :red)'.green}
3. Background color is just the color name, it does NOT begin with on_. | Bad: #{'s.colorize(background: :on_red)'.red} | Good: #{'s.colorize(background: :red)'.green}
EXAMPLES