From: Mischa POSLAWSKY Date: Sun, 1 Nov 2015 20:04:17 +0000 (+0100) Subject: termcol: greyscales in hue row if no grey ramp specified X-Git-Tag: v1.9~74 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/1a54f5dbc34d8cdbc926404c28e5ced392fc0ed6 termcol: greyscales in hue row if no grey ramp specified --- diff --git a/termcol.plp b/termcol.plp index e544bf7..0c5d3e4 100644 --- a/termcol.plp +++ b/termcol.plp @@ -114,7 +114,6 @@ sub coltable_hsv { my $vmax = $dim - 1; my $smax = $dim - 1; $rgbval ||= sub { join('', @_), map { int $_ * 255 / $vmax } @_ }; - $greyramp ||= []; my %greymap; # name => value my @colmap; # saturation => value => hue => [name, r,g,b] @@ -130,9 +129,15 @@ sub coltable_hsv { my $s = abs(min(@rgb) - max(@rgb)); if (!$s) { - my ($index, $l) = $rgbval->(@rgb); - $greymap{$index} = $l; - next; + if ($greyramp) { + my ($index, $l) = $rgbval->(@rgb); + $greymap{$index} = $l; + next; + } + + $h = $hmax; # greyscale hue + $s = 1; # lowest saturation for other hues + $v = $s = $vmax if !$v; # black at full saturation } $v = $vmax - $v; @@ -151,15 +156,19 @@ sub coltable_hsv { $out .= colcell(@$_) for map { $_->[$h] } map { @{$_} } @colmap; } - $offset += $dim ** 3; - $greymap{$offset++} = $_ for @{$greyramp}; + if ($greyramp) { + $offset += $dim ** 3; + $greymap{$offset++} = $_ for @{$greyramp}; + } - $out .= ''; - my $col = 0; - my $colbreak = scalar map { @$_ } @colmap; # same width as hue rows - for my $num (sort { $greymap{$a} <=> $greymap{$b} } keys %greymap) { - $out .= '' unless $col++ % $colbreak; - $out .= colcell($num, ($greymap{$num}) x 3); + if (%greymap) { + $out .= ''; + my $col = 0; + my $colbreak = scalar map { @$_ } @colmap; # same width as hue rows + for my $num (sort { $greymap{$a} <=> $greymap{$b} } keys %greymap) { + $out .= '' unless $col++ % $colbreak; + $out .= colcell($num, ($greymap{$num}) x 3); + } } return $out;