skeleton

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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 New

func New() Model

New returns an idle Model at a 100ms interval using theme.DarkTheme().

func (Model) LayoutNode

func (m Model) LayoutNode() layout.Node

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

func (m Model) Linearize() string

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

func (m *Model) Stop()

Stop ends the animation without resetting its frame.

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.ComponentSkeleton, ...) and then by WithTokens.

func (Model) Update

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

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

func (m Model) View() string

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.

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