ElixirOpentui.ASCIIFont (ElixirOpentui v0.2.0)

Copy Markdown View Source

Renders text using large ASCII art fonts.

Supports multiple font styles with 1 or 2 color channels. Font data is sourced from the MIT-licensed cfonts project.

Summary

Functions

Compute the rendered dimensions of text in a given font.

Get the font data map for a given font name.

Get the height (number of lines) for a font.

Parse color tags from a font glyph row string.

Render text to plain lines (color tags stripped).

Render text to color-segmented rows.

Types

font_name()

@type font_name() :: :tiny | :block

Functions

dimensions(text, font)

@spec dimensions(String.t(), font_name()) :: {non_neg_integer(), non_neg_integer()}

Compute the rendered dimensions of text in a given font.

Returns {width, height} where width is the sum of first-row grapheme widths plus letterspace gaps between characters.

font_data(font)

@spec font_data(font_name()) :: map()

Get the font data map for a given font name.

font_height(font)

@spec font_height(font_name()) :: non_neg_integer()

Get the height (number of lines) for a font.

parse_color_tags(str)

@spec parse_color_tags(String.t()) :: [{String.t(), non_neg_integer()}]

Parse color tags from a font glyph row string.

"<c1>██</c1><c2>╗</c2>" → [{"██", 0}, {"╗", 1}]

Untagged text gets color_index 0.

render_to_lines(text, font)

@spec render_to_lines(String.t(), font_name()) :: [String.t()]

Render text to plain lines (color tags stripped).

Returns a list of strings, one per font line.

render_to_segments(text, font)

@spec render_to_segments(String.t(), font_name()) :: [
  [{String.t(), non_neg_integer()}]
]

Render text to color-segmented rows.

Returns a list of rows, where each row is a list of {text, color_index} segments. Color index 0 = primary color, 1 = secondary color.