ChronoTomato/cmd/client/view.go
Sebastian Mark 9c4d43a4d3 feat: reconnect on disconnect (status in TUI)
- add `Connected()` method for client
- add `LastErr` field to GoTomatoClient
  - replace error logging by updating `LastErr` field
  - modify methods to use pointer receivers for Client
- add `prevMessage` variable to store the last received server message
- show connect status in TUI
- use EnterAltScreen instead of ClearScreen
2024-11-07 20:13:25 +01:00

31 lines
826 B
Go

package client
import (
"strings"
"github.com/alecthomas/colour"
"git.smsvc.net/pomodoro/ChronoTomato/cmd/client/helper"
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
)
func (a app) View() string {
var body string
var serverStatus string
body = "Waiting for server message..."
if a.pomodoro != (GoTomato.ServerMessage{}) {
body = helper.TerminalOutput(a.pomodoro)
helper.DesktopNotifications(a.pomodoro)
}
serverStatus = colour.Sprintf("^D^1disconnected: %v^R\n", client.LastErr)
if client.Connected() {
serverStatus = colour.Sprintf("^D^2connected to %s^R\n", client.Server)
}
helpView := a.help.View(a.keys)
height := 8 - strings.Count(body, "\n") - strings.Count(serverStatus, "\n") - strings.Count(helpView, "\n")
return body + strings.Repeat("\n", height) + serverStatus + helpView
}