empty limit support (hidemax internally)
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 7 Sep 2019 02:40:01 +0000 (04:40 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 7 Sep 2019 18:16:38 +0000 (20:16 +0200)
barcat

diff --git a/barcat b/barcat
index b0de950c6ad23f608c8703ee81a9e7f7c0749c14..d12baf6a3cad2b8e7cab1f56c99e616301145052 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -29,7 +29,7 @@ GetOptions(\%opt,
                $opt{trim} = $optval;
        },
        'value-length=i',
-       'limit|L=i',
+       'hidemax|limit|L=i',
        'markers|m=s',
        'unmodified|u!',
        'width|w=i',
@@ -80,12 +80,12 @@ state $nr = 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 +114,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 +130,6 @@ while ($nr <= $#lines) {
        say '';
 
        $nr++;
-       $nr >= $opt{limit} and last if $opt{limit};
 }
 
 }