git.shiar.nl
/
barcat.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
13a52d1
)
move human formatting code into sival() function
author
Mischa POSLAWSKY
<perl@shiar.org>
Sat, 7 Sep 2019 13:49:36 +0000
(15:49 +0200)
committer
Mischa POSLAWSKY
<perl@shiar.org>
Sat, 7 Sep 2019 18:16:38 +0000
(20:16 +0200)
barcat
patch
|
blob
|
history
diff --git
a/barcat
b/barcat
index 5ac55bab9cfbe5987aa818c2a5ef512644d40e40..69f4516c0fbd766defefe578e9cb6e8eb4cd1efc 100755
(executable)
--- a/
barcat
+++ b/
barcat
@@
-125,6
+125,11
@@
if ($opt{markers} // 1 and $size > 0) {
}
}
}
}
+sub sival {
+ my $unit = int(log($_[0]) / log(1000) - ($_[0] < 1));
+ sprintf "%3.1f%1s", $_[0] / 1000 ** $unit, $opt{units}->[$unit];
+}
+
while ($nr <= $#lines) {
$nr >= $opt{hidemax} and last if $opt{hidemax};
my $val = $values[$nr];
while ($nr <= $#lines) {
$nr >= $opt{hidemax} and last if $opt{hidemax};
my $val = $values[$nr];
@@
-133,9
+138,7
@@
while ($nr <= $#lines) {
$val == $order[0] ? 32 : # max
$val == $order[-1] ? 31 : # min
90;
$val == $order[0] ? 32 : # max
$val == $order[-1] ? 31 : # min
90;
- $val = sprintf "%3.1f%1s", $val / 1000**$_, $opt{units}->[$_]
- for $opt{units} ? int(log($val) / log(1000) - ($val < 1)) : ();
- $val = sprintf "%*s", $lenval, $val;
+ $val = $opt{units} ? sival($val) : sprintf "%*s", $lenval, $val;
$val = "\e[${color}m$val\e[0m" if $color;
}
my $line = $lines[$nr] =~ s/\n/$val/r;
$val = "\e[${color}m$val\e[0m" if $color;
}
my $line = $lines[$nr] =~ s/\n/$val/r;