feat(times): Show Total tracked time (fix #2)

This commit is contained in:
Noah 2024-03-17 21:42:40 -05:00
parent 677047a7c5
commit f8d6d8f5b2

View File

@ -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
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)