doc: add and improve comments
This commit is contained in:
parent
6187122b81
commit
f19ab81dc8
11 changed files with 31 additions and 8 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
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"
|
||||
|
@ -20,7 +21,8 @@ func start_pause_resume(message GoTomato.ServerMessage) string {
|
|||
}
|
||||
}
|
||||
|
||||
func keyhandler(key keyboard.KeyEvent, client websocket.Client, config ChronoTomato.Config, message GoTomato.ServerMessage) bool {
|
||||
// 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)
|
||||
|
|
|
@ -9,22 +9,27 @@ import (
|
|||
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
)
|
||||
|
||||
// Update the terminal and send desktop notifications until the websocket if closed or "quit"
|
||||
func UpdateLoop(client websocket.Client, config ChronoTomato.Config, channel <-chan GoTomato.ServerMessage) {
|
||||
var message GoTomato.ServerMessage
|
||||
|
||||
// listen for key events
|
||||
keysEvents, _ := keyboard.GetKeys(1)
|
||||
defer keyboard.Close()
|
||||
|
||||
for {
|
||||
select {
|
||||
case message = <-channel:
|
||||
// for every received message
|
||||
desktopNotifications(message)
|
||||
terminalOutput(message)
|
||||
case keypress := <-keysEvents:
|
||||
if !keyhandler(keypress, client, config, message) {
|
||||
// react to key pressed
|
||||
if !menuHandler(keypress, client, config, message) {
|
||||
return
|
||||
}
|
||||
case <-websocket.Done:
|
||||
// connection closed
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
)
|
||||
|
||||
// Send desktop notifications on the start of each segment
|
||||
func desktopNotifications(pomodoro GoTomato.ServerMessage) {
|
||||
|
||||
var (
|
||||
duration int
|
||||
notification string
|
||||
|
|
|
@ -8,13 +8,15 @@ import (
|
|||
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
)
|
||||
|
||||
// Update the terminal output based on the passed ServerMessage
|
||||
func terminalOutput(pomodoro GoTomato.ServerMessage) {
|
||||
var (
|
||||
modePrefix string
|
||||
timerOutput string
|
||||
)
|
||||
|
||||
fmt.Print("\033[H\033[2J") // Clears the screen
|
||||
// Clear the screen
|
||||
fmt.Print("\033[H\033[2J")
|
||||
|
||||
// header
|
||||
color.Blue("Work: %d ◊ Break: %d ◊ Longbreak: %d\n\n",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue