Raxol.Terminal.StyleBuffer (Raxol v2.0.1)

View Source

Manages terminal style state and operations. This module handles text attributes, colors, and formatting for terminal output.

Summary

Functions

Applies a style to a rectangular region.

Gets the default style.

Gets the current style.

Gets the style at a specific position (x, y). Returns the style at the position or the current style if not set.

Merges two styles.

Creates a new style buffer with the given dimensions.

Resets the style to default.

Sets text attributes (list of atoms).

Sets the background color.

Sets the default style.

Sets the foreground color.

Validates a style map.

Types

position()

@type position() :: {non_neg_integer(), non_neg_integer()}

region()

@type region() :: {position(), position()}

style()

@type style() :: %{
  foreground: String.t() | nil,
  background: String.t() | nil,
  bold: boolean(),
  italic: boolean(),
  underline: boolean(),
  attributes: [atom()]
}

t()

@type t() :: %Raxol.Terminal.StyleBuffer{
  current_style: style(),
  default_style: style(),
  height: non_neg_integer(),
  style_map: %{required(position()) => style()},
  width: non_neg_integer()
}

Functions

apply_style_to_region(buffer, style, arg1, arg2)

@spec apply_style_to_region(
  t(),
  style(),
  {non_neg_integer(), non_neg_integer()},
  {non_neg_integer(), non_neg_integer()}
) :: t()

Applies a style to a rectangular region.

get_default_style(style_buffer)

@spec get_default_style(t()) :: style()

Gets the default style.

get_style(style_buffer)

@spec get_style(t()) :: style()

Gets the current style.

get_style_at(style_buffer, x, y)

@spec get_style_at(t(), non_neg_integer(), non_neg_integer()) :: style()

Gets the style at a specific position (x, y). Returns the style at the position or the current style if not set.

merge_styles(style1, style2)

@spec merge_styles(style(), style()) :: style()

Merges two styles.

new(width, height)

@spec new(non_neg_integer(), non_neg_integer()) :: t()

Creates a new style buffer with the given dimensions.

reset_style(buffer)

@spec reset_style(t()) :: t()

Resets the style to default.

set_attributes(buffer, attrs)

@spec set_attributes(t(), [atom()]) :: t()

Sets text attributes (list of atoms).

set_background(buffer, color)

@spec set_background(t(), String.t()) :: t()

Sets the background color.

set_default_style(buffer, style)

@spec set_default_style(t(), style()) :: t()

Sets the default style.

set_foreground(buffer, color)

@spec set_foreground(t(), String.t()) :: t()

Sets the foreground color.

validate_style(style)

@spec validate_style(style()) :: :ok | {:error, String.t()}

Validates a style map.