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_extras::prelude::*;
// 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 spinnerMINI_DOT: Smaller braille dot patternJUMP: Jumping dot animationPULSE: Block fade animation (█, ▓, ▒, ░)POINTS: Three dot bounce animationGLOBE: Earth emoji rotationMOON: Moon phase animationMONKEY: See-no-evil monkey sequenceMETER: Progress bar style animationHAMBURGER: Trigram symbol animationELLIPSIS: 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§
- Spinner
Option - 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§
- dot
Deprecated - Deprecated: use the
DOTconstant instead. - ellipsis
Deprecated - Deprecated: use the
ELLIPSISconstant instead. - globe
Deprecated - Deprecated: use the
GLOBEconstant instead. - hamburger
Deprecated - Deprecated: use the
HAMBURGERconstant instead. - jump
Deprecated - Deprecated: use the
JUMPconstant instead. - line
Deprecated - Deprecated: use the
LINEconstant instead. - meter
Deprecated - Deprecated: use the
METERconstant instead. - mini_
dot Deprecated - Deprecated: use the
MINI_DOTconstant instead. - monkey
Deprecated - Deprecated: use the
MONKEYconstant instead. - moon
Deprecated - Deprecated: use the
MOONconstant instead. - new
- Creates a new spinner with the given configuration options.
- new_
model Deprecated - NewModel returns a model with default values - matches Go’s deprecated NewModel.
- points
Deprecated - Deprecated: use the
POINTSconstant instead. - pulse
Deprecated - Deprecated: use the
PULSEconstant instead. - tick
Deprecated - 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.