2024-10-31 06:37:50 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2024-11-13 08:43:58 +00:00
|
|
|
"fmt"
|
2024-10-31 06:37:50 +00:00
|
|
|
"strings"
|
|
|
|
|
2024-11-06 08:03:25 +00:00
|
|
|
"github.com/alecthomas/colour"
|
|
|
|
|
2024-10-31 06:37:50 +00:00
|
|
|
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
2024-11-13 08:43:58 +00:00
|
|
|
"github.com/charmbracelet/bubbles/progress"
|
2024-10-31 06:37:50 +00:00
|
|
|
)
|
|
|
|
|
2024-11-13 08:43:58 +00:00
|
|
|
var progressBar = progress.New(progress.WithDefaultGradient(), progress.WithoutPercentage())
|
|
|
|
|
2024-10-31 06:37:50 +00:00
|
|
|
func (a app) View() string {
|
|
|
|
var body string
|
2024-11-06 08:03:25 +00:00
|
|
|
var serverStatus string
|
2024-10-31 06:37:50 +00:00
|
|
|
|
2024-11-06 08:03:25 +00:00
|
|
|
body = "Waiting for server message..."
|
2024-10-31 06:37:50 +00:00
|
|
|
if a.pomodoro != (GoTomato.ServerMessage{}) {
|
2024-11-13 08:43:58 +00:00
|
|
|
body = terminalOutput(a.pomodoro)
|
|
|
|
desktopNotifications(a.pomodoro)
|
2024-11-06 08:03:25 +00:00
|
|
|
}
|
|
|
|
|
2024-11-13 16:17:39 +00:00
|
|
|
serverStatus = colour.Sprintf("^D^1%v^R\n", client.LastErr)
|
|
|
|
if client.Connected() && client.LastErr == nil {
|
2024-11-06 08:03:25 +00:00
|
|
|
serverStatus = colour.Sprintf("^D^2connected to %s^R\n", client.Server)
|
2024-10-31 06:37:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
helpView := a.help.View(a.keys)
|
2024-11-10 19:31:21 +00:00
|
|
|
height := 10 - strings.Count(body, "\n") - strings.Count(serverStatus, "\n") - strings.Count(helpView, "\n")
|
2024-10-31 06:37:50 +00:00
|
|
|
|
2024-11-06 08:03:25 +00:00
|
|
|
return body + strings.Repeat("\n", height) + serverStatus + helpView
|
2024-10-31 06:37:50 +00:00
|
|
|
}
|
2024-11-13 08:43:58 +00:00
|
|
|
|
|
|
|
// Return terminal output based on the passed ServerMessage
|
|
|
|
func terminalOutput(pomodoro GoTomato.ServerMessage) string {
|
|
|
|
var (
|
|
|
|
output string
|
|
|
|
|
|
|
|
modePrefix string
|
|
|
|
timerOutput string
|
|
|
|
)
|
|
|
|
|
|
|
|
// header
|
|
|
|
output += colour.Sprintf("^D^4Work: %d ◊ Break: %d ◊ Longbreak: %d^R\n\n",
|
|
|
|
pomodoro.Settings.Work/60,
|
|
|
|
pomodoro.Settings.ShortBreak/60,
|
|
|
|
pomodoro.Settings.LongBreak/60,
|
|
|
|
)
|
|
|
|
|
|
|
|
//body
|
|
|
|
switch pomodoro.Mode {
|
|
|
|
case "Idle":
|
|
|
|
modePrefix = " "
|
|
|
|
timerOutput = ""
|
|
|
|
default:
|
|
|
|
modePrefix = " "
|
|
|
|
if pomodoro.Paused {
|
|
|
|
modePrefix = " "
|
|
|
|
}
|
|
|
|
minutes := pomodoro.TimeLeft / 60
|
|
|
|
seconds := pomodoro.TimeLeft % 60
|
|
|
|
|
|
|
|
timerOutput = fmt.Sprintf("⏱ %02d:%02d", minutes, seconds) + "\n"
|
|
|
|
timerOutput += progressBar.ViewAs(calc_percentage(pomodoro))
|
|
|
|
}
|
|
|
|
|
|
|
|
output += fmt.Sprintf("Session: %d/%d\n",
|
|
|
|
pomodoro.Session,
|
|
|
|
pomodoro.Settings.Sessions,
|
|
|
|
)
|
|
|
|
output += fmt.Sprintf("%s %s\n", modePrefix, pomodoro.Mode) + "\n"
|
|
|
|
output += timerOutput
|
|
|
|
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
|
|
|
func calc_percentage(message GoTomato.ServerMessage) float64 {
|
|
|
|
var duration float64
|
|
|
|
|
|
|
|
switch message.Mode {
|
|
|
|
case "Work":
|
|
|
|
duration = float64(message.Settings.Work)
|
|
|
|
case "ShortBreak":
|
|
|
|
duration = float64(message.Settings.ShortBreak)
|
|
|
|
case "LongBreak", "End":
|
|
|
|
duration = float64(message.Settings.LongBreak)
|
|
|
|
}
|
|
|
|
|
|
|
|
timeLeft := float64(message.TimeLeft)
|
|
|
|
return 1.0 - (timeLeft / duration)
|
|
|
|
}
|