optional width of sparkline lines
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 14 Oct 2019 23:06:59 +0000 (01:06 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 24 Jan 2020 15:56:18 +0000 (16:56 +0100)
Output newlines after specified number of records.
Keep current single line by default.

barcat

diff --git a/barcat b/barcat
index 424bec2a979fbf363302e689a467c37fc0b1d2ee..3bc7ca024f9d2e0723140310914d57a0543b3576 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -101,7 +101,7 @@ GetOptions(\%opt,
        },
 ) or exit 64;  # EX_USAGE
 
-$opt{width} ||= $ENV{COLUMNS} || qx(tput cols) || 80;
+$opt{width} ||= $ENV{COLUMNS} || qx(tput cols) || 80 unless $opt{spark};
 $opt{color} //= -t *STDOUT;  # enable on tty
 $opt{'graph-format'} //= '-';
 $opt{trim}   *= $opt{width} / 100 if $opt{trimpct};
@@ -154,6 +154,10 @@ while (defined ($_ = $opt{input} ? shift @{ $opt{input} } : readline)) {
                and $. % $opt{interval} == 0;
 }
 
+if ($opt{'zero-missing'}) {
+       push @values, (0) x 10;
+}
+
 $SIG{INT} = 'DEFAULT';
 
 sub color {
@@ -243,6 +247,7 @@ while ($nr <= $#lines) {
                $opt{palette}->[ $rel * ($#{$opt{palette}} - 1) + 1 ];
 
        if ($opt{spark}) {
+               say '' if $opt{width} and $nr and $nr % $opt{width} == 0;
                print color($color), $opt{spark}->[
                        !$val ? 0 : # blank
                        $val == $order[0] ? -1 : # max