reserve minimal length for -H formatting
[barcat.git] / barcat
diff --git a/barcat b/barcat
index 1a1112c0ccdfa530e55b1792a7d25bf21f5381c1..426053ecce2f864fe5bc8144e538761677657431 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -116,7 +116,7 @@ $opt{trim}   *= $opt{width} / 100 if $opt{trimpct};
 $opt{units}   = [split //, ' kMGTPEZYyzafpn'.($opt{ascii} ? 'u' : 'μ').'m']
        if $opt{'human-readable'};
 $opt{anchor} //= qr/\A/;
-$opt{'value-length'} = 6 if $opt{units};
+$opt{'value-length'} = 4 if $opt{units};
 $opt{'value-length'} = 1 if $opt{unmodified};
 $opt{'signal-stat'} //= exists $SIG{INFO} ? 'INFO' : 'QUIT';
 $opt{markers} //= '=avg >31.73v <68.27v +50v |0';
@@ -131,8 +131,8 @@ $opt{input} = (@ARGV && $ARGV[0] =~ m/\A[-0-9]/) ? \@ARGV : undef
 $opt{'sum-format'} = sub { sprintf '%.8g', $_[0] };
 $opt{'calc-format'} = sub { sprintf '%*.*f', 0, 2, $_[0] };
 $opt{'value-format'} = $opt{sexagesimal} ? sub {
-       my $s = $_[0] + .5;
-       sprintf('%d:%02d:%02d', $s/3600, $s/60%60, $s%60);
+       my $s = abs($_[0]) + .5;
+       sprintf('%s%d:%02d:%02d', $_[0] < 0 && '-', $s/3600, $s/60%60, $s%60);
 } : $opt{units} && sub {
        my $unit = (
                log(abs $_[0] || 1) / log(10)