+<:
+use 5.010;
+use Shiar_Sheet::Colour '1.03';
+use List::Util qw( min max );
-for my $num (0 .. 15) {
- printf('
%d | %s%s |
---|
'."\n",
- $num,
- $col{-name}[$num],
- join('', map {sprintf '
⪠',
- 'background:#'.$col{$_}[0].'; color:#'.$col{$_}[$num + 2],
- } qw/linux xterm tango/ ),
+my $palettes = do 'termcol.inc.pl';
+die "Cannot open palette data: $_\n" for $@ || $! || ();
+
+sub colcell {
+ my $name = shift // return " | \n";
+ my $col = Shiar_Sheet::Colour->new(@_);
+ my $minhex = $col->rgb24;
+ my $css = '#' . $col->rgb48;
+ my $inverse = '#' . sprintf('%X', $col->luminance/255 < .3 ? 12 : 0) x 3;
+
+ my $sample = [ qw(#000 #FFF) ];
+ ($name, $sample) = @$name if ref $name eq 'ARRAY';
+
+ my $out = sprintf(' | %s',
+ join(',', map { int } @$col),
+ "background:$css; color:$inverse",
+ $name,
);
+ $out .= sprintf('%s',
+ "background:$_; color:$css", $minhex
+ ) for @$sample;
+ return "$out\n";
+}
+
+sub img_egapal {
+ my ($palette) = @_;
+ return eval {
+ require Imager;
+ require MIME::Base64;
+
+ my @imgpal = map { Imager::Color->new(ref $_ ? @$_ : $_) } @{$palette};
+ state $img = Imager->new(file => "data/$imgfile")
+ or die Imager->errstr.$/;
+ @{[ $img->getcolors ]} == @imgpal
+ or die "incompatible palette size\n";
+ $img->setcolors(colors => \@imgpal);
+ $img->write(data => \my $imgdata, type => 'png');
+ return sprintf '',
+ MIME::Base64::encode_base64($imgdata);
+ } || $@;
+}
+
+for my $term (@termlist) {
+ my $info = $palettes->{$term};
+ ref $info eq 'HASH' or next;
+ my $caption = $info->{name} // $term;
+ $caption = sprintf('<%s %s>%s%1$s>',
+ $info->{href} ? 'a' : 'span',
+ join(' ',
+ map { sprintf '%s="%s"', $_, $info->{$_} }
+ grep { defined $info->{$_} }
+ qw( href title )
+ ),
+ $caption,
+ ) if $info->{href} or $info->{title};
+
+ if (my $mapinfo = $info->{rgbmap}) {
+ print ''."\n";
+ printf "%s\n", $caption;
+ print coltable_hsv(@{$mapinfo});
+ print " \n\n";
+ }
+
+ if (my $colours = $info->{list}) {
+ if (my $reorder = $info->{ansiorder} and $get{v}) {
+ $colours = [ map { $colours->[$_] =~ s/:|$/:$_/r } @{$reorder} ];
+ }
+
+ print '', "\n";
+ printf "%s\n", $caption;
+ for my $num (0 .. $#{$colours}) {
+ my ($rgb, $name) = split /:/, $colours->[$num], 3;
+ $name ||= $num;
+ $name = [ $name, [] ] if $term =~ /^msx/ and !$num;
+ $name = [ $name, ['#333'] ] if $term eq 'xkcd';
+ print '', colcell($name, $rgb);
+ }
+
+ print ' ', img_egapal(\@{$colours}) if $imgfile;
+ print " | \n\n";
+ }
}
-:> |