Documentation
¶
Overview ¶
Package animation provides centralized animation tick management for the TUI. All animated components (spinners, fades, etc.) share a single tick stream to avoid tick storms and ensure synchronized animations.
Thread safety: All exported functions are safe for concurrent use, though the typical usage pattern is single-threaded via Bubble Tea's Update loop.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasActive ¶
func HasActive() bool
HasActive returns true if any animations are currently active.
func Register ¶
func Register()
Register increments the active animation count. Call this when an animation starts.
func StartTick ¶
StartTick starts the global animation tick if any animations are active. Call this after processing a TickMsg to continue the tick stream.
func StartTickIfFirst ¶
StartTickIfFirst registers an animation and starts the tick if this is the first. This is atomic: no race between checking and registering. Returns the tick command if the tick stream was started, nil otherwise.
func Unregister ¶
func Unregister()
Unregister decrements the active animation count. Call this when an animation stops.
Types ¶
type Coordinator ¶
type Coordinator struct {
// contains filtered or unexported fields
}
Coordinator manages a single tick stream for all animations. It tracks active animations and only generates ticks when at least one is active.
type Subscription ¶ added in v1.20.1
type Subscription struct {
// contains filtered or unexported fields
}
Subscription represents a component's subscription to animation ticks. It encapsulates the registration/unregistration lifecycle, making it easier to manage animation state correctly.
Usage:
type MyComponent struct {
animSub animation.Subscription
}
func (m *MyComponent) Init() tea.Cmd {
return m.animSub.Start()
}
func (m *MyComponent) Cleanup() {
m.animSub.Stop()
}
func (*Subscription) IsActive ¶ added in v1.20.1
func (s *Subscription) IsActive() bool
IsActive returns whether the subscription is currently active.
func (*Subscription) Reset ¶ added in v1.20.1
func (s *Subscription) Reset() Subscription
Reset returns a new inactive subscription. Useful when recreating a component that needs fresh animation state.
func (*Subscription) Start ¶ added in v1.20.1
func (s *Subscription) Start() tea.Cmd
Start activates the subscription if not already active. Returns a command to start the tick if this is the first subscription. Safe to call multiple times - only the first call registers.
func (*Subscription) Stop ¶ added in v1.20.1
func (s *Subscription) Stop()
Stop deactivates the subscription if currently active. Safe to call multiple times - only the first call unregisters.