40 lines
984 B
Go
40 lines
984 B
Go
package frontend
|
|
|
|
import (
|
|
"github.com/eiannone/keyboard"
|
|
|
|
"git.smsvc.net/pomodoro/ChronoTomato/internal/websocket"
|
|
|
|
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
|
|
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
|
)
|
|
|
|
// 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"
|
|
}
|
|
}
|
|
|
|
// reads a KeyEvent and sends the matching command
|
|
func menuHandler(key keyboard.KeyEvent, client websocket.Client, config ChronoTomato.Config, message GoTomato.ServerMessage) bool {
|
|
switch key.Rune {
|
|
case 0: // space
|
|
cmd := start_pause_resume(message)
|
|
client.SendCmd(cmd)
|
|
case 115: // s
|
|
client.SendCmd("stop")
|
|
case 114: // r
|
|
if config.PomodoroConfig != (GoTomato.PomodoroConfig{}) {
|
|
client.SendSettingsUpdate(config.PomodoroConfig)
|
|
}
|
|
case 113: // q
|
|
return false
|
|
}
|
|
return true
|
|
}
|