From e9f79b011e4075bb76fabfe8113d151eaedd01c7 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Wed, 2 Jul 2025 14:32:00 -0400 Subject: [PATCH] fix: don't render periods of ellipsis when there's no label --- internal/tui/components/anim/anim.go | 38 +++++++++++++++------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/internal/tui/components/anim/anim.go b/internal/tui/components/anim/anim.go index 9fa8e6f724435541839b29cdfe2cb47f6d2ca35a..712fe1555b4b0d5a891f8412acbeede5e68c1e40 100644 --- a/internal/tui/components/anim/anim.go +++ b/internal/tui/components/anim/anim.go @@ -83,14 +83,24 @@ func New(numChars int, label string, t *styles.Theme) (a Anim) { a.width += labelGapWidth + lipgloss.Width(label) } - // Pre-render the label. - // XXX: We should really get the graphemes for the label, not the runes. - labelRunes := []rune(label) - a.label = make([]string, len(labelRunes)) - for i := range a.label { - a.label[i] = lipgloss.NewStyle(). - Foreground(t.FgBase). - Render(string(labelRunes[i])) + if a.labelWidth > 0 { + // Pre-render the label. + // XXX: We should really get the graphemes for the label, not the runes. + labelRunes := []rune(label) + a.label = make([]string, len(labelRunes)) + for i := range a.label { + a.label[i] = lipgloss.NewStyle(). + Foreground(t.FgBase). + Render(string(labelRunes[i])) + } + + // Pre-render the ellipsis frames which come after the label. + a.ellipsisFrames = make([]string, len(ellipsisFrames)) + for i, frame := range ellipsisFrames { + a.ellipsisFrames[i] = lipgloss.NewStyle(). + Foreground(t.FgBase). + Render(frame) + } } // Pre-generate gradient. @@ -104,14 +114,6 @@ func New(numChars int, label string, t *styles.Theme) (a Anim) { Render(string(initialChar)) } - // Pre-render the ellipsis frames. - a.ellipsisFrames = make([]string, len(ellipsisFrames)) - for i, frame := range ellipsisFrames { - a.ellipsisFrames[i] = lipgloss.NewStyle(). - Foreground(t.FgBase). - Render(frame) - } - // Prerender scrambled rune frames for the animation. a.cyclingFrames = make([][]string, prerenderedFrames) for i := range a.cyclingFrames { @@ -154,7 +156,7 @@ func (a Anim) Update(msg tea.Msg) (tea.Model, tea.Cmd) { a.step = 0 } - if a.initialized { + if a.initialized && a.labelWidth > 0 { // Manage the ellipsis animation. a.ellipsisStep++ if a.ellipsisStep >= ellipsisAnimSpeed*len(ellipsisFrames) { @@ -190,7 +192,7 @@ func (a Anim) View() tea.View { } // Render animated ellipsis at the end of the label if all characters // have been initialized. - if a.initialized { + if a.initialized && a.labelWidth > 0 { b.WriteString(a.ellipsisFrames[a.ellipsisStep/ellipsisAnimSpeed]) } return tea.NewView(b.String())