beamtea_spinner (beamtea v0.1.2)
View SourceA bubble: an animated spinner.
Inspired by charmbracelet/bubbles. A spinner is a self-contained mini-program (model + update + view). Start its animation by returning tick/1 from your init/1, then forward every message to update/2 — the spinner recognises only its own tick messages and keeps itself running by returning the next tick.
init(_) -> S = beamtea_spinner:new(dot),
{#st{spin = S}, beamtea_spinner:tick(S)}.
update(Msg, St) -> {S1, Cmd} = beamtea_spinner:update(Msg, St#st.spin),
{St#st{spin = S1}, Cmd}.
view(St) -> [beamtea_spinner:view(St#st.spin), " loading..."].
Summary
Functions
A spinner with the default style (dot).
A spinner with the given built-in style() or a custom #{frames => [binary()], fps_ms => pos_integer(), color => 0..255}.
The list of built-in style names.
The command that advances the animation once. Return it from init/1 (and it re-schedules itself thereafter).
Advance the spinner on its own tick; ignore everything else.
The current frame, coloured if a colour was configured.
Types
Functions
-spec new() -> spinner().
A spinner with the default style (dot).
A spinner with the given built-in style() or a custom #{frames => [binary()], fps_ms => pos_integer(), color => 0..255}.
-spec styles() -> [style()].
The list of built-in style names.
-spec tick(spinner()) -> beamtea:cmd().
The command that advances the animation once. Return it from init/1 (and it re-schedules itself thereafter).
-spec update(term(), spinner()) -> {spinner(), beamtea:cmd()}.
Advance the spinner on its own tick; ignore everything else.
The current frame, coloured if a colour was configured.