From 9550ed22b3f54bf1e0fb27eebee8099334fc9cb1 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Mon, 21 Nov 2022 18:21:29 +0100 Subject: [PATCH] report variables always formatted on trailing + Random character chosen to fix sum values (t1602-float_statistics &a) without obscure code invocations. --- barcat | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/barcat b/barcat index a86f74f..e898b6c 100755 --- a/barcat +++ b/barcat @@ -359,13 +359,14 @@ sub show_stat { $linemin += @lines; $linemax = @lines - $linemax; } - printf '%.8g of ', $opt{'value-format'}->( - sum(grep {length} @values[$linemin .. $linemax]) // 0 - ); + print varfmt('${sum+} of ', { + lines => $linemax - $linemin + 1, + sum => sum(0, grep {length} @values[$linemin .. $linemax]), + }); } if (@order) { my $total = sum @order; - my $fmt = '${sum;color(1)} total in ${count#} values'; + my $fmt = '${sum+;color(1)} total in ${count#} values'; $fmt .= ' over ${lines#} lines' if @order != @lines; $fmt .= " ($_)" for $opt{report} || (); print varfmt($fmt, { @@ -383,9 +384,9 @@ sub show_stat { sub varfmt { my ($fmt, $vars) = @_; - $fmt =~ s[\$\{( (?: [^{}]++ | \{(?1)\} )+ )\}]{ + $fmt =~ s[\$\{ \h*+ ((?: [^{}]++ | \{(?1)\} )+) \}]{ my ($name, $cmd) = split /\s*;/, $1, 2; - my $format = $name !~ s/\h*\#// && $opt{reformat}; + my $format = $name =~ s/\+// || $name !~ s/\#// && $opt{reformat}; local $_ = $vars->{$name}; if (defined) { $_ = $opt{'value-format'}->($_) if $format; -- 2.30.0