Compare commits
No commits in common. "21edd2d823080771eff13c885f6e1d71d6cfbbe2" and "c30829392d8ee387929057ed9ed3b871f680ffc5" have entirely different histories.
21edd2d823
...
c30829392d
6 changed files with 59 additions and 81 deletions
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Send desktop notifications on the start of each segment
|
// Send desktop notifications on the start of each segment
|
||||||
func desktopNotifications(pomodoro GoTomato.ServerMessage) {
|
func DesktopNotifications(pomodoro GoTomato.ServerMessage) {
|
||||||
var (
|
var (
|
||||||
duration int
|
duration int
|
||||||
notification string
|
notification string
|
51
cmd/client/helper/terminal.go
Normal file
51
cmd/client/helper/terminal.go
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/alecthomas/colour"
|
||||||
|
|
||||||
|
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
output += fmt.Sprintf("Session: %d/%d\n",
|
||||||
|
pomodoro.Session,
|
||||||
|
pomodoro.Settings.Sessions,
|
||||||
|
)
|
||||||
|
output += fmt.Sprintf("%s %s\n", modePrefix, pomodoro.Mode)
|
||||||
|
output += fmt.Sprintf(timerOutput)
|
||||||
|
|
||||||
|
return output
|
||||||
|
}
|
|
@ -1,93 +1,31 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/alecthomas/colour"
|
"github.com/alecthomas/colour"
|
||||||
|
|
||||||
|
"git.smsvc.net/pomodoro/ChronoTomato/cmd/client/helper"
|
||||||
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||||
"github.com/charmbracelet/bubbles/progress"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var progressBar = progress.New(progress.WithDefaultGradient(), progress.WithoutPercentage())
|
|
||||||
|
|
||||||
func (a app) View() string {
|
func (a app) View() string {
|
||||||
var body string
|
var body string
|
||||||
var serverStatus string
|
var serverStatus string
|
||||||
|
|
||||||
body = "Waiting for server message..."
|
body = "Waiting for server message..."
|
||||||
if a.pomodoro != (GoTomato.ServerMessage{}) {
|
if a.pomodoro != (GoTomato.ServerMessage{}) {
|
||||||
body = terminalOutput(a.pomodoro)
|
body = helper.TerminalOutput(a.pomodoro)
|
||||||
desktopNotifications(a.pomodoro)
|
helper.DesktopNotifications(a.pomodoro)
|
||||||
}
|
}
|
||||||
|
|
||||||
serverStatus = colour.Sprintf("^D^1%v^R\n", client.LastErr)
|
serverStatus = colour.Sprintf("^D^1disconnected: %v^R\n", client.LastErr)
|
||||||
if client.Connected() && client.LastErr == nil {
|
if client.Connected() {
|
||||||
serverStatus = colour.Sprintf("^D^2connected to %s^R\n", client.Server)
|
serverStatus = colour.Sprintf("^D^2connected to %s^R\n", client.Server)
|
||||||
}
|
}
|
||||||
|
|
||||||
helpView := a.help.View(a.keys)
|
helpView := a.help.View(a.keys)
|
||||||
height := 10 - strings.Count(body, "\n") - strings.Count(serverStatus, "\n") - strings.Count(helpView, "\n")
|
height := 8 - strings.Count(body, "\n") - strings.Count(serverStatus, "\n") - strings.Count(helpView, "\n")
|
||||||
|
|
||||||
return body + strings.Repeat("\n", height) + serverStatus + helpView
|
return body + strings.Repeat("\n", height) + serverStatus + helpView
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -15,7 +15,6 @@ require (
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||||
github.com/charmbracelet/harmonica v0.2.0 // indirect
|
|
||||||
github.com/charmbracelet/lipgloss v1.0.0 // indirect
|
github.com/charmbracelet/lipgloss v1.0.0 // indirect
|
||||||
github.com/charmbracelet/x/ansi v0.4.5 // indirect
|
github.com/charmbracelet/x/ansi v0.4.5 // indirect
|
||||||
github.com/charmbracelet/x/term v0.2.0 // indirect
|
github.com/charmbracelet/x/term v0.2.0 // indirect
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -8,8 +8,6 @@ github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQW
|
||||||
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
|
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
|
||||||
github.com/charmbracelet/bubbletea v1.2.1 h1:J041h57zculJKEKf/O2pS4edXGIz+V0YvojvfGXePIk=
|
github.com/charmbracelet/bubbletea v1.2.1 h1:J041h57zculJKEKf/O2pS4edXGIz+V0YvojvfGXePIk=
|
||||||
github.com/charmbracelet/bubbletea v1.2.1/go.mod h1:viLoDL7hG4njLJSKU2gw7kB3LSEmWsrM80rO1dBJWBI=
|
github.com/charmbracelet/bubbletea v1.2.1/go.mod h1:viLoDL7hG4njLJSKU2gw7kB3LSEmWsrM80rO1dBJWBI=
|
||||||
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
|
|
||||||
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
|
|
||||||
github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
|
github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
|
||||||
github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo=
|
github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo=
|
||||||
github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM=
|
github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM=
|
||||||
|
|
|
@ -19,7 +19,6 @@ func (c *Client) ProcessServerMessages(channel chan<- GoTomato.ServerMessage) {
|
||||||
defer close(Done)
|
defer close(Done)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
c.Conn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
|
||||||
_, message, err := c.Conn.ReadMessage()
|
_, message, err := c.Conn.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// On normal closure exit gracefully
|
// On normal closure exit gracefully
|
||||||
|
@ -27,18 +26,11 @@ func (c *Client) ProcessServerMessages(channel chan<- GoTomato.ServerMessage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.LastErr = err
|
|
||||||
// Try to reconnect on unexpected disconnect
|
// Try to reconnect on unexpected disconnect
|
||||||
for {
|
for {
|
||||||
channel <- prevMessage // send previous ServerMessage to update view
|
channel <- prevMessage // send previous ServerMessage to update view
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
// reconnect while preserving password
|
|
||||||
pw := c.Password
|
|
||||||
*c = Connect(c.Server)
|
*c = Connect(c.Server)
|
||||||
c.Password = pw
|
|
||||||
|
|
||||||
if c.Connected() {
|
if c.Connected() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue