Raxol.Terminal.Buffer.Formatting (Raxol v0.5.0)
View SourceManages text formatting state and operations for the screen buffer. This module handles text attributes, colors, and style management.
Summary
Functions
Checks if a specific attribute is set.
Gets the current background color.
Gets the current foreground color.
Gets all currently set attributes.
Gets the current style.
Initializes a new formatting state with default values.
Resets all attributes to their default values.
Resets a specific attribute.
Sets a specific attribute.
Sets the background color.
Sets the foreground color.
Updates the style with new attributes.
Types
@type t() :: %Raxol.Terminal.Buffer.Formatting{ background: {non_neg_integer(), non_neg_integer(), non_neg_integer()} | nil, blink: boolean(), bold: boolean(), dim: boolean(), foreground: {non_neg_integer(), non_neg_integer(), non_neg_integer()} | nil, hidden: boolean(), italic: boolean(), reverse: boolean(), strikethrough: boolean(), underline: boolean() }
Functions
@spec attribute_set?(Raxol.Terminal.ScreenBuffer.t(), atom()) :: boolean()
Checks if a specific attribute is set.
Parameters
buffer
- The screen buffer to queryattribute
- The attribute to check
Returns
A boolean indicating if the attribute is set.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> Formatting.attribute_set?(buffer, :bold)
false
@spec get_background(Raxol.Terminal.ScreenBuffer.t()) :: {non_neg_integer(), non_neg_integer(), non_neg_integer()} | nil
Gets the current background color.
Parameters
buffer
- The screen buffer to query
Returns
The current background color or nil if not set.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> Formatting.get_background(buffer)
nil
@spec get_foreground(Raxol.Terminal.ScreenBuffer.t()) :: {non_neg_integer(), non_neg_integer(), non_neg_integer()} | nil
Gets the current foreground color.
Parameters
buffer
- The screen buffer to query
Returns
The current foreground color or nil if not set.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> Formatting.get_foreground(buffer)
nil
@spec get_set_attributes(Raxol.Terminal.ScreenBuffer.t()) :: [atom()]
Gets all currently set attributes.
Parameters
buffer
- The screen buffer to query
Returns
A list of set attributes.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Formatting.set_attribute(buffer, :bold)
iex> Formatting.get_set_attributes(buffer)
[:bold]
@spec get_style(Raxol.Terminal.ScreenBuffer.t()) :: t()
Gets the current style.
Parameters
buffer
- The screen buffer to query
Returns
The current style map.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> Formatting.get_style(buffer)
%{bold: false, dim: false, italic: false, underline: false, blink: false, reverse: false, hidden: false, strikethrough: false, foreground: nil, background: nil}
@spec init() :: t()
Initializes a new formatting state with default values.
@spec reset_all(Raxol.Terminal.ScreenBuffer.t()) :: Raxol.Terminal.ScreenBuffer.t()
Resets all attributes to their default values.
Parameters
buffer
- The screen buffer to modify
Returns
The updated screen buffer with all attributes reset.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Formatting.reset_all(buffer)
iex> Formatting.get_style(buffer)
%{bold: false, dim: false, italic: false, underline: false, blink: false, reverse: false, hidden: false, strikethrough: false, foreground: nil, background: nil}
@spec reset_attribute(Raxol.Terminal.ScreenBuffer.t(), atom()) :: Raxol.Terminal.ScreenBuffer.t()
Resets a specific attribute.
Parameters
buffer
- The screen buffer to modifyattribute
- The attribute to reset (:bold, :dim, :italic, etc.)
Returns
The updated screen buffer with the attribute reset.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Formatting.reset_attribute(buffer, :bold)
iex> Formatting.attribute_set?(buffer, :bold)
false
@spec set_attribute(Raxol.Terminal.ScreenBuffer.t(), atom()) :: Raxol.Terminal.ScreenBuffer.t()
Sets a specific attribute.
Parameters
buffer
- The screen buffer to modifyattribute
- The attribute to set (:bold, :dim, :italic, etc.)
Returns
The updated screen buffer with the attribute set.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Formatting.set_attribute(buffer, :bold)
iex> Formatting.attribute_set?(buffer, :bold)
true
@spec set_background( Raxol.Terminal.ScreenBuffer.t(), {non_neg_integer(), non_neg_integer(), non_neg_integer()} ) :: Raxol.Terminal.ScreenBuffer.t()
Sets the background color.
Parameters
buffer
- The screen buffer to modifycolor
- The RGB color tuple {r, g, b}
Returns
The updated screen buffer with new background color.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Formatting.set_background(buffer, {0, 0, 255})
iex> Formatting.get_background(buffer)
{0, 0, 255}
@spec set_foreground( Raxol.Terminal.ScreenBuffer.t(), {non_neg_integer(), non_neg_integer(), non_neg_integer()} ) :: Raxol.Terminal.ScreenBuffer.t()
Sets the foreground color.
Parameters
buffer
- The screen buffer to modifycolor
- The RGB color tuple {r, g, b}
Returns
The updated screen buffer with new foreground color.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Formatting.set_foreground(buffer, {255, 0, 0})
iex> Formatting.get_foreground(buffer)
{255, 0, 0}
@spec update_style(Raxol.Terminal.ScreenBuffer.t(), map()) :: Raxol.Terminal.ScreenBuffer.t()
Updates the style with new attributes.
Parameters
buffer
- The screen buffer to modifystyle
- The new style map
Returns
The updated screen buffer with new style.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Formatting.update_style(buffer, %{bold: true})
iex> Formatting.get_style(buffer)
%{bold: true, ...}