beamtea_spinner (beamtea v0.1.2)

View Source

A 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

spinner/0

-opaque spinner()

style/0

-type style() :: line | dot | minidot | jump | points | moon | meter | pulse.

Functions

new()

-spec new() -> spinner().

A spinner with the default style (dot).

new(Style)

-spec new(style() | map()) -> spinner().

A spinner with the given built-in style() or a custom #{frames => [binary()], fps_ms => pos_integer(), color => 0..255}.

styles()

-spec styles() -> [style()].

The list of built-in style names.

tick(_)

-spec tick(spinner()) -> beamtea:cmd().

The command that advances the animation once. Return it from init/1 (and it re-schedules itself thereafter).

update(Msg, S)

-spec update(term(), spinner()) -> {spinner(), beamtea:cmd()}.

Advance the spinner on its own tick; ignore everything else.

view(_)

-spec view(spinner()) -> iodata().

The current frame, coloured if a colour was configured.