X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/b10a1871f75e16efe0cf94f05f2f9585ef0a8ea9..803fc2946b1c6a3b876cabea90ebac62ca6e55a9:/tools/mktermcol-xcolor diff --git a/tools/mktermcol-xcolor b/tools/mktermcol-xcolor index 2d007bc..615bff2 100755 --- a/tools/mktermcol-xcolor +++ b/tools/mktermcol-xcolor @@ -1,29 +1,52 @@ #!/usr/bin/env perl use 5.010; +use Shiar_Sheet::Colour 1.05; + say 'use strict;'; say '+{'; my @names; -for my $path (glob 'data/xcolors/themes/*') { - open my $theme, '<', $path; +for my $path (@ARGV) { + open my $theme, '<', $path or do { + warn "could not open $path: $!\n"; + next; + }; (my $name = $path) =~ s{.*/}{}; # basename - push @names, $name; - my @pal; + my (%pal, @pal); while (readline $theme) { - m{ color(\d+) \h* : \h* ( \#(\S+) | rgb:(\S+) ) }x or next; - my ($idx, $val) = ($1, uc $+); - $idx < 16 or next; + m{ + (?: (foreground | background) | color(\d+) ) \h* : \h* + (?: \#(\S+) | rgb:(\S+) ) + }x or next; + my ($name, $idx, $val) = ($1, $2, uc $+); + $name or $idx < 16 or next; $val =~ s/[^0-9A-F]//g; - $pal[$idx] = $val; + ($name ? $pal{$name} : $pal[$idx]) = $val; } + my $huesum = 0; + for my $hue ( + sort map { $_->hue } + grep { ($_->hsv)[1] > 32 } # ignore unsaturated + map { Shiar_Sheet::Colour->new($_) } + @pal + ) { + state $lasthue; + $huesum += abs($lasthue - $hue) > .02 if defined $lasthue; + $lasthue = $hue; + } + $huesum > 3 or next; # require number of significant hue changes + #TODO tweak to include good-pants, exclude cheesecake-* + say qq("$name" => {); say qq(\ttitle => '$name',); say qq(\tparent => 'cga',); say qq(\tlist => [qw(@pal)],); + say qq(\t$_ => '$pal{$_}',) for keys %pal; say qq(},); + push @names, $name; } say 'xcolor => [', join(', ', map {"'$_'"} @names), '],';