ignore interval option without input file
[barcat.git] / barcat
diff --git a/barcat b/barcat
index 424bec2a979fbf363302e689a467c37fc0b1d2ee..144b6244d0bd3970bdc1e36dbea987a330cb2566 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -1,10 +1,9 @@
 #!/usr/bin/perl -CA
-use 5.018;
+use 5.014;
 use warnings;
 use utf8;
 use List::Util qw( min max sum );
 use open qw( :std :utf8 );
-use experimental qw( lexical_subs );
 
 our $VERSION = '1.06';
 
@@ -101,7 +100,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};
@@ -112,7 +111,8 @@ $opt{'value-length'} = 1 if $opt{unmodified};
 $opt{'signal-stat'} //= exists $SIG{INFO} ? 'INFO' : 'QUIT';
 $opt{markers} //= '=avg >31.73v <68.27v +50v |0';
 $opt{palette} //= $opt{color} && [31, 90, 32];
-$opt{input} = @ARGV && $ARGV[0] =~ m/\A[-0-9]/ ? \@ARGV : undef;
+$opt{input} = @ARGV && $ARGV[0] =~ m/\A[-0-9]/ ? \@ARGV : undef
+       and undef $opt{interval};
 
 my (@lines, @values, @order);
 
@@ -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
@@ -493,7 +498,7 @@ Monitor network latency from prefixed results:
 
 Commonly used after counting, for example users on the current server:
 
-    users | sed 's/ /\n/g' | sort | uniq -c | barcat
+    users | tr ' ' '\n' | sort | uniq -c | barcat
 
 Letter frequencies in text files:
 
@@ -534,8 +539,7 @@ USD/EUR exchange rate from CSV provided by the ECB:
          -Gd 'node=SEARCHRESULTS&q=EXR.D.USD.EUR.SP00.A&exportType=csv' |
     grep '^[12]' | barcat -f',\K' --value-length=7
 
-Total population history from the World Bank dataset (XML):
-External datasets, like total population in XML from the World Bank:
+Total population history in XML from the World Bank:
 
     curl http://api.worldbank.org/v2/country/1W/indicator/SP.POP.TOTL |
     xmllint --xpath '//*[local-name()="date" or local-name()="value"]' - |