loadingbar

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 7 Imported by: 0

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

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 New

func New(width int) Model

New returns an idle Model with an 80ms interval and a width-wide track.

func (Model) LayoutNode

func (m Model) LayoutNode() layout.Node

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

func (m Model) Linearize() string

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) Running

func (m Model) Running() bool

Running reports whether the animation is currently running.

func (Model) SetTheme

func (m Model) SetTheme(t theme.Theme) Model

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

func (m *Model) Start() tui.Cmd

Start begins the animation; return the Cmd it produces from your own Init or Update.

func (*Model) Stop

func (m *Model) Stop()

Stop ends the animation without resetting its position.

func (Model) Tokens

func (m Model) Tokens() theme.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

func (m Model) Update(msg tui.Msg) (Model, tui.Cmd)

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.

func (Model) View

func (m Model) View() string

View renders the track with the moving segment at its current position.

func (Model) WithTokens

func (m Model) WithTokens(tok theme.Tokens) Model

WithTokens returns m with tok as its per-instance colour override. Nil fields inherit from the theme, so only the roles tok names change; the theme and every other widget are untouched. A second call replaces the first.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL