From f4423db9671d9650e7a39482ffc935d373e72ef5 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Mon, 9 Sep 2019 19:17:38 +0200 Subject: [PATCH] spark option to replace lines by single characters Implement "sparklines" (one-line graph) by simply substituting Unicode block elements U+2581-2588 relative to values. Inspired by Zach Holman's `spark` . --- barcat | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/barcat b/barcat index 5863c4c..82cf7d6 100755 --- a/barcat +++ b/barcat @@ -47,6 +47,9 @@ GetOptions(\%opt, ); }, 'markers|m=s', + 'spark!' => sub { + $opt{spark} = [split //, '⎽▁▂▃▄▅▆▇█']; + }, 'stat|s!', 'unmodified|u!', 'width|w=i', @@ -164,6 +167,12 @@ sub sival { while ($nr <= $#lines) { $nr >= $opt{hidemax} and last if defined $opt{hidemax}; my $val = $values[$nr]; + + if ($opt{spark}) { + print $opt{spark}->[ ($val - $minval) / $maxval * $#{$opt{spark}} ]; + next; + } + if (length $val) { my $color = !$opt{color} ? undef : $val == $order[0] ? 32 : # max @@ -176,9 +185,11 @@ while ($nr <= $#lines) { printf '%-*s', $len + length($val), $line; print $barmark[$_] // '-' for 1 .. $size && (($values[$nr] || 0) - $minval) * $size + .5; say ''; - +} +continue { $nr++; } +say '' if $opt{spark}; } show_lines(); @@ -398,7 +409,7 @@ Activity of the last days (substitute date C<-v-{}d> on BSD): ( git log --pretty=%ci --since=30day | cut -b-10 seq 0 30 | xargs -i date +%F -d-{}day ) | - sort | uniq -c | awk '$1--' | graph + sort | uniq -c | awk '$1--' | graph --spark =head1 AUTHOR -- 2.30.0