Structure that defines text effects applicable in terminal.
Represents a collection of visual effects (bold, italic, underline, etc.) that can be applied to text when rendering to terminal.
Examples
iex> EffectInfo.new(:bold)
%EffectInfo{bold: true, dim: false, ...}
iex> EffectInfo.new([:bold, :underline])
%EffectInfo{bold: true, underline: true, ...}
iex> EffectInfo.to_ansi(EffectInfo.new([:bold, :italic]))
"\e[1;3m"
Summary
Functions
Combines two EffectInfo structures.
Creates a new empty EffectInfo structure.
Creates a new EffectInfo from various inputs.
Calculates the optimal foreground color for a given background color.
Converts EffectInfo to ANSI escape codes.
Types
Functions
Combines two EffectInfo structures.
Effects are combined using OR logic - if either has an effect enabled, the result will have it enabled.
Examples
iex> e1 = EffectInfo.new(:bold)
iex> e2 = EffectInfo.new(:italic)
iex> EffectInfo.combine(e1, e2)
%EffectInfo{bold: true, italic: true, ...}
@spec new() :: t()
Creates a new empty EffectInfo structure.
Examples
iex> EffectInfo.new()
%EffectInfo{bold: false, dim: false, ...}
Creates a new EffectInfo from various inputs.
Parameters
effect- Can be:- An atom (
:bold,:italic, etc.) - A list of atoms
- A URL string (creates link effect)
- An existing EffectInfo struct
- A map with effect fields
- An atom (
Examples
iex> EffectInfo.new(:bold)
%EffectInfo{bold: true, ...}
iex> EffectInfo.new([:bold, :underline])
%EffectInfo{bold: true, underline: true, ...}
iex> EffectInfo.new("https://example.com")
%EffectInfo{link: "https://example.com"}
Calculates the optimal foreground color for a given background color.
Uses brightness (luminance) to determine whether to use white or black for best contrast.
Examples
iex> EffectInfo.optimal_fg_color({255, 255, 255})
{0, 0, 0}
iex> EffectInfo.optimal_fg_color({0, 0, 0})
{255, 255, 255}
Converts EffectInfo to ANSI escape codes.
Examples
iex> EffectInfo.to_ansi(EffectInfo.new([:bold, :underline]))
"\e[1;4m"