diff options
| author | Paul Buetow <paul@buetow.org> | 2025-02-05 01:02:17 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-02-05 01:02:17 +0200 |
| commit | 24778551d8e5b0b47a06494dd28a66a71dfb47f0 (patch) | |
| tree | 6000d14601d57f2f34840793f1798c8baefc59ca /internal/schedule | |
| parent | 07d9f1840494924dd6ca713493dd3d630e9ad721 (diff) | |
use of generic ascii table package
Diffstat (limited to 'internal/schedule')
| -rw-r--r-- | internal/schedule/stats.go | 55 |
1 files changed, 13 insertions, 42 deletions
diff --git a/internal/schedule/stats.go b/internal/schedule/stats.go index 40cc175..ecc840d 100644 --- a/internal/schedule/stats.go +++ b/internal/schedule/stats.go @@ -1,10 +1,8 @@ package schedule import ( - "fmt" "os" "path/filepath" - "strconv" "strings" "time" @@ -12,6 +10,7 @@ import ( "codeberg.org/snonux/gos/internal/entry" "codeberg.org/snonux/gos/internal/oi" "codeberg.org/snonux/gos/internal/platforms" + "codeberg.org/snonux/gos/internal/table" "codeberg.org/snonux/gos/internal/timestamp" ) @@ -155,48 +154,20 @@ func (s *stats) gatherQueuedStats(dir string) error { } func (s stats) RenderTable(platform platforms.Platform) { - var sb strings.Builder - - val := func(val any) string { - switch v := val.(type) { - case int: - return strconv.Itoa(v) - case float64: - return fmt.Sprintf("%0.2f", v) - case string: - return v - default: - return fmt.Sprintf("%v", v) - } - } - - dataRow := func(descr1 string, val1 any, descr2 string, val2 any) { - const format = "| %-21s | %-11s | %-21s | %-11s |" - sb.WriteString(colour.SInfo2f(format, descr1, val(val1), descr2, val(val2))) - sb.WriteString("\n") - } + err := table.New(platform.String(), "value", "Lifetime stats", "value"). + WithColor(colour.Info2Col). + Add("Since (days)", s.sinceDays, "Total since (days)", s.totalSinceDays). + Add("#Posted entries", s.posted, "#Total posted entries", s.totalPosted). + Add("#Queued entries", s.queued, "", ""). + Add("Enough for (days)", s.queuedForDays, "", ""). + Add("Last post (days ago)", s.lastPostDaysAgo, "Pause days", s.pauseDays). + Add("Posts per day", s.postsPerDay, "Total posts per day", s.totalPostsPerDay). + Add("Posts per day target", s.postsPerDayTarget, "", ""). + Render() - sep := colour.SInfo2f("+%s+%s+%s+%s+", strings.Repeat("-", 23), - strings.Repeat("-", 13), strings.Repeat("-", 23), strings.Repeat("-", 13)) - - separator := func() { - sb.WriteString(sep) - sb.WriteString("\n") + if err != nil { + panic(err) } - - separator() - dataRow(platform.String(), "value", "Lifetime stats", "value") - separator() - dataRow("Since (days)", s.sinceDays, "Total since (days)", s.totalSinceDays) - dataRow("#Posted entries", s.posted, "#Total posted entries", s.totalPosted) - dataRow("#Queued entries", s.queued, "", "") - dataRow("Enough for (days)", s.queuedForDays, "", "") - dataRow("Last post (days ago)", s.lastPostDaysAgo, "Pause days", s.pauseDays) - dataRow("Posts per day", s.postsPerDay, "Total posts per day", s.totalPostsPerDay) - dataRow("Posts per day target", s.postsPerDayTarget, "", "") - separator() - - fmt.Print(sb.String()) } func pastTime(duration time.Duration) time.Time { |
