From f8d6d8f5b293b9833edd50e9cb6f49d33699e3ea Mon Sep 17 00:00:00 2001 From: Noah Date: Sun, 17 Mar 2024 21:42:40 -0500 Subject: [PATCH] feat(times): Show Total tracked time (fix #2) --- times.go | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/times.go b/times.go index d01e32b..898036d 100644 --- a/times.go +++ b/times.go @@ -14,10 +14,12 @@ import ( "code.gitea.io/sdk/gitea" ) -var textStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#626262")) +var textStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#5b6078")) type timesviewer struct { - table table.Model + table table.Model + length int + total_time time.Duration } func (m timesviewer) Init() tea.Cmd { @@ -42,7 +44,12 @@ func (m timesviewer) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd } func (m timesviewer) View() string { - return m.table.View() + "\n" + textStyle.Render("\n Use Up and Down arrows to navigate\n") + var totalTextStyle = lipgloss.NewStyle(). + Foreground(lipgloss.Color("#6e738d")). + Bold(true) + return m.table.View() + + textStyle.Render("\nUse Up and Down arrows to navigate") + + totalTextStyle.Render(fmt.Sprintf("\nTotal - %s\n", m.total_time.String())) } type Indicator struct { @@ -68,7 +75,7 @@ func (i IndicatorInfo) String() string { func initialIndicator() Indicator { s := spinner.New() s.Spinner = spinner.Dot - s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205")) + s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("#a6da95")) return Indicator{spinner: s} } func (m Indicator) Init() tea.Cmd { @@ -95,7 +102,6 @@ func (m Indicator) View() string { } str := "" if !m.quitting { - // str += fmt.Sprintf("\n %s Loading time logs...\n", m.spinner.View()) str += fmt.Sprintf("\n %s Loading time logs...\n %s\n", m.spinner.View(), m.info.String()) } return str @@ -155,6 +161,8 @@ func times() { }) p.Quit() + var total_time time.Duration + columns := []table.Column{ {Title: "User", Width: 10}, {Title: "Time", Width: 8}, @@ -171,26 +179,33 @@ func times() { dur.String(), t.Created.String(), }) + total_time += dur + } + tv := timesviewer{ + total_time: total_time, + length: 50, } tab := table.New( table.WithColumns(columns), table.WithRows(rows), table.WithFocused(true), table.WithHeight(10), + table.WithWidth(tv.length), ) s := table.DefaultStyles() s.Header = s.Header. + Foreground(lipgloss.Color("#6e738d")). BorderStyle(lipgloss.DoubleBorder()). - BorderForeground(lipgloss.Color("240")). + BorderForeground(lipgloss.Color("#a6da95")). BorderBottom(true). Bold(false) s.Selected = s.Selected. - Foreground(lipgloss.Color("229")). - Background(lipgloss.Color("57")). + Foreground(lipgloss.Color("#494d64")). + Background(lipgloss.Color("#a6da95")). Bold(false) tab.SetStyles(s) + tv.table = tab - tv := timesviewer{tab} if _, err := tea.NewProgram(tv).Run(); err != nil { fmt.Println("Error running program:", err) os.Exit(1)