diff options
| author | Paul Buetow <paul@buetow.org> | 2023-03-07 02:01:10 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-03-07 02:01:10 +0200 |
| commit | 168348c14cc47e32c7cdb9e243dd9f3554dfc399 (patch) | |
| tree | d3cb0c590322f079623a3b89e9a821c276395651 | |
| parent | 1cb64b9c690a570c3e7059e789102c5f6a4231f0 (diff) | |
better table output
| -rw-r--r-- | guprecords.raku | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/guprecords.raku b/guprecords.raku index 40873de..534546f 100644 --- a/guprecords.raku +++ b/guprecords.raku @@ -100,22 +100,34 @@ class Reporter { method report { say "Top {$.first} {$.sub-cat}'s by {$.cat}:"; + with self!table -> (@table, %size) { + my Str \format = "| %{%size<count>}s | %{%size<name>}s | %{%size<value>}s |\n"; + printf format, 'Pos', $.cat, $.sub-cat; + for @table -> \position, \name, \value { + printf format, position, name, value; + } + } + } + + method !table returns List { my Nat $count = 0; + my @table; + my %size := { count => 'Pos'.chars, name => $.cat.chars, value => $.sub-cat.chars }; - printf " %4s|%16s|%16s\n", '-' x 4, '-' x 16, '-' x 16; - printf "%3s. |%15s | %s\n", 'Pos', $.cat, $.sub-cat; - printf " %4s|%16s|%16s\n", '-' x 4, '-' x 16, '-' x 16; - for self.sort-by($!sub-cat) -> Aggregate $what { - self!pretty-say($what, $count+1); + for self.sort-by($!sub-cat) -> Aggregate \what { + my Str \active = what.is-active ?? '*' !! ' '; + my Str \name = active ~ what.name; + my Str \value = self.human-str($!sub-cat, what).Str; + + with $count.Str.chars+1 { %size<count> = $_ if %size<count> < $_ } + with name.chars { %size<name> = $_ if %size<name> < $_ } + with value.chars { %size<value> = $_ if %size<value> < $_ } + + @table.push: "{$count+1}.", name, value; last if ++$count == $.first; } - printf " %4s|%16s|%16s\n", '-' x 4, '-' x 16, '-' x 16; - } - method !pretty-say(Aggregate:D \what, Nat:D \position) { - my Str \active = what.is-active ?? '*' !! ' '; - my Str \display = (active ~ what.name).substr(0,15); - printf "%3d. |%15s | %s\n", position, display, self.human-str($.sub-cat, what); + return @table, %size; } multi method sort-by('uptime') { self.sort-by: *.uptime } |
