termcol: parse Xcolors.net checkout
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 23 Oct 2016 04:48:35 +0000 (06:48 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 22 Mar 2017 21:28:04 +0000 (22:28 +0100)
Prepare a separate (optional) include with themes from the popular
ansi palettes repository <https://github.com/tlatsas/xcolors.git>.

Makefile
termcol.plp
tools/mktermcol-xcolor [new file with mode: 0755]

index c13afc16e0f8feb0ed7c7788f5f47241bfb60107..1750fd006ebf530cdad7438488027848503bef1a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-all: digraphs.inc.pl unicode-cover.inc.pl countries.inc.pl data/browser/support.inc.pl
+all: digraphs.inc.pl unicode-cover.inc.pl countries.inc.pl data/browser/support.inc.pl termcol-xcolor.inc.pl
 more: all data/digraphs-xorg.inc.pl
 
 download: data/DerivedAge.txt data/rfc1345.txt data/xorg-compose data/countryInfo.txt data/caniuse.json
@@ -37,6 +37,9 @@ unicode-char.inc.pl: tools/mkcharinfo data/digraphs-rfc.inc.pl data/digraphs-shi
 ttfsupport/%.inc.pl: tools/mkttfinfo data/font/%.ttf
        $< $(word 2,$^) $@ || true
 
+termcol-xcolor.inc.pl: tools/mktermcol-xcolor
+       $< >$@
+
 .SECONDARY:
 data/font/%.ttf:
        find /usr/share/fonts/truetype/ ~/.fonts/ -iname "$(@F)" | head -1 | xargs -i ln -sf {} $@
index 8f8878bf498535442122a16eb28284432786b016..3d807a242c7272253672a941db9d0d5ca1655955 100644 (file)
@@ -42,6 +42,8 @@ use POSIX qw( ceil );
 
 my $palettes = do 'termcol.inc.pl';
 die "Cannot open palette data: $_\n" for $@ || $! || ();
+my $more = do 'termcol-xcolor.inc.pl';
+$palettes = {%$palettes, %$more};
 
 sub colcell {
        my $name = shift // return "<td>\n";
diff --git a/tools/mktermcol-xcolor b/tools/mktermcol-xcolor
new file mode 100755 (executable)
index 0000000..2d007bc
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+use 5.010;
+
+say 'use strict;';
+say '+{';
+my @names;
+
+for my $path (glob 'data/xcolors/themes/*') {
+       open my $theme, '<', $path;
+       (my $name = $path) =~ s{.*/}{};  # basename
+       push @names, $name;
+
+       my @pal;
+       while (readline $theme) {
+               m{ color(\d+) \h* : \h* ( \#(\S+) | rgb:(\S+) ) }x or next;
+               my ($idx, $val) = ($1, uc $+);
+               $idx < 16 or next;
+               $val =~ s/[^0-9A-F]//g;
+               $pal[$idx] = $val;
+       }
+
+       say qq("$name" => {);
+       say qq(\ttitle => '$name',);
+       say qq(\tparent => 'cga',);
+       say qq(\tlist => [qw(@pal)],);
+       say qq(},);
+}
+
+say 'xcolor => [', join(', ', map {"'$_'"} @names), '],';
+say '}';