progress_bar (cellium v0.1.0)

View Source

Progress bar widget module for displaying task completion.

This module provides a visual progress bar widget that displays completion percentage using filled and unfilled block characters.

Usage

Basic progress bar:

progress_bar:new(my_progress)

Progress bar with custom width and progress:

Widget = progress_bar:new(my_progress),
CustomWidget = Widget#{width => 40, progress => 0.75}

Properties

  • progress (float): Completion percentage from 0.0 to 1.0. Default: 0.0
  • width (integer): Total width of the progress bar including brackets. Default: 20
  • focusable (boolean): Set to true by default

Display

The progress bar uses Unicode block characters:

  • for filled portion (completed)
  • for unfilled portion (remaining)
  • Format: [████████░░░░░░░░░░]

When focused, foreground and background colors are swapped.

Example

% 50% complete with width of 30
Widget#{progress => 0.5, width => 30}
% Displays: [██████████████░░░░░░░░░░░░░░]

Summary

Functions

Handles keyboard events for the progress bar. Adjusts progress with Left/Right arrow keys.

Creates a new progress bar with default settings.

Renders the progress bar in unfocused state.

Renders the progress bar in focused state with inverted colors.

Functions

handle_event/2

-spec handle_event(term(), map()) -> map().

Handles keyboard events for the progress bar. Adjusts progress with Left/Right arrow keys.

new(Id)

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

Creates a new progress bar with default settings.

Default progress is 0.0 (0%) and default width is 20 characters.

render(Widget, Buffer)

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

Renders the progress bar in unfocused state.

render_focused(Widget, Buffer)

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

Renders the progress bar in focused state with inverted colors.