High-level drawing helpers for TUI applications.
Provides functions for common UI patterns like:
- Braille sparklines
- Progress bars with color gradients
- Box drawing (single and double border)
- Color interpolation utilities
Note: Basic ANSI escape functions have been moved to Alaja.ANSI.
This module now focuses on high-level helpers only.
Summary
Functions
Draw a box with single-line border.
Generate a braille sparkline from a list of values (0-100).
Draw a box with double-line border.
Linear interpolation between two RGB colors.
Generate a progress bar with color gradient.
Safely converts a string to an existing atom.
Functions
Draw a box with single-line border.
Parameters
- x, y: Starting position (1-indexed)
- w, h: Width and height
- title: Optional title (default: "")
- color: RGB color as {r, g, b} (default: {100, 140, 200})
Returns
A list of {x, y, text} tuples for rendering.
Example
iex> Helpers.box(1, 1, 40, 10, "My Box", {100, 140, 200})
[{1, 1, "╭──────────────────────────────────────╮"}, ...]
Generate a braille sparkline from a list of values (0-100).
Parameters
- values: List of numbers (0-100)
- width: Maximum number of braille characters to display
Returns
A string of braille characters representing the data.
Example
iex> Helpers.braille_spark([10, 50, 90, 30], 4)
"⣤ ⣿ ⣤ ⣀"
Draw a box with double-line border.
Parameters
- x, y: Starting position (1-indexed)
- w, h: Width and height
- title: Optional title (default: "")
- color: RGB color as {r, g, b} (default: {180, 130, 80})
Returns
A list of {x, y, text} tuples for rendering.
Example
iex> Helpers.double_box(1, 1, 40, 10, "Workers", {180, 130, 80})
[{1, 1, "╔══════════════════════════════════════╗"}, ...]
Linear interpolation between two RGB colors.
Parameters
- c1: Starting color {r, g, b}
- c2: Ending color {r, g, b}
- t: Interpolation factor (0.0 to 1.0)
Returns
Interpolated color as {r, g, b}.
Example
iex> Helpers.lerp({0, 0, 0}, {255, 255, 255}, 0.5)
{127, 127, 127}
Generate a progress bar with color gradient.
Parameters
- pct: Percentage (0-100)
- width: Width of the bar in characters
- color_start: Starting color as {r, g, b}
- color_end: Ending color as {r, g, b}
Returns
A string containing the progress bar with percentage display.
Example
iex> Helpers.progress_bar(75, 20, {80, 140, 255}, {200, 100, 255})
"███████████████████░░░ 75%"
Safely converts a string to an existing atom.
Wraps String.to_existing_atom/1 in a try/rescue to prevent
atom table exhaustion from untrusted input.
Returns {:ok, atom} on success, {:error, message} if the atom does not exist.