Raxol. Core. Style
(Raxol v2.6.0)
View Source
Style utilities for Raxol.Core.Buffer.
Provides functions to create, merge, and convert styles for terminal rendering. Supports named colors, RGB colors, and 256-color palette.
Example
style = Raxol.Core.Style.new(bold: true, fg_color: :blue)
ansi = Raxol.Core.Style.to_ansi(style)
# => "[1;34m"
Summary
Functions
Create a 256-color palette index.
Merge two style maps, with override values taking precedence.
Validate and return a named color atom.
Create a new style map with the given options.
Reset ANSI sequence to clear all styling.
Create an RGB color tuple.
Convert a style map to ANSI escape codes.
Types
@type color() :: atom() | non_neg_integer() | {non_neg_integer(), non_neg_integer(), non_neg_integer()}
Functions
@spec color_256(0..255) :: 0..255
Create a 256-color palette index.
Example
Raxol.Core.Style.color_256(196)
# => 196
Merge two style maps, with override values taking precedence.
Example
base = Raxol.Core.Style.new(bold: true, fg_color: :red)
override = Raxol.Core.Style.new(fg_color: :blue)
Raxol.Core.Style.merge(base, override)
# => %{bold: true, ..., fg_color: :blue, ...}
@spec named_color(
:black
| :red
| :green
| :yellow
| :blue
| :magenta
| :cyan
| :white
) ::
:black | :red | :green | :yellow | :blue | :magenta | :cyan | :white
Validate and return a named color atom.
Valid colors: :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white
Example
Raxol.Core.Style.named_color(:blue)
# => :blue
Create a new style map with the given options.
Options
:bold- Boolean, enables bold text:italic- Boolean, enables italic text:underline- Boolean, enables underlined text:fg_color- Foreground color (atom, integer 0-255, or RGB tuple):bg_color- Background color (atom, integer 0-255, or RGB tuple)
Example
Raxol.Core.Style.new(bold: true, fg_color: :blue)
# => %{bold: true, italic: false, underline: false, fg_color: :blue, bg_color: nil}
@spec reset() :: String.t()
Reset ANSI sequence to clear all styling.
Example
Raxol.Core.Style.reset()
# => "[0m"
@spec rgb(0..255, 0..255, 0..255) :: {0..255, 0..255, 0..255}
Create an RGB color tuple.
Example
Raxol.Core.Style.rgb(255, 100, 50)
# => {255, 100, 50}
Convert a style map to ANSI escape codes.
Example
style = Raxol.Core.Style.new(bold: true, fg_color: :blue)
Raxol.Core.Style.to_ansi(style)
# => "[1;34m"