From 2528fbe9ebc249c020ebdfd68765f893407fd8a7 Mon Sep 17 00:00:00 2001 From: Noah Date: Sun, 7 Apr 2024 14:18:21 -0500 Subject: [PATCH] feat(summary): Quit out of program when user interrupts loading indicator (fix #21) --- summary.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/summary.go b/summary.go index f8faa19..8c82598 100644 --- a/summary.go +++ b/summary.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "os" "time" "code.gitea.io/sdk/gitea" @@ -41,10 +42,14 @@ func (m summaryviewer) View() string { } func summary() { + finished := false p := tea.NewProgram(initialIndicator(("Fetching time logs..."))) go func() { 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)) } + finished = true p.Send(IndicatorInfo{info: "Done", quitting: true}) - p.RestoreTerminal() p.Quit() + p.Wait() program := tea.NewProgram(viewer) if _, err := program.Run(); err != nil {