X-Git-Url: http://git.shiar.net/barcat.git/blobdiff_plain/86ddf3f48f705f0865390bebbef9beeacec97aa4..3f7e3fb002626412e76a781ba93d12f72562afcc:/barcat diff --git a/barcat b/barcat index 2acdadd..c5b7e0a 100755 --- a/barcat +++ b/barcat @@ -50,7 +50,7 @@ GetOptions(\%opt, $opt{'graph-format'} = substr $_[1], 0, 1; }, 'spark:s' => sub { - $opt{spark} = [split //, $_[1] || '▁▂▃▄▅▆▇█']; + $opt{spark} = [split //, $_[1] || ' ▁▂▃▄▅▆▇█']; }, 'palette=s' => sub { $opt{palette} = { @@ -101,7 +101,7 @@ GetOptions(\%opt, }, ) or exit 64; # EX_USAGE -$opt{width} ||= $ENV{COLUMNS} || 80; +$opt{width} ||= $ENV{COLUMNS} || qx(tput cols) || 80; $opt{color} //= -t *STDOUT; # enable on tty $opt{'graph-format'} //= '-'; $opt{trim} *= $opt{width} / 100 if $opt{trimpct}; @@ -238,8 +238,13 @@ while ($nr <= $#lines) { my $rel = length $val && ($val - $minval) / ($maxval - $minval); if ($opt{spark}) { - print color($opt{palette}->[ $rel * $#{$opt{palette}} ]) if $opt{palette}; - print $opt{spark}->[ $rel * $#{$opt{spark}} ]; + print $opt{spark}->[ + !$val ? 0 : # blank + $val == $order[0] ? -1 : # max + $val == $order[-1] ? 1 : # min + $#{$opt{spark}} < 3 ? 1 : + $rel * ($#{$opt{spark}} - 3) + 2.5 + ]; next; }