Raxol.Terminal.ANSI.Sequences.Colors (Raxol v0.5.0)

View Source

ANSI Color Sequence Handler.

Handles parsing and application of ANSI color control sequences, including 16-color mode, 256-color mode, and true color (24-bit) mode.

Summary

Functions

Generate ANSI color code for a given color.

Returns a map of ANSI color codes.

Parse a color string into a Color struct.

Set the background color.

Set background color using 256-color mode.

Set background color using basic 16-color mode.

Set background color using true (24-bit) RGB color.

Set a color at a specific index in the color palette.

Set the cursor color.

Set the foreground color.

Set foreground color using 256-color mode.

Set foreground color using basic 16-color mode.

Set foreground color using true (24-bit) RGB color.

Set the highlight background color.

Set the highlight cursor color.

Set the highlight foreground color.

Set the highlight mouse background color.

Set the highlight mouse foreground color.

Set the mouse background color.

Set the mouse foreground color.

Functions

color_code(color, arg2)

Generate ANSI color code for a given color.

Parameters

  • color - The color struct
  • type - Either :foreground or :background

Returns

ANSI escape sequence as string

color_codes()

Returns a map of ANSI color codes.

Returns

A map of color names to ANSI codes.

Examples

iex> Raxol.Terminal.ANSI.Sequences.Colors.color_codes()
%{
  black: "",
  red: "",
  # ... other colors ...
  reset: ""
}

parse_color(color_str)

Parse a color string into a Color struct.

Parameters

  • color_str - Color string in format "rgb:RRRR/GGGG/BBBB" or "#RRGGBB"

Returns

Color struct or nil if invalid format

set_background(colors, color)

Set the background color.

Parameters

  • colors - The color palette
  • color - Color struct

Returns

Updated color palette

set_background_256(emulator, index)

Set background color using 256-color mode.

Parameters

  • emulator - The terminal emulator state
  • index - Color index (0-255)

Returns

Updated emulator state

set_background_basic(emulator, color_code)

Set background color using basic 16-color mode.

Parameters

  • emulator - The terminal emulator state
  • color_code - Color code (0-15)

Returns

Updated emulator state

set_background_true(emulator, r, g, b)

Set background color using true (24-bit) RGB color.

Parameters

  • emulator - The terminal emulator state
  • r - Red component (0-255)
  • g - Green component (0-255)
  • b - Blue component (0-255)

Returns

Updated emulator state

set_color(colors, index, color)

Set a color at a specific index in the color palette.

Parameters

  • colors - The color palette
  • index - Color index (0-255)
  • color - Color struct

Returns

Updated color palette

set_cursor_color(colors, color)

Set the cursor color.

Parameters

  • colors - The color palette
  • color - Color struct

Returns

Updated color palette

set_foreground(colors, color)

Set the foreground color.

Parameters

  • colors - The color palette
  • color - Color struct

Returns

Updated color palette

set_foreground_256(emulator, index)

Set foreground color using 256-color mode.

Parameters

  • emulator - The terminal emulator state
  • index - Color index (0-255)

Returns

Updated emulator state

set_foreground_basic(emulator, color_code)

Set foreground color using basic 16-color mode.

Parameters

  • emulator - The terminal emulator state
  • color_code - Color code (0-15)

Returns

Updated emulator state

set_foreground_true(emulator, r, g, b)

Set foreground color using true (24-bit) RGB color.

Parameters

  • emulator - The terminal emulator state
  • r - Red component (0-255)
  • g - Green component (0-255)
  • b - Blue component (0-255)

Returns

Updated emulator state

set_highlight_background(colors, color)

Set the highlight background color.

Parameters

  • colors - The color palette
  • color - Color struct

Returns

Updated color palette

set_highlight_cursor(colors, color)

Set the highlight cursor color.

Parameters

  • colors - The color palette
  • color - Color struct

Returns

Updated color palette

set_highlight_foreground(colors, color)

Set the highlight foreground color.

Parameters

  • colors - The color palette
  • color - Color struct

Returns

Updated color palette

set_highlight_mouse_background(colors, color)

Set the highlight mouse background color.

Parameters

  • colors - The color palette
  • color - Color struct

Returns

Updated color palette

set_highlight_mouse_foreground(colors, color)

Set the highlight mouse foreground color.

Parameters

  • colors - The color palette
  • color - Color struct

Returns

Updated color palette

set_mouse_background(colors, color)

Set the mouse background color.

Parameters

  • colors - The color palette
  • color - Color struct

Returns

Updated color palette

set_mouse_foreground(colors, color)

Set the mouse foreground color.

Parameters

  • colors - The color palette
  • color - Color struct

Returns

Updated color palette