Documentation
¶
Overview ¶
Package loadingbar is an indeterminate progress animation — InkUI's "LoadingBar": a segment sliding back and forth across a fixed-width track, distinct from widgets.ProgressBar's determinate fill.
Example ¶
An indeterminate bar of fixed width; Start returns the Cmd that animates it.
package main
import (
"fmt"
"github.com/ows4444/tui/ansi"
"github.com/ows4444/tui/loadingbar"
)
func main() {
m := loadingbar.New(12)
fmt.Println(m.Running(), ansi.Width(m.View()))
_ = m.Start()
fmt.Println(m.Running())
}
Output: false 12 true
Index ¶
- type Model
- func (m Model) LayoutNode() layout.Node
- func (m Model) Linearize() string
- func (m Model) Running() bool
- func (m Model) SetTheme(t theme.Theme) Model
- func (m *Model) Start() tui.Cmd
- func (m *Model) Stop()
- func (m Model) Tokens() theme.Tokens
- func (m Model) Update(msg tui.Msg) (Model, tui.Cmd)
- func (m Model) View() string
- func (m Model) WithTokens(tok theme.Tokens) Model
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Model ¶
type Model struct {
Width int
Interval time.Duration
Theme theme.Theme
// Motion is the reduced-motion preference. The zero value is
// motion.Normal, the behaviour before this field existed. With
// motion.Reduced, Start schedules no tick, so the segment stays at its start.
Motion motion.Preference
// Clock, if set, drives the animation: the widget renders from the
// shared Clock's frame and schedules no tick of its own (Start returns
// nil; start the Clock instead). Nil keeps the per-widget tick.
Clock *motion.Clock
// contains filtered or unexported fields
}
Model animates a segment bouncing across a Width-wide track. Like spinner.Model, it uses a self-rescheduling motion tick: Stop needs no explicit cancellation, since a tick that arrives after Stop just doesn't reschedule another one.
func (Model) LayoutNode ¶
LayoutNode adapts the bar to a layout.Node. Measure reports its own Width by one row; Render draws the bar across the allotted width, using it in place of Width (rows beyond the first are blank). The Model is not changed.
func (Model) Linearize ¶
Linearize renders the indeterminate bar as plain text for accessible output (see tui.Linearizer): "Loading, in progress" while running, "Loading, stopped" otherwise. The sliding segment carries no information a screen reader could use. A zero-width bar reads as "".
func (Model) SetTheme ¶
SetTheme returns m with t applied. It makes Model a tui.ThemeSetter, so a root model can forward the Program's theme (see tui.WithTheme).
func (*Model) Start ¶
Start begins the animation; return the Cmd it produces from your own Init or Update.
func (Model) Tokens ¶
Tokens returns the colour tokens the widget renders with: its theme's roles, overridden by any theme.WithTokens(theme.ComponentLoadingBar, ...) and then by WithTokens.
func (Model) Update ¶
Update advances the segment one step and bounces it off either end of the track; a no-op for any Msg but its own tick, or while stopped.