TermUI.CharacterSet (TermUI v1.0.0)
View SourceCharacter set definitions for Unicode and ASCII box-drawing characters.
This module provides character sets for rendering borders, progress bars, check marks, and other UI elements. Two character sets are available:
:unicode- Full Unicode box-drawing characters for modern terminals:ascii- ASCII fallback characters for limited terminals
Usage
Widgets should use get/1 to retrieve the appropriate character set based
on terminal capabilities:
chars = TermUI.CharacterSet.get(:unicode)
top_border = chars.tl <> String.duplicate(chars.h_line, width - 2) <> chars.trFor runtime queries, use current/0 which reads from persistent_term:
chars = TermUI.CharacterSet.get(TermUI.CharacterSet.current())Or use the convenience function current_charset/0:
chars = TermUI.CharacterSet.current_charset()Available Characters
Box Drawing
tl,tr,bl,br- Corners (top-left, top-right, bottom-left, bottom-right)tl_round,tr_round,bl_round,br_round- Rounded cornersh_line,v_line- Horizontal and vertical lines (light)h_line_heavy,v_line_heavy- Heavy horizontal and vertical linest_up,t_down,t_left,t_right- T-junctionscross- Cross junction (four-way)
Progress/Gauge
bar_full- Full block for filled progressbar_empty- Empty/light block for unfilled progressbar_levels- List of characters for fractional progress (8 levels Unicode, 5 ASCII)sparkline_levels- List of vertical bar characters for sparklines
Indicators
check- Check mark for success/selectedcross_mark- X mark for failure/deselectedbullet,bullet_empty- Filled and empty circle bulletspointer- Pointer/cursor indicator
Arrows and Triangles
arrow_up,arrow_down,arrow_left,arrow_right- Directional arrowsarrow_up_down- Bidirectional vertical arrowtriangle_up,triangle_down,triangle_left,triangle_right- Solid triangles
Special Icons
info- Information iconwarning- Warning iconloading- Loading/spinner icon
Misc
ellipsis- Ellipsis characterdot- Bullet dot/point
Configuration
When no runtime context exists, the fallback character set can be configured in your application:
config :term_ui, :character_set, :unicodeOr changed while no runtime-managed value is present:
Application.put_env(:term_ui, :character_set, :ascii)
Summary
Functions
Creates the bottom border of a box.
Creates the top border of a box.
Returns the currently configured character set type.
Returns the current character set as a map.
Returns the character set for the given type.
Creates a horizontal line of the specified width.
Returns the list of all character keys available in a character set.
Creates a vertical line as a list of strings.
Types
@type charset() :: :unicode | :ascii
Character set type.
:unicode- Full Unicode box-drawing characters:ascii- ASCII fallback characters
@type t() :: %{ tl: String.t(), tr: String.t(), bl: String.t(), br: String.t(), tl_round: String.t(), tr_round: String.t(), bl_round: String.t(), br_round: String.t(), h_line: String.t(), v_line: String.t(), h_line_heavy: String.t(), v_line_heavy: String.t(), t_up: String.t(), t_down: String.t(), t_left: String.t(), t_right: String.t(), cross: String.t(), bar_full: String.t(), bar_empty: String.t(), bar_levels: [String.t()], sparkline_levels: [String.t()], check: String.t(), cross_mark: String.t(), arrow_up: String.t(), arrow_down: String.t(), arrow_left: String.t(), arrow_right: String.t(), arrow_up_down: String.t(), triangle_up: String.t(), triangle_down: String.t(), triangle_left: String.t(), triangle_right: String.t(), bullet: String.t(), bullet_empty: String.t(), pointer: String.t(), info: String.t(), warning: String.t(), loading: String.t(), ellipsis: String.t(), dot: String.t() }
Character set map containing all box-drawing and special characters.
Functions
@spec box_bottom(non_neg_integer()) :: String.t()
Creates the bottom border of a box.
Format: └ + horizontal line + ┘
Parameters
width- Total width including corners (minimum 2)
Examples
iex> TermUI.CharacterSet.box_bottom(10)
"└────────┘" # Unicode mode
@spec box_top(non_neg_integer()) :: String.t()
Creates the top border of a box.
Format: ┌ + horizontal line + ┐
Parameters
width- Total width including corners (minimum 2)
Examples
iex> TermUI.CharacterSet.box_top(10)
"┌────────┐" # Unicode mode
@spec current() :: charset()
Returns the currently configured character set type.
Reads from persistent_term via PersistentTerms (set by Runtime from detected
Unicode capabilities), falling back to application config. Defaults to
:unicode if neither is configured.
Returns
Either :unicode or :ascii.
Examples
iex> TermUI.CharacterSet.current()
:unicode
# After Runtime sets it based on capabilities
iex> :persistent_term.put(:term_ui_character_set, :ascii)
iex> TermUI.CharacterSet.current()
:ascii
@spec current_charset() :: t()
Returns the current character set as a map.
Convenience function that combines current/0 and get/1.
Returns
A map containing all box-drawing and special characters for the currently configured character set.
Examples
iex> chars = TermUI.CharacterSet.current_charset()
iex> is_map(chars)
true
iex> Application.put_env(:term_ui, :character_set, :ascii)
iex> TermUI.CharacterSet.current_charset().tl
"+"
Returns the character set for the given type.
Parameters
type- Either:unicodeor:ascii
Returns
A map containing all box-drawing and special characters.
Examples
iex> chars = TermUI.CharacterSet.get(:unicode)
iex> chars.tl
"┌"
iex> chars = TermUI.CharacterSet.get(:ascii)
iex> chars.tl
"+"
@spec horizontal_line(non_neg_integer()) :: String.t()
Creates a horizontal line of the specified width.
Uses the current character set's horizontal line character.
Parameters
width- Width of the line in characters
Examples
iex> TermUI.CharacterSet.horizontal_line(5)
"─────" # Unicode mode
iex> Application.put_env(:term_ui, :character_set, :ascii)
iex> TermUI.CharacterSet.horizontal_line(5)
"-----"
@spec keys() :: [atom()]
Returns the list of all character keys available in a character set.
Keys are derived from the actual character set map at compile time, ensuring they stay in sync with the character set definitions.
Useful for validation and testing.
Returns
List of atom keys.
Examples
iex> :tl in TermUI.CharacterSet.keys()
true
@spec vertical_line(non_neg_integer()) :: [String.t()]
Creates a vertical line as a list of strings.
Returns a list of vertical line characters, one per line.
Parameters
height- Height of the line in characters
Examples
iex> TermUI.CharacterSet.vertical_line(3)
["│", "│", "│"] # Unicode mode