Raxol.Terminal.ANSI.TextFormatting (Raxol v0.5.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 an ANSI code to a color name.
Applies a text attribute to the style map.
Applies the given color to the text.
Calculates the effective width of the text.
Formats a style into SGR (Select Graphic Rendition) parameters. Returns a list of ANSI SGR codes.
Gets the background color.
Gets the foreground color.
Gets the hyperlink from a style. Returns the hyperlink URL or nil if no hyperlink is set.
Returns the paired line type for the given line.
Checks if the line needs a paired line.
Creates a new text formatting struct with default values.
Resets all text attributes to their default values.
Resets blink text mode.
Resets bold text mode.
Resets italic text mode.
Resets reverse video mode.
Resets to single-width, single-height mode.
Resets underline text mode.
Sets a single attribute on the emulator.
Sets multiple text attributes at once.
Sets the background color.
Sets blink text mode.
Sets bold text mode.
Sets concealed text mode.
Sets a custom attribute in the style map.
Sets double-height bottom half mode for the current line.
Sets double-height top half mode for the current line.
Sets double underline text mode.
Sets double-width mode for the current line.
Sets encircled text mode.
Sets faint text mode.
Sets the foreground color.
Sets fraktur text mode.
Sets framed text mode.
Sets a hyperlink for the text.
Sets italic text mode.
Sets overlined text mode.
Sets reverse video mode.
Sets strikethrough text mode.
Sets underline text mode.
Updates multiple attributes from a map.
Validates a text style map.
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 an ANSI code to a color name.
@spec apply_attribute(text_style(), atom()) :: text_style()
Applies a text attribute to the style map.
Parameters
style
- The current text styleattribute
- The attribute to apply (e.g., :bold, :underline, etc.)
Returns
The updated text style with the new attribute applied.
Applies the given color to the text.
Calculates the effective width of the text.
Formats a style into SGR (Select Graphic Rendition) parameters. Returns a list of ANSI SGR codes.
@spec get_background(text_style()) :: color()
Gets the background color.
@spec get_foreground(text_style()) :: color()
Gets the foreground color.
Gets the hyperlink from a style. Returns the hyperlink URL or nil if no hyperlink is set.
Returns the paired line type for the given line.
Checks if the line needs a paired line.
Creates a new text formatting struct with default values.
@spec reset_attributes(text_style()) :: text_style()
Resets all text attributes to their default values.
@spec reset_blink(text_style()) :: text_style()
Resets blink text mode.
@spec reset_bold(text_style()) :: text_style()
Resets bold text mode.
@spec reset_italic(text_style()) :: text_style()
Resets italic text mode.
@spec reset_reverse(text_style()) :: text_style()
Resets reverse video mode.
@spec reset_size(text_style()) :: text_style()
Resets to single-width, single-height mode.
@spec reset_underline(text_style()) :: text_style()
Resets underline text mode.
Sets a single attribute on the emulator.
@spec set_attributes(text_style(), [atom()]) :: text_style()
Sets multiple text attributes at once.
@spec set_background(text_style(), color()) :: text_style()
Sets the background color.
@spec set_blink(text_style()) :: text_style()
Sets blink text mode.
@spec set_bold(text_style()) :: text_style()
Sets bold text mode.
@spec set_conceal(text_style()) :: text_style()
Sets concealed text mode.
@spec set_custom(text_style(), atom(), any()) :: text_style()
Sets a custom attribute in the style map.
@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_underline(text_style()) :: text_style()
Sets double underline text mode.
@spec set_double_width(text_style()) :: text_style()
Sets double-width mode for the current line.
@spec set_encircled(text_style()) :: text_style()
Sets encircled text mode.
@spec set_faint(text_style()) :: text_style()
Sets faint text mode.
@spec set_foreground(text_style(), color()) :: text_style()
Sets the foreground color.
@spec set_fraktur(text_style()) :: text_style()
Sets fraktur text mode.
@spec set_framed(text_style()) :: text_style()
Sets framed text mode.
@spec set_hyperlink(text_style(), String.t() | nil) :: text_style()
Sets a hyperlink for the text.
@spec set_italic(text_style()) :: text_style()
Sets italic text mode.
@spec set_overlined(text_style()) :: text_style()
Sets overlined text mode.
@spec set_reverse(text_style()) :: text_style()
Sets reverse video mode.
@spec set_strikethrough(text_style()) :: text_style()
Sets strikethrough text mode.
@spec set_underline(text_style()) :: text_style()
Sets underline text mode.
@spec update_attrs(text_style(), map()) :: text_style()
Updates multiple attributes from a map.
@spec validate(text_style()) :: {:ok, text_style()} | {:error, String.t()}
Validates a text style map.