Raxol.Terminal.ANSI.TextFormatting (Raxol v0.2.0)

View Source

Handles 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.

Calculates the effective width of a character based on the current style.

Gets the background color.

Gets the foreground color.

Determines if the current line needs a paired line (for double-height mode).

Creates a new text style map with default values.

Gets the paired line type for double-height mode.

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

color()

@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

text_style()

@type text_style() :: %{
  double_width: boolean(),
  double_height: :none | :top | :bottom,
  bold: boolean(),
  italic: boolean(),
  underline: boolean(),
  blink: boolean(),
  reverse: boolean(),
  conceal: boolean(),
  strikethrough: boolean(),
  fraktur: boolean(),
  double_underline: boolean(),
  foreground: color(),
  background: color(),
  hyperlink: String.t() | nil
}

Functions

ansi_code_to_color_name(code)

@spec ansi_code_to_color_name(integer()) :: color() | nil

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

apply_attribute(style, attribute)

@spec apply_attribute(text_style(), atom()) :: text_style()

Applies a text attribute to the style map.

apply_color(style, type, color)

@spec apply_color(text_style(), :foreground | :background, color()) :: text_style()

Applies a color attribute to the style map.

effective_width(style, char)

@spec effective_width(text_style(), String.t()) :: integer()

Calculates the effective width of a character based on the current style.

get_background(style)

@spec get_background(text_style()) :: color()

Gets the background color.

get_foreground(style)

@spec get_foreground(text_style()) :: color()

Gets the foreground color.

needs_paired_line?(style)

@spec needs_paired_line?(text_style()) :: boolean()

Determines if the current line needs a paired line (for double-height mode).

new()

@spec new() :: %{
  double_width: false,
  double_height: :none,
  bold: false,
  italic: false,
  underline: false,
  blink: false,
  reverse: false,
  conceal: false,
  strikethrough: false,
  fraktur: false,
  double_underline: false,
  foreground: nil,
  background: nil,
  hyperlink: nil
}

Creates a new text style map with default values.

paired_line_type(style)

@spec paired_line_type(text_style()) :: :top | :bottom | nil

Gets the paired line type for double-height mode.

reset(style)

@spec reset(text_style()) :: text_style()

Resets all text formatting attributes to their default values.

reset_size(style)

@spec reset_size(text_style()) :: text_style()

Resets to single-width, single-height mode.

set_background(style, color)

@spec set_background(text_style(), color()) :: text_style()

Sets the background color.

set_double_height_bottom(style)

@spec set_double_height_bottom(text_style()) :: text_style()

Sets double-height bottom half mode for the current line.

set_double_height_top(style)

@spec set_double_height_top(text_style()) :: text_style()

Sets double-height top half mode for the current line.

set_double_width(style)

@spec set_double_width(text_style()) :: text_style()

Sets double-width mode for the current line.

set_foreground(style, color)

@spec set_foreground(text_style(), color()) :: text_style()

Sets the foreground color.