internal/format/spinner.go 🔗
@@ -20,7 +20,7 @@ type Spinner struct {
type model struct {
cancel context.CancelFunc
- anim anim.Anim
+ anim anim.Spinner
}
func (m model) Init() tea.Cmd { return m.anim.Init() }
Carlos Alexandro Becker created
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
internal/format/spinner.go | 2 +-
internal/tui/components/anim/anim.go | 13 ++++++++++---
internal/tui/components/anim/static.go | 15 ++++-----------
internal/tui/components/chat/messages/messages.go | 2 +-
internal/tui/components/chat/messages/tool.go | 4 ++--
5 files changed, 18 insertions(+), 18 deletions(-)
@@ -20,7 +20,7 @@ type Spinner struct {
type model struct {
cancel context.CancelFunc
- anim anim.Anim
+ anim anim.Spinner
}
func (m model) Init() tea.Cmd { return m.anim.Init() }
@@ -97,7 +97,14 @@ type Settings struct {
Static bool
}
-// anim is a Bubble for an animated spinner.
+// Spinner is a Bubble for a spinner.
+type Spinner interface {
+ Init() tea.Cmd
+ Update(tea.Msg) (Spinner, tea.Cmd)
+ View() string
+ SetLabel(string)
+}
+
type anim struct {
width int
cyclingCharWidth int
@@ -116,7 +123,7 @@ type anim struct {
}
// New creates a new anim instance with the specified width and label.
-func New(opts Settings) Anim {
+func New(opts Settings) Spinner {
// Validate settings.
if opts.Size < 1 {
opts.Size = defaultNumCyclingChars
@@ -319,7 +326,7 @@ func (a *anim) Init() tea.Cmd {
}
// Update processes animation steps (or not).
-func (a *anim) Update(msg tea.Msg) (Anim, tea.Cmd) {
+func (a *anim) Update(msg tea.Msg) (Spinner, tea.Cmd) {
switch msg := msg.(type) {
case StepMsg:
if msg.id != a.id {
@@ -7,19 +7,12 @@ import (
"github.com/charmbracelet/lipgloss/v2"
)
-type Anim interface {
- Init() tea.Cmd
- Update(tea.Msg) (Anim, tea.Cmd)
- View() string
- SetLabel(string)
-}
-
type noAnim struct {
Color color.Color
rendered string
}
-func newStatic(label string, foreground color.Color) Anim {
+func newStatic(label string, foreground color.Color) Spinner {
a := &noAnim{Color: foreground}
a.SetLabel(label)
return a
@@ -29,6 +22,6 @@ func (s *noAnim) SetLabel(label string) {
s.rendered = lipgloss.NewStyle().Foreground(s.Color).Render(label + ellipsisFrames[2])
}
-func (s noAnim) Init() tea.Cmd { return nil }
-func (s *noAnim) Update(tea.Msg) (Anim, tea.Cmd) { return s, nil }
-func (s *noAnim) View() string { return s.rendered }
+func (s noAnim) Init() tea.Cmd { return nil }
+func (s *noAnim) Update(tea.Msg) (Spinner, tea.Cmd) { return s, nil }
+func (s *noAnim) View() string { return s.rendered }
@@ -54,7 +54,7 @@ type messageCmp struct {
// Core message data and state
message message.Message // The underlying message content
spinning bool // Whether to show loading animation
- anim anim.Anim // Animation component for loading states
+ anim anim.Spinner // Animation component for loading states
// Thinking viewport for displaying reasoning content
thinkingViewport viewport.Model
@@ -61,8 +61,8 @@ type toolCallCmp struct {
permissionGranted bool
// Animation state for pending tool calls
- spinning bool // Whether to show loading animation
- anim anim.Anim // Animation component for pending states
+ spinning bool // Whether to show loading animation
+ anim anim.Spinner // Animation component for pending states
nestedToolCalls []ToolCallCmp // Nested tool calls for hierarchical display
}