From be204b9ad8d34c179c492e5f173b77e330fa53dd Mon Sep 17 00:00:00 2001 From: Juerd Waalboer Date: Tue, 11 Jul 2023 03:37:09 +0200 Subject: [PATCH] users: reformat user log view Shaves 7 characters off for most lines, and gets rid of infamous GAIN/LOSE display. The terms "GAIN" and "LOSE" were originally introduced because having negative numbers everywhere would look too, er, negative, and having a "+" for positive numbers would get hard to notice in a right aligned list. The visibility of the "+" was fixed a while ago, simply by adding a space between the sign and the number, and now the same style is applied to the user log view. Old: 2023-07-05 06:24:54 LOSE 2 1.80 Example [2x 0.90] 2023-07-07 20:55:53 GAIN 1 20.00 Received from someone (example) New: 2023-07-05 06:24:54 1.80 2x Example [2x 0.90] 2023-07-07 20:55:53 + 20.00 Received from someone (example) --- plugins/users | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/plugins/users b/plugins/users index f531f7c..2992f66 100644 --- a/plugins/users +++ b/plugins/users @@ -55,16 +55,27 @@ sub shame($self) { return ACCEPT; } -sub _grep($u) { +sub _grep($user) { + $user = lc $user; my @lines; open my $fh, "<", ".revbank.log" or die $!; + while (defined($_ = readline $fh)) { - s/CHECKOUT\s+\S+\s+(\S+)\s+// or next; - lc($1) eq lc($u) or next; - s/ #// or next; - s/_/ /; - push @lines, $_; + length($_) > 28 or next; + substr($_, 20, 8) eq 'CHECKOUT' or next; # fast check + + my ($dt, $c, $t_id, $u, $dir, $qty, $amount, undef, $desc) = split " ", $_, 9; + $c eq 'CHECKOUT' or next; # real check after expensive split + lc($u) eq $user or next; + + push @lines, sprintf "%s %8s %s%-s", ( + $dt =~ s/_/ /r, + $dir eq 'GAIN' ? "+ $amount" : $amount, # like R::A->string_flipped + $qty > 1 ? $qty . "x " : "", + $desc + ); } + return @lines; }