termcol: export gimp palette on .gpl requests
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 4 Dec 2023 22:39:38 +0000 (23:39 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 19 Dec 2023 03:03:44 +0000 (04:03 +0100)
termcol.plp

index 5f89c3fadd2d70a2cd335ed9e46ad3a57f49ad45..f76e293a31e3dcfbf4173abcfe3efe352f138569 100644 (file)
@@ -1,5 +1,24 @@
 <(common.inc.plp)><:
 
+if (my ($name) = $Request =~ /(.+)\.gpl\z/) {
+       my $palettes = Data('termcol');
+       my $palette = $palettes->{$name}
+               or Abort("Palette '$name' not found", 404);
+       ref $palette ne 'ARRAY'
+               or Abort("Group contains multiple palettes: ".join(', ', @{$palette}));
+
+       $header{content_type} = 'text/x-gimp-gpl';
+       say 'GIMP Palette';
+       say 'Name: ', $palette->{name} // $name;
+       say 'Columns: 8';
+       say '#';
+       for (@{ $palette->{list} }) {
+               my ($rgb, $name) = split /:/, $_, 3;
+               say join ' ', unpack('C*', pack 'H6', $rgb), $name;
+       }
+       exit;
+}
+
 Html({
        title => ($Request ? 'terminal colour' : 'colour palettes') . ' cheat sheet',
        version => '1.4',