X-Git-Url: http://git.shiar.net/barcat.git/blobdiff_plain/df0c8de6d8a58b68a94308ef203ee685d6e2fbd9..beb81e63d94ed634661c385bf676ceb3544f9079:/barcat diff --git a/barcat b/barcat index b0237c4..d4a8274 100755 --- a/barcat +++ b/barcat @@ -162,6 +162,7 @@ while (defined ($_ = $opt{input} ? shift @{ $opt{input} } : readline)) { $_ = substr $_, 0, 2; } elsif (length > $trimpos) { + # cut and replace (intentional lvalue for speed, contrary to PBP) substr($_, $trimpos - 1) = '…'; } } @@ -209,7 +210,7 @@ my $lenval = $opt{'value-length'} // max map { length } @order; my $len = defined $opt{trim} && $opt{trim} <= 0 ? -$opt{trim} + 1 : max map { length $values[$_] && length $lines[$_] } 0 .. min $#lines, $opt{hidemax} || (); # left padding -my $size = $range && +my $size = defined $opt{width} && $range && ($opt{width} - $lenval - $len) / $range; # bar multiplication my @barmark; @@ -221,13 +222,22 @@ if ($opt{markers} and $size > 0) { return sum(@order) / @order; } elsif ($func =~ /\A([0-9.]+)v\z/) { + die "Invalid marker $char: percentile $1 out of bounds\n" if $1 > 100; my $index = $#order * $1 / 100; return ($order[$index] + $order[$index + .5]) / 2; } - else { + elsif ($func =~ /\A-?[0-9.]+\z/) { return $func; } - } - $minval; + else { + die "Unknown marker $char: $func\n"; + } + }; + defined $pos or do { + warn $@ if $@; + next; + }; + $pos -= $minval; $pos >= 0 or next; color(36) for $barmark[$pos * $size] = $char; } @@ -266,7 +276,7 @@ while ($nr <= $#lines) { if ($opt{spark}) { say '' if $opt{width} and $nr and $nr % $opt{width} == 0; print color($color), $opt{spark}->[ - !$val ? 0 : # blank + !$val || !$#{$opt{spark}} ? 0 : # blank $val == $order[0] ? -1 : # max $val == $order[-1] ? 1 : # min $#{$opt{spark}} < 3 ? 1 : @@ -546,12 +556,12 @@ In PostgreSQL from within the client: Earthquakes worldwide magnitude 1+ in the last 24 hours: - https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_day.csv | + curl https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_day.csv | column -tns, | barcat -f4 -u -l80% External datasets, like movies per year: - curl https://github.com/prust/wikipedia-movie-data/raw/master/movies.json | + curl https://github.com/prust/wikipedia-movie-data/raw/master/movies.json -L | perl -054 -nlE 'say if s/^"year"://' | uniq -c | barcat But please get I to process JSON @@ -559,7 +569,7 @@ and replace the manual selection by C<< jq '.[].year' >>. Pokémon height comparison: - curl https://github.com/Biuni/PokemonGO-Pokedex/raw/master/pokedex.json | + curl https://github.com/Biuni/PokemonGO-Pokedex/raw/master/pokedex.json -L | jq -r '.pokemon[] | [.height,.num,.name] | join(" ")' | barcat USD/EUR exchange rate from CSV provided by the ECB: @@ -570,7 +580,7 @@ USD/EUR exchange rate from CSV provided by the ECB: Total population history in XML from the World Bank: - curl http://api.worldbank.org/v2/country/1W/indicator/SP.POP.TOTL | + curl http://api.worldbank.org/v2/country/1W/indicator/SP.POP.TOTL -L | xmllint --xpath '//*[local-name()="date" or local-name()="value"]' - | sed -r 's,,\n,g; s,(<[^>]+>)+, ,g' | barcat -f1 -H