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)
This commit is contained in:
parent
338ea37127
commit
be204b9ad8
1 changed files with 17 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue