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