395c2086a663fd2e1926ff9449d6ea85a315fbb7
[sheet.git] / termcol.plp
1 <(common.inc.plp)><:
2         our $VERSION = 'v1.0';
3
4         use List::Util 'min';
5
6 :><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
7  "http://www.w3.org/TR/html4/loose.dtd">
8 <html lang="en">
9
10 <head>
11 <meta http-equiv="content-type" content="utf-8">
12 <title>terminal colour cheat sheet</title>
13 <meta name="description" content="Index of all terminal/console colour codes, with an example result of various environments.">
14 <meta name="keywords" content="color, code, terminal, console, escape, table, xterm, rxvt">
15 <:= stylesheet(qw'light dark') :>
16 <link rel="icon" type="image/png" href="/clip.png">
17 </head>
18
19 <body id="colour">
20 <h1>Terminal colours</h1>
21
22 <div class="section">
23 <:
24 sub luminance {
25         # perceived brightness (using ITU-R recommendation 601 luma co-efficients)
26         my ($r, $g, $b) = @_;
27         return $r*.299 + $g*.587 + $b*.114;
28 }
29
30 sub colcell {
31         my $id = shift;
32         my @rgb = @_ >= 3 ? @_ : (map {hex} $_[0] =~ /(..)/g);
33         my $rgb24 = '';
34         $rgb24 .= sprintf '%X', min($_ / 17 + .5, 15) for @rgb[0..2];
35         my $rgb48 = '';
36         $rgb48 .= sprintf '%02X', $_ for @rgb[0..2];
37         my $inverse = sprintf('%X', luminance(@rgb)/255 < .3 ? 12 : 0) x 3;
38         return sprintf '<td style="%s; padding:0 1ex">%s<td style="%s">%s<td style="%s">%s'."\n",
39                 "background:#$rgb48; color:#$inverse",
40                 $id,
41                 "background:#000; color:#$rgb48",
42                 $rgb24,
43                 "background:#FFF; color:#$rgb48",
44                 $rgb24,
45 }
46
47 my %col = (
48         -html => [
49                 qw/black maroon green olive  navy purple  cyan silver
50                    gray  red    lime  yellow blue fuchsia aqua white/,
51                 qw/reset bold dim italic underline blink fastblink
52                    reverse hidden/,
53         ],
54         html => [
55                 qw/000000 CCCCCC/,
56                 qw/000000 800000 008000 808000 000080 800080 008080 C0C0C0
57                    808080 FF0000 00FF00 FFFF00 0000FF FF00FF 00FFFF FFFFFF/,
58         ],
59         cga => [
60                 qw/000000 CCCCCC/,
61                 qw/000000 AA0000 00AA00 AA5500 0000AA AA00AA 00AAAA AAAAAA
62                    555555 FF5555 55FF55 FFFF55 5555FF FF55FF 55FFFF FFFFFF/,
63         ],
64         xterm => [
65                 qw/000000 CCCCCC/,
66                 qw/000000 CC0000 00CC00 CCCC00 4682B4 CC00CC 00CCCC E5E5E5
67                    4C4C4C FF0000 00FF00 FFFF00 1E90FF FF00FF 00FFFF FFFFFF/,
68         ],
69         tango => [
70                 qw/000000 CCCCCC/,
71                 qw/2E3436 CC0000 4E9A06 C4A000 3465A4 75507B 06989A D3D7CF
72                    555753 EF2929 8AE234 FCE94F 729FCF AD7FA8 34E2E2 EEEEEC/,
73         ],
74 );
75
76 for my $term (qw/html cga xterm tango/) {
77         print '<table>', "\n";
78         print "<caption>$term</caption>\n";
79         for my $num (0 .. 15) {
80                 my $rgb = $col{$term}[$num + 2];
81                 print '<tr>',
82                         colcell($col{"-$term"}[$num] || $num, $rgb, $col{$term}[0]);
83         }
84         print "</table>\n\n";
85 }
86 :></div>
87
88 <hr>
89
90 <div class="section">
91 <h2>88-colour space</h2>
92 <:
93 for my $r (0 .. 3) {
94         print '<table>';
95         for my $g (0 .. 3) {
96                 print '<tr>';
97                 for my $b (0 .. 3) {
98                         my $index = $r*4*4 + $g*4 + $b + 16;
99                         print colcell($index, map {(0, 139, 205, 255)[$_]} $r, $g, $b);
100                 }
101         }
102         print "</table>\n";
103 }
104 print "\n";
105
106 print '<table><tr>';
107 print colcell(80, ($_) x 3) for 46, 92, 115, 139, 162, 185, 208, 231;
108 print "</table>\n\n";
109 :></div>
110
111 <hr>
112
113 <div class="section">
114 <h2>256-colour space</h2>
115 <:
116 for my $r (0 .. 5) {
117         print '<table>';
118         for my $g (0 .. 5) {
119                 print '<tr>';
120                 for my $b (0 .. 5) {
121                         my $index = $r*6*6 + $g*6 + $b + 16;
122                         print colcell($index, map { $_ && $_*40 + 55 } $r, $g, $b);
123                 }
124         }
125         print "</table>\n";
126 }
127 print "\n";
128
129 for my $row (0, 12) {
130         print '<table><tr>';
131         print colcell(232+$_, ($_*10 + 8) x 3) for $row .. $row+11;
132         print "</table>\n";
133 }
134 print "\n";
135 :></div>
136
137 <hr>
138
139 <p class="footer">
140         <a href="/" rel="home">sheet.shiar.nl</a>/termcol.<a href="/source/termcol.plp"
141          rel="code" title="Written in Perl">plp</a>
142         <a href="http://git.shiar.nl/sheet.git/history/HEAD:/termcol.plp"
143          rel="vcs-git" title="Git repository"><:= $VERSION :></a>
144         created by <a href="http://shiar.nl/" rel="author">Shiar</a> •
145         <a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html" rel="copyright"
146          title="Licensed under the GNU Affero General Public License, version 3">AGPLv3</a>
147 </p>
148
149 </html>