Documentation
¶
Overview ¶
Package skeleton is a loading placeholder block — InkUI's "Skeleton".
Example ¶
A skeleton is a placeholder shown while content loads; Start animates it.
package main
import (
"fmt"
"github.com/ows4444/tui/skeleton"
)
func main() {
m := skeleton.New()
fmt.Println(m.Running())
_ = m.Start()
fmt.Println(m.Running())
}
Output: false 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
Lines int
Theme theme.Theme
Interval time.Duration
// 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 shimmer stays put.
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 renders Lines rows of Width placeholder cells, with a shimmer highlight that sweeps across each row while running. It uses the same self-rescheduling motion tick pattern spinner.Model does: each tick's Cmd only reschedules itself while still running, so Stop needs no explicit cancellation — a tick that arrives after Stop just doesn't reschedule another one.
func (Model) LayoutNode ¶
LayoutNode adapts the skeleton to a layout.Node. Measure reports its own Width by Lines; Render fills exactly the allotted Size, using it in place of Width and Lines, at the current shimmer frame. The Model is not changed.
func (Model) Linearize ¶
Linearize renders the placeholder as plain text for accessible output (see tui.Linearizer): "Loading placeholder" for a visible skeleton, "" for one with no size. The shimmer animation is not spoken.
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 shimmer animation; return the Cmd it produces from your own Init or Update so it actually runs. Call it on the model your program keeps: in an Init with a value receiver it would run on a copy, and the kept model would ignore the ticks. Start where the model is built and have Init return that Cmd.
func (Model) Tokens ¶
Tokens returns the colour tokens the widget renders with: its theme's roles, overridden by any theme.WithTokens(theme.ComponentSkeleton, ...) and then by WithTokens.
func (Model) Update ¶
Update advances the shimmer by one frame; a no-op for any Msg but its own tick, another Model's tick included, or while stopped.
func (Model) View ¶
View renders Lines rows, each exactly Width cells wide (measured with ansi.Width), filled with fillRune and styled with the Theme's Muted color, except for a shimmerWidth-wide highlighted span whose column position is a function of m.frame — so consecutive frames sweep the highlight across the row. Width <= 0 or Lines <= 0 renders "" without panicking.