X-Git-Url: http://git.shiar.nl/barcat.git/blobdiff_plain/a052b8d20f25e69c82104135c9925c17dcaa3eb3..ea4599f110cbf1c347535ac1add4299bb8a5e13e:/graph diff --git a/graph b/graph index e76ec64..0e07a6e 100755 --- a/graph +++ b/graph @@ -1,9 +1,10 @@ #!/usr/bin/env perl -use 5.014; +use 5.018; use warnings; use utf8; use List::Util qw( min max sum ); use open qw( :std :utf8 ); +use experimental qw( lexical_subs ); our $VERSION = '1.02'; @@ -12,10 +13,19 @@ sub podexit { require Pod::Usage; Pod::Usage::pod2usage(-exitval => 0, -perldocopt => '-oman', @_); } -GetOptions(\my %opt, +my %opt; +GetOptions(\%opt, 'color|c!', 'follow|f:i', - 'trim|length|l=i', + 'trim|length|l=s' => sub { + my ($optname, $optval) = @_; + $optval =~ s/%$// and $opt{trimpct}++; + $optval =~ m/^-?[0-9]+$/ or die( + "Value \"$optval\" invalid for option $optname", + " (number or percentage expected)\n" + ); + $opt{trim} = $optval; + }, 'markers|m=s', 'unmodified|u!', 'width|w=i', @@ -25,6 +35,7 @@ GetOptions(\my %opt, $opt{width} ||= $ENV{COLUMNS} || 80; $opt{color} //= -t *STDOUT; # enable on tty +$opt{trim} *= $opt{width} / 100 if $opt{trimpct}; if (defined $opt{follow}) { $opt{follow} ||= 1; @@ -53,13 +64,13 @@ while (readline) { } push @lines, $_; } -@lines or exit; $SIG{INT} = 'DEFAULT'; sub show_lines { state $nr = 0; +@lines and @lines > $nr or return; my @order = sort { $b <=> $a } grep { length } @values; my $maxval = $order[0]; @@ -142,7 +153,7 @@ disabled otherwise such as when piped or redirected. Interval to output partial progress. -=item -l, --length=[-] +=item -l, --length=[-][%] Trim line contents (between number and bars) to a maximum number of characters.