X-Git-Url: http://git.shiar.nl/barcat.git/blobdiff_plain/dadf1e71a2fb2f1f331d830636d286ab98b4034a..b8ecf0c19b1c9f899933a067a6958edf859927f8:/barcat diff --git a/barcat b/barcat index 5676228..aa18957 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}; @@ -154,6 +153,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 +246,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 @@ -277,7 +281,7 @@ sub show_stat { } if (@order) { my $total = sum @order; - printf '%s total', color(1) . $total . color(0); + printf '%s total', color(1) . sprintf('%.8g', $total) . color(0); printf ' in %d values', scalar @order; printf ' over %d lines', scalar @lines if @order != @lines; printf(' (%s min, %s avg, %s max)', @@ -534,8 +538,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"]' - |