From ef8a9d9c7231f42bba4cd0b5fe56d1ed77b74e26 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 14 Jul 2021 23:11:53 -0300 Subject: [PATCH] fix: log to file, improve styles Signed-off-by: Carlos Alexandro Becker --- .gitignore | 1 + cmd/root.go | 6 ++++++ go.mod | 1 - go.sum | 2 -- highlights/highlight.go | 18 +++++++++++------- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 66e09d3..a2d1cb1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ bin coverage.out snap.login completions/ +*.log diff --git a/cmd/root.go b/cmd/root.go index a9ee83c..2b5ad70 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -97,6 +97,12 @@ Important notes: csv = f } + f, err := tea.LogToFile("org-stats.log", "org-stats") + if err != nil { + return err + } + defer f.Close() + p := tea.NewProgram(ui.NewInitialModel( client, organization, diff --git a/go.mod b/go.mod index 553d307..422bc1f 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,6 @@ module github.com/caarlos0/org-stats require ( github.com/caarlos0/duration v0.0.0-20210713014422-2153d649c037 - github.com/caarlos0/spin v1.1.0 github.com/charmbracelet/bubbles v0.8.0 github.com/charmbracelet/bubbletea v0.14.1 github.com/charmbracelet/lipgloss v0.3.0 diff --git a/go.sum b/go.sum index 43efbda..d982147 100644 --- a/go.sum +++ b/go.sum @@ -48,8 +48,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/caarlos0/duration v0.0.0-20210713014422-2153d649c037 h1:Rn1A0df8CQZsO7hDvZGAVR06N6jqonCuj/K3IrGNZZY= github.com/caarlos0/duration v0.0.0-20210713014422-2153d649c037/go.mod h1:mSkwb/eZEwOJJJ4tqAKiuhLIPe0e9+FKhlU0oMCpbf8= -github.com/caarlos0/spin v1.1.0 h1:EjsfGbZJejib25BPnDqf7iL2z9RUna7refvUf+AN9UE= -github.com/caarlos0/spin v1.1.0/go.mod h1:HOC4pUvfhjXR2yDt+sEY9dRc2m4CCaK5z5oQYAbzXSA= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/charmbracelet/bubbles v0.8.0 h1:+l2op90Ag37Vn+30O1hbg/0wBl+e+sxHhgY1F/rvdHs= github.com/charmbracelet/bubbles v0.8.0/go.mod h1:5WX1sSSjNCgCrzvRMN/z23HxvWaa+AI16Ch0KPZPeDs= diff --git a/highlights/highlight.go b/highlights/highlight.go index a47ff76..db48e4e 100644 --- a/highlights/highlight.go +++ b/highlights/highlight.go @@ -38,14 +38,21 @@ func Write(w io.Writer, s orgstats.Stats, top int, includeReviews bool) error { Foreground(lipgloss.AdaptiveColor{ Dark: "#BD7EFC", Light: "#7D56F4", - }) + }). + MarginTop(1). + Underline(true) var bodyStyle = lipgloss.NewStyle(). - PaddingLeft(2) + MarginLeft(2) + + var userStyle = lipgloss.NewStyle().Bold(true) // TODO: handle no results for a given topic for _, d := range data { - if _, err := fmt.Fprintln(w, headerStyle.Render(d.trophy+" champions are:")); err != nil { + if _, err := fmt.Fprintln( + w, + headerStyle.Render(d.trophy+" champions are:"), + ); err != nil { return err } j := top @@ -58,7 +65,7 @@ func Write(w io.Writer, s orgstats.Stats, top int, includeReviews bool) error { fmt.Sprintf( "%s %s with %d %s!", emojiForPos(i), - d.stats[i].Key, + userStyle.Render(d.stats[i].Key), d.stats[i].Value, d.kind, ), @@ -67,9 +74,6 @@ func Write(w io.Writer, s orgstats.Stats, top int, includeReviews bool) error { return err } } - if _, err := fmt.Fprintln(w); err != nil { - return err - } } return nil }