spinner (cellium v0.1.0)

View Source

Spinner widget module for displaying loading/activity indicators.

This module provides an animated spinner widget that cycles through a series of frames to indicate ongoing activity or loading state.

Usage

Basic spinner:

spinner:new(loading_spinner)

Spinner with custom frames:

Widget = spinner:new(loading_spinner),
CustomWidget = Widget#{frames => ["-", "\\", "|", "/"]}

Properties

  • frame (integer): Current frame index. Increment this in your update loop to animate the spinner. Default: 0
  • frames (list of strings): List of characters/strings to cycle through. Default: ["⣷", "⣯", "⣟", "⡿", "⢿", "⣻", "⣽", "⣾"] (Braille dots)
  • focusable (boolean): Not focusable by default

Animation

To animate the spinner, increment the frame value in your update function:

update(Model, tick) ->
    erlang:send_after(100, self(), tick),
    Model#{spinner_frame => maps:get(spinner_frame, Model) + 1}.

Then pass the frame to the widget:

{spinner, [{id, s1}, {frame, maps:get(spinner_frame, Model)}]}

Default Frames

The default frames use Unicode Braille patterns for a smooth circular animation. Alternative classic frames: ["|", "/", "-", "\\"]

Summary

Functions

Creates a new spinner with default Braille dot animation frames.

Renders the current frame of the spinner.

Functions

new(Id)

-spec new(term()) -> map().

Creates a new spinner with default Braille dot animation frames.

The spinner starts at frame 0. Increment the frame value to animate.

render(Widget, Buffer)

-spec render(map(), map()) -> map().

Renders the current frame of the spinner.

The frame index wraps around using modulo, so incrementing indefinitely works.