-$opt{color} //= 1;
-
-my @lines = readline or exit;
-chomp for @lines;
-my @values = map { s/^\h*(-?[0-9]*)// and $1 } @lines;
-my @order = sort { $b <=> $a } @values;
-my $maxval = max $order[0], -$order[-1];
-my $lenval = 1 + ($order[-1] < 0) + int log($maxval || 1) / log 10; # max string length
-my $len = 1 + max map { length } @lines; # left padding
-my $size = ($opt{width} - $lenval - $len) / $maxval; # bar multiplication
-
-sub orderpos { ($order[$_[0]] + $order[$_[0] + .5]) / 2 * $size }
+$opt{color} //= -t *STDOUT; # enable on tty
+$opt{trim} *= $opt{width} / 100 if $opt{trimpct};
+
+if (defined $opt{follow}) {
+ $opt{follow} ||= 1;
+ $SIG{ALRM} = sub {
+ show_lines();
+ alarm $opt{follow};
+ };
+ alarm $opt{follow};
+}
+
+$SIG{INT} = 'IGNORE'; # continue after assumed eof
+
+my (@lines, @values);
+while (readline) {
+ s/\r?\n\z//;
+ s/^\h*// unless $opt{unmodified};
+ push @values, s/^ ( \h* -? [0-9]* \.? [0-9]+ |)//x && $1;
+ if (defined $opt{trim}) {
+ my $trimpos = abs $opt{trim};
+ if ($trimpos <= 1) {
+ $_ = substr $_, 0, 1;
+ }
+ elsif (length > $trimpos) {
+ substr($_, $trimpos - 1) = '…';
+ }
+ }
+ push @lines, $_;
+}
+
+$SIG{INT} = 'DEFAULT';
+
+sub show_lines {
+
+state $nr = 0;
+@lines and @lines > $nr or return;
+
+my @order = sort { $b <=> $a } grep { length } @values;
+my $maxval = $order[0];
+my $minval = min $order[-1], 0;
+my $lenval = max map { length } @order;
+my $len = defined $opt{trim} && $opt{trim} <= 0 ? -$opt{trim} + 1 :
+ 1 + max map { length } @lines; # left padding
+my $size = ($maxval - $minval) &&
+ ($opt{width} - $lenval - $len) / ($maxval - $minval); # bar multiplication
+