Unified terminal text formatting and styling operations.
This module manages formatting state (bold, italic, colors, etc.) and provides functions for applying ANSI escape codes to text. It consolidates the previously separate FormattingManager and Formatting.Manager modules.
Usage
iex> format = Format.new()
iex> format = Format.set_foreground(format, 196)
iex> format = Format.toggle_bold(format)
iex> Format.apply_formatting(format, "Hello")
"[1m[38;5;196mHello[39m[22m"
Summary
Functions
Applies a map of format updates to the current state.
Applies the current formatting to a string, wrapping it with ANSI escape codes.
Checks if the specified attribute is set.
Gets the current background color.
Gets the current foreground color.
Gets the current formatting state.
Returns a list of all attributes that are currently set to true.
Creates a new formatting state with default values.
Resets the specified attribute to false.
Resets the current format to default values.
Restores the previously saved format state.
Saves the current format state for later restoration.
Sets the specified attribute to true.
Sets the background color.
Sets the font number (0-9 for standard ANSI fonts).
Sets the foreground color.
Generates the ANSI escape sequence for the current format without text.
Toggles blink formatting.
Toggles bold formatting.
Toggles conceal formatting.
Toggles faint formatting.
Toggles italic formatting.
Toggles reverse video formatting.
Toggles strikethrough formatting.
Toggles underline formatting.
Types
@type format() :: %{ bold: boolean(), faint: boolean(), italic: boolean(), underline: boolean(), blink: boolean(), reverse: boolean(), conceal: boolean(), strikethrough: boolean(), foreground: term() | nil, background: term() | nil, font: non_neg_integer() }
Terminal text attributes
Format state with current and saved formats
Functions
Applies a map of format updates to the current state.
Applies the current formatting to a string, wrapping it with ANSI escape codes.
Each attribute that is enabled will add the appropriate SGR codes around the text.
Checks if the specified attribute is set.
Gets the current background color.
Gets the current foreground color.
Gets the current formatting state.
Returns a list of all attributes that are currently set to true.
@spec new() :: %Raxol.Terminal.Format{
current_format: %{
bold: false,
faint: false,
italic: false,
underline: false,
blink: false,
reverse: false,
conceal: false,
strikethrough: false,
foreground: nil,
background: nil,
font: 0
},
saved_format: nil
}
Creates a new formatting state with default values.
Resets the specified attribute to false.
Resets the current format to default values.
Restores the previously saved format state.
Returns unchanged state if no format was saved.
Saves the current format state for later restoration.
Sets the specified attribute to true.
Sets the background color.
Color can be an 8-bit color code (0-255) or nil for default.
@spec set_font(t(), non_neg_integer()) :: t()
Sets the font number (0-9 for standard ANSI fonts).
Sets the foreground color.
Color can be an 8-bit color code (0-255) or nil for default.
Generates the ANSI escape sequence for the current format without text.
Returns a tuple of {start_sequence, end_sequence} that can be used to wrap text.
Toggles blink formatting.
Toggles bold formatting.
Toggles conceal formatting.
Toggles faint formatting.
Toggles italic formatting.
Toggles reverse video formatting.
Toggles strikethrough formatting.
Toggles underline formatting.