shimmer

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package shimmer provides shimmer animation rendering for clog.

Index

Constants

View Source
const (
	// Speed is the number of full gradient cycles per second.
	Speed = 0.5

	// TickRate is the repaint interval when shimmer is active (~30fps).
	TickRate = 33 * time.Millisecond
)

Variables

This section is empty.

Functions

func DefaultGradient

func DefaultGradient() []gradient.ColorStop

DefaultGradient returns a wave-shaped gradient for shimmer effects: a subtle red-to-green-to-blue cycle that wraps seamlessly.

func Text

func Text(
	text string,
	phase float64,
	dir Direction,
	lut *LUT,
	styleLUT *StyleLUT,
) string

Text renders each character of text with a gradient-interpolated foreground color, creating an animated shimmer when called with advancing phase values. Spaces are passed through unstyled. The caller must supply a pre-built LUT from BuildLUT. Passing a pre-built StyleLUT from BuildStyleLUT eliminates per-frame style allocations; pass nil to create styles on the fly.

Types

type Config added in v0.11.0

type Config struct {
	Direction Direction
	Gradient  []gradient.ColorStop
	Speed     float64
}

Config holds resolved shimmer configuration.

func Apply added in v0.11.0

func Apply(opts ...Option) Config

Apply returns a copy of DefaultConfig with all opts applied in order.

func DefaultConfig added in v0.11.0

func DefaultConfig() Config

DefaultConfig returns the default shimmer configuration.

type Direction

type Direction int

Direction controls which way an animation travels.

const (
	// Right moves the shimmer wave from left to right (default).
	Right Direction = iota
	// Left moves the shimmer wave from right to left.
	Left
	// MiddleIn sends the shimmer wave inward from both edges.
	MiddleIn
	// MiddleOut sends the shimmer wave outward from the center.
	MiddleOut
	// BounceIn sends the shimmer wave inward from both edges, then
	// bounces it back outward, creating a ping-pong effect.
	BounceIn
	// BounceOut sends the shimmer wave outward from the center, then
	// bounces it back inward, creating a ping-pong effect.
	BounceOut
)

type LUT

type LUT [lutSize]string

LUT is a pre-computed gradient lookup table of hex color strings.

func BuildLUT

func BuildLUT(stops []gradient.ColorStop) *LUT

BuildLUT pre-computes a gradient lookup table of hex color strings from the given color stops.

type Option

type Option func(*Config)

Option configures a Config.

func WithDirection

func WithDirection(d Direction) Option

WithDirection sets the direction the shimmer wave travels.

func WithGradient

func WithGradient(stops ...gradient.ColorStop) Option

WithGradient sets custom gradient color stops.

func WithSpeed

func WithSpeed(speed float64) Option

WithSpeed sets the number of full gradient cycles per second. Values <= 0 are a no-op (keep default).

type StyleLUT

type StyleLUT [lutSize]lipgloss.Style

StyleLUT is a pre-computed lookup table of lipgloss styles, built from a LUT. Reusing styles across frames eliminates per-frame style allocations entirely.

func BuildStyleLUT

func BuildStyleLUT(lut *LUT) *StyleLUT

BuildStyleLUT pre-computes a lipgloss style for every entry in the hex LUT. Call once after BuildLUT and pass the result to Text to avoid style allocations in the render loop.

Jump to

Keyboard shortcuts

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