feat: use bubbletea framework
- implement TUI in bubbletea - split components into separate files - remove now unused functions - restructure files
This commit is contained in:
parent
9656db5335
commit
8a0ef32c91
14 changed files with 269 additions and 187 deletions
45
cmd/client/update.go
Normal file
45
cmd/client/update.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue