X-Git-Url: http://git.shiar.nl/barcat.git/blobdiff_plain/e40f2d7b5bec7ae512a9e005786905d090cd5bfe..ba4406a60d218341b89196f2466459e4b2384996:/barcat diff --git a/barcat b/barcat index b0de950..a69bbe5 100755 --- a/barcat +++ b/barcat @@ -29,7 +29,17 @@ GetOptions(\%opt, $opt{trim} = $optval; }, 'value-length=i', - 'limit|L=i', + 'hidemin=i', + 'hidemax=i', + 'limit|L=s' => sub { + my ($optname, $optval) = @_; + $optval ||= 0; + ($opt{hidemin}, $opt{hidemax}) = + $optval =~ m/\A (?: ([0-9]+)? - )? ([0-9]+)? \z/x or die( + "Value \"$optval\" invalid for option limit", + " (range expected)\n" + ); + }, 'markers|m=s', 'unmodified|u!', 'width|w=i', @@ -76,16 +86,16 @@ $SIG{INT} = 'DEFAULT'; sub show_lines { -state $nr = 0; +state $nr = $opt{hidemin} ? $opt{hidemin} - 1 : 0; @lines and @lines > $nr or return; my @order = sort { $b <=> $a } grep { length } @values; -my $maxval = $opt{limit} ? max @values[0 .. $opt{limit} - 1] : $order[0]; +my $maxval = $opt{hidemax} ? max @values[0 .. $opt{hidemax} - 1] : $order[0]; my $minval = min $order[-1], 0; 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{limit} || (); # left padding + 0 .. min $#lines, $opt{hidemax} || (); # left padding my $size = ($maxval - $minval) && ($opt{width} - $lenval - $len) / ($maxval - $minval); # bar multiplication @@ -114,6 +124,7 @@ if ($opt{markers} // 1 and $size > 0) { } while ($nr <= $#lines) { + $nr >= $opt{hidemax} and last if $opt{hidemax}; my $val = $values[$nr]; if (length $val) { my $color = !$opt{color} ? 0 : @@ -129,7 +140,6 @@ while ($nr <= $#lines) { say ''; $nr++; - $nr >= $opt{limit} and last if $opt{limit}; } } @@ -187,7 +197,7 @@ unless C<--length=0>. Prepend a dash (i.e. make negative) to enforce padding regardless of encountered contents. -=item -L, --limit= +=item -L, --limit=(|-[]) Stop output after a number of lines. All input is still counted and analyzed for statistics,