feat(times): Show Total tracked time (fix #2)
This commit is contained in:
parent
677047a7c5
commit
f8d6d8f5b2
31
times.go
31
times.go
@ -14,10 +14,12 @@ import (
|
|||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
)
|
)
|
||||||
|
|
||||||
var textStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#626262"))
|
var textStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#5b6078"))
|
||||||
|
|
||||||
type timesviewer struct {
|
type timesviewer struct {
|
||||||
table table.Model
|
table table.Model
|
||||||
|
length int
|
||||||
|
total_time time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m timesviewer) Init() tea.Cmd {
|
func (m timesviewer) Init() tea.Cmd {
|
||||||
@ -42,7 +44,12 @@ func (m timesviewer) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return m, cmd
|
return m, cmd
|
||||||
}
|
}
|
||||||
func (m timesviewer) View() string {
|
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 {
|
type Indicator struct {
|
||||||
@ -68,7 +75,7 @@ func (i IndicatorInfo) String() string {
|
|||||||
func initialIndicator() Indicator {
|
func initialIndicator() Indicator {
|
||||||
s := spinner.New()
|
s := spinner.New()
|
||||||
s.Spinner = spinner.Dot
|
s.Spinner = spinner.Dot
|
||||||
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
|
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("#a6da95"))
|
||||||
return Indicator{spinner: s}
|
return Indicator{spinner: s}
|
||||||
}
|
}
|
||||||
func (m Indicator) Init() tea.Cmd {
|
func (m Indicator) Init() tea.Cmd {
|
||||||
@ -95,7 +102,6 @@ func (m Indicator) View() string {
|
|||||||
}
|
}
|
||||||
str := ""
|
str := ""
|
||||||
if !m.quitting {
|
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())
|
str += fmt.Sprintf("\n %s Loading time logs...\n %s\n", m.spinner.View(), m.info.String())
|
||||||
}
|
}
|
||||||
return str
|
return str
|
||||||
@ -155,6 +161,8 @@ func times() {
|
|||||||
})
|
})
|
||||||
p.Quit()
|
p.Quit()
|
||||||
|
|
||||||
|
var total_time time.Duration
|
||||||
|
|
||||||
columns := []table.Column{
|
columns := []table.Column{
|
||||||
{Title: "User", Width: 10},
|
{Title: "User", Width: 10},
|
||||||
{Title: "Time", Width: 8},
|
{Title: "Time", Width: 8},
|
||||||
@ -171,26 +179,33 @@ func times() {
|
|||||||
dur.String(),
|
dur.String(),
|
||||||
t.Created.String(),
|
t.Created.String(),
|
||||||
})
|
})
|
||||||
|
total_time += dur
|
||||||
|
}
|
||||||
|
tv := timesviewer{
|
||||||
|
total_time: total_time,
|
||||||
|
length: 50,
|
||||||
}
|
}
|
||||||
tab := table.New(
|
tab := table.New(
|
||||||
table.WithColumns(columns),
|
table.WithColumns(columns),
|
||||||
table.WithRows(rows),
|
table.WithRows(rows),
|
||||||
table.WithFocused(true),
|
table.WithFocused(true),
|
||||||
table.WithHeight(10),
|
table.WithHeight(10),
|
||||||
|
table.WithWidth(tv.length),
|
||||||
)
|
)
|
||||||
s := table.DefaultStyles()
|
s := table.DefaultStyles()
|
||||||
s.Header = s.Header.
|
s.Header = s.Header.
|
||||||
|
Foreground(lipgloss.Color("#6e738d")).
|
||||||
BorderStyle(lipgloss.DoubleBorder()).
|
BorderStyle(lipgloss.DoubleBorder()).
|
||||||
BorderForeground(lipgloss.Color("240")).
|
BorderForeground(lipgloss.Color("#a6da95")).
|
||||||
BorderBottom(true).
|
BorderBottom(true).
|
||||||
Bold(false)
|
Bold(false)
|
||||||
s.Selected = s.Selected.
|
s.Selected = s.Selected.
|
||||||
Foreground(lipgloss.Color("229")).
|
Foreground(lipgloss.Color("#494d64")).
|
||||||
Background(lipgloss.Color("57")).
|
Background(lipgloss.Color("#a6da95")).
|
||||||
Bold(false)
|
Bold(false)
|
||||||
tab.SetStyles(s)
|
tab.SetStyles(s)
|
||||||
|
tv.table = tab
|
||||||
|
|
||||||
tv := timesviewer{tab}
|
|
||||||
if _, err := tea.NewProgram(tv).Run(); err != nil {
|
if _, err := tea.NewProgram(tv).Run(); err != nil {
|
||||||
fmt.Println("Error running program:", err)
|
fmt.Println("Error running program:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user