X-Git-Url: http://git.shiar.net/barcat.git/blobdiff_plain/4820a5300d409142bc5a3fec59006e3a96ea59df..97da4d68eddd9d66e30a73978afe2ad2f08364a7:/barcat diff --git a/barcat b/barcat index 424bec2..144b624 100755 --- 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"]' - |