From ac5854882bde4c88cf9d66fc2ede5762aaf0c2bd Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 4 Sep 2019 15:59:49 +0200 Subject: [PATCH] reformat and colourise numbers Replace captured values in dark grey, with minimal padding (uniq adds at least 6 spaces we can use for graphing). --- graph | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/graph b/graph index d20fcd3..cce0d3c 100755 --- a/graph +++ b/graph @@ -7,12 +7,17 @@ my $width = $ENV{COLUMNS} || 80; my @lines = readline; chomp for @lines; -my @values = map { /^\h*([0-9]*)/ } @lines; +my @values = map { s/^\h*([0-9]*)// and $1 } @lines; my $maxval = max @values; +my $lenval = 1 + int log($maxval) / log 10; # max string length my $len = 1 + max map { length } @lines; # left padding -my $size = ($width - $len) / $maxval; # bar multiplication +my $size = ($width - $lenval - $len) / $maxval; # bar multiplication -for (@lines) { - my $val = shift @values; - say $_, ' ' x ($len - length), '#' x ($val * $size); +for my $nr (0 .. $#lines) { + my $val = $values[$nr]; + printf "\e[90m"; + printf "%*s", $lenval, $val; + print "\e[0m"; + printf '%-*s', $len, $lines[$nr]; + say '-' x ($val * $size); } -- 2.30.0