ChronoTomato/cmd/client/update.go
Sebastian Mark 8a0ef32c91 feat: use bubbletea framework
- implement TUI in bubbletea
  - split components into separate files
- remove now unused functions
- restructure files
2024-11-02 10:55:15 +01:00

45 lines
1 KiB
Go

package client
import (
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
)
// sends start/pause/resume based on the state of the pomodoro
func start_pause_resume(message GoTomato.ServerMessage) string {
if !message.Ongoing {
return "start"
}
if message.Paused {
return "resume"
} else {
return "pause"
}
}
func (a app) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case GoTomato.ServerMessage:
a.pomodoro = msg
return a, a.waitForChannelSignal()
case tea.KeyMsg:
switch {
case key.Matches(msg, a.keys.Start):
cmd := start_pause_resume(a.pomodoro)
client.SendCmd(cmd)
case key.Matches(msg, a.keys.Stop):
client.SendCmd("stop")
case key.Matches(msg, a.keys.Reset):
if config.PomodoroConfig != (GoTomato.PomodoroConfig{}) {
client.SendSettingsUpdate(config.PomodoroConfig)
}
case key.Matches(msg, a.keys.Quit):
client.Disconnect()
return a, tea.Quit
}
}
return a, nil
}