File: colortab

package info (click to toggle)
ruby-term-ansicolor 1.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 1,104 kB
  • sloc: ruby: 1,269; makefile: 10
file content (48 lines) | stat: -rwxr-xr-x 706 bytes parent folder | download | duplicates (3)
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
40
41
42
43
44
45
46
47
48
#!/usr/bin/env ruby

require 'term/ansicolor'

class String
  include Term::ANSIColor
end

def print_color(c)
  color = Term::ANSIColor::Attribute[c]
  text = [
    Term::ANSIColor::Attribute.nearest_rgb_color('#000'),
    Term::ANSIColor::Attribute.nearest_rgb_color('#fff'),
  ].max_by { |t| t.distance_to(color) }
  print ("%3u #{color.rgb.html} " % c).on_color(color.name).color(text.name)
end

for c in 0..3
  print_color c
end
puts

for c in 4..7
  print_color c
end
puts

for c in 8..11
  print_color c
end
puts

for c in 12..15
  print_color c
end
puts

for c in 16..231
  (c - 16) % 6 == 0 and puts
  print_color c
end
puts

for c in 232..255
  (c - 16) % 6 == 0 and puts
  print_color c
end
puts