Raxol.Terminal.ANSI.TextFormatting (Raxol v0.4.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.
Returns the default text style for the terminal emulator. This is an alias for new/0 for compatibility.
Calculates the effective width of a character based on the current style.
Reconstructs the SGR parameter string corresponding to the given style attributes. Used primarily for DECRQSS responses.
Gets the background color.
Gets the foreground color.
Gets the hyperlink URI.
Gets the paired line type for double-height mode.
Determines if the current line needs a paired line (for double-height mode).
Creates a new text style map with default values.
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(), faint: boolean(), italic: boolean(), underline: boolean(), blink: boolean(), reverse: boolean(), conceal: boolean(), strikethrough: boolean(), fraktur: boolean(), double_underline: boolean(), framed: boolean(), encircled: boolean(), overlined: 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 default_style() :: text_style()
Returns the default text style for the terminal emulator. This is an alias for new/0 for compatibility.
@spec effective_width(text_style(), String.t()) :: integer()
Calculates the effective width of a character based on the current style.
@spec format_sgr_params(text_style()) :: String.t()
Reconstructs the SGR parameter string corresponding to the given style attributes. Used primarily for DECRQSS responses.
@spec get_background(text_style()) :: color()
Gets the background color.
@spec get_foreground(text_style()) :: color()
Gets the foreground color.
@spec get_hyperlink(text_style()) :: String.t() | nil
Gets the hyperlink URI.
@spec get_paired_line_type(text_style()) :: :top | :bottom | :none
Gets the paired line type for double-height mode.
@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,
faint: false,
italic: false,
underline: false,
blink: false,
reverse: false,
conceal: false,
strikethrough: false,
fraktur: false,
double_underline: false,
framed: false,
encircled: false,
overlined: false,
foreground: nil,
background: nil,
hyperlink: nil
}
Creates a new text style map with default values.
@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.