Raxol.Terminal.ANSI.TextFormatting (Raxol v0.2.0)
View SourceHandles advanced text formatting features for the terminal emulator. This includes double-width and double-height characters, as well as other advanced text attributes and colors.
Summary
Functions
Converts a standard ANSI 3/4-bit color code to a color name atom.
Applies a text attribute to the style map.
Applies a color attribute to the style map.
Calculates the effective width of a character based on the current style.
Gets the background color.
Gets the foreground color.
Determines if the current line needs a paired line (for double-height mode).
Creates a new text style map with default values.
Gets the paired line type for double-height mode.
Resets all text formatting attributes to their default values.
Resets to single-width, single-height mode.
Sets the background color.
Sets double-height bottom half mode for the current line.
Sets double-height top half mode for the current line.
Sets double-width mode for the current line.
Sets the foreground color.
Types
@type color() :: :black | :red | :green | :yellow | :blue | :magenta | :cyan | :white | {:rgb, non_neg_integer(), non_neg_integer(), non_neg_integer()} | {:index, non_neg_integer()} | nil
@type text_style() :: %{ double_width: boolean(), double_height: :none | :top | :bottom, bold: boolean(), italic: boolean(), underline: boolean(), blink: boolean(), reverse: boolean(), conceal: boolean(), strikethrough: boolean(), fraktur: boolean(), double_underline: boolean(), foreground: color(), background: color(), hyperlink: String.t() | nil }
Functions
Converts a standard ANSI 3/4-bit color code to a color name atom.
Examples
iex> Raxol.Terminal.ANSI.TextFormatting.ansi_code_to_color_name(31)
:red
iex> Raxol.Terminal.ANSI.TextFormatting.ansi_code_to_color_name(44)
:blue
iex> Raxol.Terminal.ANSI.TextFormatting.ansi_code_to_color_name(99) # Unknown
nil
@spec apply_attribute(text_style(), atom()) :: text_style()
Applies a text attribute to the style map.
@spec apply_color(text_style(), :foreground | :background, color()) :: text_style()
Applies a color attribute to the style map.
@spec effective_width(text_style(), String.t()) :: integer()
Calculates the effective width of a character based on the current style.
@spec get_background(text_style()) :: color()
Gets the background color.
@spec get_foreground(text_style()) :: color()
Gets the foreground color.
@spec needs_paired_line?(text_style()) :: boolean()
Determines if the current line needs a paired line (for double-height mode).
@spec new() :: %{
double_width: false,
double_height: :none,
bold: false,
italic: false,
underline: false,
blink: false,
reverse: false,
conceal: false,
strikethrough: false,
fraktur: false,
double_underline: false,
foreground: nil,
background: nil,
hyperlink: nil
}
Creates a new text style map with default values.
@spec paired_line_type(text_style()) :: :top | :bottom | nil
Gets the paired line type for double-height mode.
@spec reset(text_style()) :: text_style()
Resets all text formatting attributes to their default values.
@spec reset_size(text_style()) :: text_style()
Resets to single-width, single-height mode.
@spec set_background(text_style(), color()) :: text_style()
Sets the background color.
@spec set_double_height_bottom(text_style()) :: text_style()
Sets double-height bottom half mode for the current line.
@spec set_double_height_top(text_style()) :: text_style()
Sets double-height top half mode for the current line.
@spec set_double_width(text_style()) :: text_style()
Sets double-width mode for the current line.
@spec set_foreground(text_style(), color()) :: text_style()
Sets the foreground color.