feat(summary): Quit out of program when user interrupts loading indicator (fix #21)

This commit is contained in:
Noah 2024-04-07 14:18:21 -05:00
parent d434ff273b
commit 2528fbe9eb

View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"os"
"time" "time"
"code.gitea.io/sdk/gitea" "code.gitea.io/sdk/gitea"
@ -41,10 +42,14 @@ func (m summaryviewer) View() string {
} }
func summary() { func summary() {
finished := false
p := tea.NewProgram(initialIndicator(("Fetching time logs..."))) p := tea.NewProgram(initialIndicator(("Fetching time logs...")))
go func() { go func() {
if _, err := p.Run(); err != nil { if _, err := p.Run(); err != nil {
panic("An error occured.") fmt.Println(err)
}
if !finished {
os.Exit(1)
} }
}() }()
@ -61,9 +66,10 @@ func summary() {
viewer.total_time += time.Duration(t.Time * int64(time.Second)) viewer.total_time += time.Duration(t.Time * int64(time.Second))
} }
finished = true
p.Send(IndicatorInfo{info: "Done", quitting: true}) p.Send(IndicatorInfo{info: "Done", quitting: true})
p.RestoreTerminal()
p.Quit() p.Quit()
p.Wait()
program := tea.NewProgram(viewer) program := tea.NewProgram(viewer)
if _, err := program.Run(); err != nil { if _, err := program.Run(); err != nil {