$opt{width} ||= $ENV{COLUMNS} || 80;
$opt{color} //= -t *STDOUT; # enable on tty
$opt{trim} *= $opt{width} / 100 if $opt{trimpct};
$opt{width} ||= $ENV{COLUMNS} || 80;
$opt{color} //= -t *STDOUT; # enable on tty
$opt{trim} *= $opt{width} / 100 if $opt{trimpct};
my @order = sort { $b <=> $a } grep { length } @values;
my $maxval = $opt{hidemax} ? max @values[0 .. $opt{hidemax} - 1] : $order[0];
my @order = sort { $b <=> $a } grep { length } @values;
my $maxval = $opt{hidemax} ? max @values[0 .. $opt{hidemax} - 1] : $order[0];
sub sival {
my $unit = int(log($_[0]) / log(1000) - ($_[0] < 1));
my $float = $_[0] !~ /^ (?: 0*\.)? [0-9]{1,3} $/x;
sprintf('%*.*f%*s',
$float ? 5 : 3, $float, # length and tenths
$_[0] / 1000 ** $unit, # number
sub sival {
my $unit = int(log($_[0]) / log(1000) - ($_[0] < 1));
my $float = $_[0] !~ /^ (?: 0*\.)? [0-9]{1,3} $/x;
sprintf('%*.*f%*s',
$float ? 5 : 3, $float, # length and tenths
$_[0] / 1000 ** $unit, # number