termcol: parse Xcolors.net checkout
[sheet.git] / tools / mktermcol-xcolor
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 '}';