feat: use bubbletea framework

- implement TUI in bubbletea
  - split components into separate files
- remove now unused functions
- restructure files
This commit is contained in:
Sebastian Mark 2024-10-31 07:37:50 +01:00
parent 9656db5335
commit 8a0ef32c91
14 changed files with 269 additions and 187 deletions

45
cmd/client/update.go Normal file
View file

@ -0,0 +1,45 @@
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
}