Module spinner

Source
Expand description

Spinner component for Bubble Tea applications.

This module provides a spinner component for Bubble Tea applications. It closely matches the API of the Go bubbles spinner component for 1-1 compatibility.

§Basic Usage

use bubbletea_widgets::spinner::{new, with_spinner, with_style, DOT};
use lipgloss::Style;

// Create a spinner with default settings
let spinner = new(&[]);

// Create a spinner with custom settings using the option pattern
let spinner = new(&[
    with_spinner(DOT.clone()),
    with_style(Style::new().foreground(lipgloss::Color::from("red"))),
]);

§Available Spinners

The following predefined spinners are available as constants (matching Go exactly):

  • LINE: Basic line spinner (|, /, -, )
  • DOT: Braille dot pattern spinner
  • MINI_DOT: Smaller braille dot pattern
  • JUMP: Jumping dot animation
  • PULSE: Block fade animation (█, ▓, ▒, ░)
  • POINTS: Three dot bounce animation
  • GLOBE: Earth emoji rotation
  • MOON: Moon phase animation
  • MONKEY: See-no-evil monkey sequence
  • METER: Progress bar style animation
  • HAMBURGER: Trigram symbol animation
  • ELLIPSIS: Text ellipsis animation (“”, “.”, “..”, “…”)

§bubbletea-rs Integration

use bubbletea_rs::{Model as BubbleTeaModel, Msg, Cmd};
use bubbletea_widgets::spinner::{new, with_spinner, DOT, TickMsg};

struct MyApp {
    spinner: bubbletea_widgets::spinner::Model,
}

impl BubbleTeaModel for MyApp {
    fn init() -> (Self, Option<Cmd>) {
        let spinner = new(&[with_spinner(DOT.clone())]);
        // Spinners start automatically when created
        (Self { spinner }, None)
    }

    fn update(&mut self, msg: Msg) -> Option<Cmd> {
        // Forward spinner messages to spinner
        self.spinner.update(msg)
    }

    fn view(&self) -> String {
        format!("{} Loading...", self.spinner.view())
    }
}

Structs§

Model
Model represents the state and configuration of a spinner component.
Spinner
Spinner configuration defining animation frames and timing.
TickMsg
Message indicating that the timer has ticked and the spinner should advance one frame.

Enums§

SpinnerOption
Configuration option for creating a new spinner with custom settings.

Statics§

DOT
Dot spinner - matches Go’s Dot constant
ELLIPSIS
Ellipsis spinner - matches Go’s Ellipsis constant
GLOBE
Globe spinner - matches Go’s Globe constant
HAMBURGER
Hamburger spinner - matches Go’s Hamburger constant
JUMP
Jump spinner - matches Go’s Jump constant
LINE
Line spinner - matches Go’s Line constant
METER
Meter spinner - matches Go’s Meter constant
MINI_DOT
MiniDot spinner - matches Go’s MiniDot constant
MONKEY
Monkey spinner - matches Go’s Monkey constant
MOON
Moon spinner - matches Go’s Moon constant
POINTS
Points spinner - matches Go’s Points constant
PULSE
Pulse spinner - matches Go’s Pulse constant

Functions§

dotDeprecated
Deprecated: use the DOT constant instead.
ellipsisDeprecated
Deprecated: use the ELLIPSIS constant instead.
globeDeprecated
Deprecated: use the GLOBE constant instead.
hamburgerDeprecated
Deprecated: use the HAMBURGER constant instead.
jumpDeprecated
Deprecated: use the JUMP constant instead.
lineDeprecated
Deprecated: use the LINE constant instead.
meterDeprecated
Deprecated: use the METER constant instead.
mini_dotDeprecated
Deprecated: use the MINI_DOT constant instead.
monkeyDeprecated
Deprecated: use the MONKEY constant instead.
moonDeprecated
Deprecated: use the MOON constant instead.
new
Creates a new spinner with the given configuration options.
new_modelDeprecated
NewModel returns a model with default values - matches Go’s deprecated NewModel.
pointsDeprecated
Deprecated: use the POINTS constant instead.
pulseDeprecated
Deprecated: use the PULSE constant instead.
tickDeprecated
Tick is the command used to advance the spinner one frame - matches Go’s deprecated Tick function.
with_spinner
Creates a SpinnerOption to set the animation frames and timing.
with_style
Creates a SpinnerOption to set the visual styling.