show statistics on SIGQUIT
[barcat.git] / barcat
diff --git a/barcat b/barcat
index 2f73fa5ab2c59e3e8be6ce6b0b57fd235641587a..650e4060b1b30fd9c743d2f870c6998ade606578 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -43,6 +43,9 @@ GetOptions(\%opt,
                );
        },
        'markers|m=s',
+       'graph-format=s' => sub {
+               $opt{'graph-format'} = substr $_[1], 0, 1;
+       },
        'spark:s' => sub {
                $opt{spark} = [split //, $_[1] || '⎽▁▂▃▄▅▆▇█'];
        },
@@ -75,6 +78,7 @@ GetOptions(\%opt,
 
 $opt{width} ||= $ENV{COLUMNS} || 80;
 $opt{color} //= -t *STDOUT;  # enable on tty
+$opt{'graph-format'} //= '-';
 $opt{trim}   *= $opt{width} / 100 if $opt{trimpct};
 $opt{units}   = [split //, ' kMGTPEZYyzafpnμm'] if $opt{'human-readable'};
 $opt{anchor} //= qr/\A/;
@@ -83,6 +87,7 @@ $opt{'value-length'} = 1 if $opt{unmodified};
 
 my (@lines, @values, @order);
 
+$SIG{QUIT} = \&show_stat;
 $SIG{ALRM} = sub {
        show_lines();
        alarm $opt{interval} if defined $opt{interval} and $opt{interval} > 0;
@@ -205,7 +210,7 @@ while ($nr <= $#lines) {
        }
        my $line = $lines[$nr] =~ s/\n/$val/r;
        printf '%-*s', $len + length($val), $line;
-       print $barmark[$_] // '-' for 1 .. $size && (($values[$nr] || 0) - $minval) * $size + .5;
+       print $barmark[$_] // $opt{'graph-format'} for 1 .. $size && (($values[$nr] || 0) - $minval) * $size + .5;
        say '';
 }
 continue {
@@ -216,7 +221,7 @@ say '' if $opt{spark};
 }
 show_lines();
 
-if ($opt{stat}) {
+sub show_stat {
        if ($opt{hidemin} or $opt{hidemax}) {
                $opt{hidemin} ||= 1;
                $opt{hidemax} ||= @lines;
@@ -234,6 +239,7 @@ if ($opt{stat}) {
        }
        say '';
 }
+show_stat() if $opt{stat};
 
 __END__
 =encoding utf8
@@ -308,6 +314,11 @@ Stop output after a number of lines.
 All input is still counted and analyzed for statistics,
 but disregarded for padding and bar size.
 
+=item --graph-format=<character>
+
+Glyph to repeat for the graph line.
+Defaults to a dash C<->.
+
 =item -m, --markers=
 
 Statistical positions to indicate on bars.