feat(times): Allow user to quit out of an Indicator
Let user press "CTRL+C" or "q" to quit out of the program while fetching time logs (fix #12)
This commit is contained in:
parent
3a0ff257f7
commit
2a8f2e46d3
@ -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
|
||||
|
7
times.go
7
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
|
||||
|
Loading…
Reference in New Issue
Block a user