X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/dae21a09b01baa118720670247a87c5cdc2591b8..2a99bcdadec88d7483903e2c8420ad3e78fcb805:/termcol.plp diff --git a/termcol.plp b/termcol.plp index 359b33d..571b296 100644 --- a/termcol.plp +++ b/termcol.plp @@ -1,149 +1,258 @@ -<: -use utf8; -use strict; -use warnings; -use open IO => ':utf8'; -use List::Util 'min'; - -our $VERSION = 'v1.0'; +<(common.inc.plp)><: -$header{content_type} = 'text/html; charset=utf-8'; +Html({ + title => 'terminal colour cheat sheet', + version => '1.1', + description => [ + "Index of all terminal/console colour codes,", + "with an example result of various environments.", + ], + keywords => [qw' + color code terminal console escape table xterm rxvt + '], + data => ['termcol.inc.pl'], + stylesheet => [qw'light dark'], +}); -:> - +my @draw = map { [$_, s/\W+\z//] } grep { $_ } split m(/), + $get{img} // exists $get{img} && 'indi.png'; - -terminal colour cheat sheet - - - +my @termlist; +push @termlist, split /\W+/, $Request || 'default'; - +:>

Terminal colours

- -
-

88-colour space

+ if (my $palette = $info->{list}) { + my $order = $get{order} && $get{order}.'order'; + my $colours = colorder($palette, + $info->{$order} // $palettes->{ $info->{parent} }->{$order} + ); -
-

256-colour space

-
+sub coltable_hsv { + my ($dim, $rgbval, $greyramp) = @_; - + my $hmax = 2 * $dim * 3; # each face of the rgb cube + my $vmax = $dim - 1; + my $smax = $dim - 1; + $rgbval ||= sub { join('', @_), map { int $_ * 255 / $vmax } @_ }; + + my @greymap = @{$greyramp || []}; # [name, r, g=l, b] + my @colmap; # saturation => value => hue => [name, r,g,b] + + for my $r (0 .. $dim - 1) { + for my $g (0 .. $dim - 1) { + for my $b (0 .. $dim - 1) { + my @rgb = ($r, $g, $b); + + my ($h, $s, $v) = Shiar_Sheet::Colour->new(@rgb)->hsv; + + if (!$s) { + if (@greymap) { + push @greymap, [ $rgbval->(@rgb) ]; + next; + } + + $h = 1; # greyscale hue + $s = $smax - $v + 1; # spread brightness over saturation groups + $v &&= $smax # highest saturation + or $v = $s = 1; # black at initial column + } + + $h *= $hmax; + $v = $vmax - $v; + $s = $smax - $s - $v; + + $colmap[$s][$v][$h] = [ $rgbval->(@rgb) ]; + } + } + } + + my $out = ''; + $out .= sprintf '', scalar @{$_} for @colmap; + my $huerow = $colmap[0][0]; # first {$_} map { @{$_} } @colmap; + for my $h (grep { $huerow->[$_] } 0 .. $#{$huerow}) { + $out .= ''; + $out .= colcell(@$_) for map { $_->[$h] } map { reverse @{$_} } @colmap; + } + + if (@greymap) { + $out .= ''; + my $col = 0; + my $colbreak = scalar map { @$_ } @colmap; # same width as hue rows + for my $cell (sort { $a->[1] <=> $b->[1] || $a->[0] <=> $b->[0] } @greymap) { + $out .= '' unless $col++ % $colbreak; + $out .= colcell(@{$cell}); + } + } + + if (@draw) { + my @palette = map { [ @{$_}[1 .. 3] ] } @greymap, map {@$_} map {@$_} @colmap; + my $tablespan = scalar map { @$_ } @colmap; + my $imgdata = img_egapal(\@palette, @{ $draw[0] }); + $out .= "$imgdata"; + } + + return $out; +} + +coltable($_) for @termlist; +:> +
-