diff --git a/indicator.go b/indicator.go index 0d2b9cb..f286002 100644 --- a/indicator.go +++ b/indicator.go @@ -44,6 +44,14 @@ func (m Indicator) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case error: m.err = msg return m, nil + case tea.KeyMsg: + switch msg.String() { + case "ctrl+c", "q": + m.quitting = true + return m, tea.Quit + default: + return m, nil + } case IndicatorInfo: m.info = msg m.quitting = msg.quitting diff --git a/times.go b/times.go index d3dd419..362da7a 100644 --- a/times.go +++ b/times.go @@ -14,15 +14,19 @@ import ( ) func times() { + finished := false p := tea.NewProgram(initialIndicator("Fetching time logs...")) go func() { if _, err := p.Run(); err != nil { fmt.Println(err) + } + // If the indicator exited before we got all the time logs, it was either an error or the user press CTRL + C / q + if !finished { os.Exit(1) } }() - since := time.Now().AddDate(0, -6, 0) + since := time.Now().AddDate(0, -1, 0) times := getTimeLogs(since, func(repo gitea.Repository, took time.Duration) { p.Send(IndicatorInfo{ info: fmt.Sprintf("%s / %s", repo.Owner.UserName, repo.Name), @@ -33,6 +37,7 @@ func times() { info: "Done!", quitting: true, }) + finished = true p.Quit() var total_time time.Duration