summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-25 23:19:54 +0300
committerPaul Buetow <paul@buetow.org>2025-06-25 23:19:54 +0300
commit0442a28b352d2374f5702c00f682071476439c27 (patch)
treeda7eda2883411008f0c9384322c865696a9992eb
parent2e74f80bdb12ac5cb9c9e30e9878bb594c03e5df (diff)
feat: Improve live view with large ASCII timer
-rw-r--r--go.mod1
-rw-r--r--go.sum2
-rw-r--r--internal/live/live.go33
3 files changed, 30 insertions, 6 deletions
diff --git a/go.mod b/go.mod
index dca39aa..b77964f 100644
--- a/go.mod
+++ b/go.mod
@@ -11,6 +11,7 @@ require (
github.com/charmbracelet/x/ansi v0.8.0 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
+ github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
diff --git a/go.sum b/go.sum
index e883d4e..f2bb186 100644
--- a/go.sum
+++ b/go.sum
@@ -14,6 +14,8 @@ github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0G
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
+github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be h1:J5BL2kskAlV9ckgEsNQXscjIaLiOYiZ75d4e94E6dcQ=
+github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
diff --git a/internal/live/live.go b/internal/live/live.go
index 300e0dc..ff214f7 100644
--- a/internal/live/live.go
+++ b/internal/live/live.go
@@ -1,11 +1,11 @@
package live
import (
- "fmt"
"time"
"github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
+ "github.com/common-nighthawk/go-figure"
timrTimer "timr/internal/timer"
)
@@ -24,6 +24,8 @@ type Model struct {
helpStyle lipgloss.Style
timerStyle lipgloss.Style
statusStyle lipgloss.Style
+ width int
+ height int
}
// NewModel creates a new Model.
@@ -52,6 +54,10 @@ func (m Model) Init() tea.Cmd {
// Update is called when a message is received.
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
+ case tea.WindowSizeMsg:
+ m.width = msg.Width
+ m.height = msg.Height
+ return m, nil
case tickMsg:
if !m.state.Running {
return m, nil
@@ -111,10 +117,25 @@ func (m Model) View() string {
status = "Running"
}
- return fmt.Sprintf(
- "%s\n%s\n\n%s",
- m.timerStyle.Render(totalElapsed.String()),
- m.statusStyle.Render(status),
- m.helpStyle.Render("q: quit, s: start/stop, r: reset"),
+ // Large timer text
+ figure := figure.NewFigure(totalElapsed.String(), "doom", true)
+ timerStr := m.timerStyle.Render(figure.String())
+
+ statusStr := m.statusStyle.Render(status)
+ helpStr := m.helpStyle.Render("q: quit, s: start/stop, r: reset")
+
+ // Centering
+ return lipgloss.Place(
+ m.width,
+ m.height,
+ lipgloss.Center,
+ lipgloss.Center,
+ lipgloss.JoinVertical(
+ lipgloss.Center,
+ timerStr,
+ statusStr,
+ "", // spacer
+ helpStr,
+ ),
)
}