Pote.Style (Pote v3.0.0)

Copy Markdown View Source

Inline styling DSL — compose foreground, background and text effects into an immutable %Pote.Style{} struct, then render text with ANSI escapes.

Pote.Style is the agnostic, terminal-agnostic layer: it resolves colors (atoms from Pote.Colors.Basic, RGB tuples, hex strings via Pote.parse/1) and emits truecolor ANSI. Deciding whether to fall back to 256-color or no-color modes is the host's job (alaja does this for the TUI).

Example

iex> style = Pote.Style.red() |> Pote.Style.bold() |> Pote.Style.on("#1e1e2e")
iex> style.fg
{255, 0, 0}
iex> style.bg
{30, 30, 46}
iex> style.effects
[:bold]
iex> Pote.Style.render(style, "hi") |> IO.iodata_to_binary()
"hi"

Summary

Functions

Returns a style with aqua as the foreground color.

Sets the background color on a style. Alias of on/2.

Returns a style with black as the foreground color.

Adds the blink effect to the style.

Returns a style with blue as the foreground color.

Adds the bold effect to the style.

Returns a style with bright_black as the foreground color.

Returns a style with bright_blue as the foreground color.

Returns a style with bright_cyan as the foreground color.

Returns a style with bright_green as the foreground color.

Returns a style with bright_magenta as the foreground color.

Returns a style with bright_red as the foreground color.

Returns a style with bright_white as the foreground color.

Returns a style with bright_yellow as the foreground color.

Returns a style with cyan as the foreground color.

Adds the dim effect to the style.

Sets the foreground color on a style.

Returns a style with fuchsia as the foreground color.

Returns a style with gray as the foreground color.

Returns a style with green as the foreground color.

Returns a style with grey as the foreground color.

Adds the hidden effect to the style.

Returns a style with indigo as the foreground color.

Adds the inverse effect to the style.

Adds the italic effect to the style.

Returns a style with lime as the foreground color.

Returns a style with magenta as the foreground color.

Returns a style with maroon as the foreground color.

Returns a style with navy as the foreground color.

Returns an empty style (no fg, no bg, no effects).

Returns a style with olive as the foreground color.

Sets the background color on a style (terminal-idiomatic "on").

Returns a style with orange as the foreground color.

Returns a style with pink as the foreground color.

Returns a style with purple as the foreground color.

Returns a style with red as the foreground color.

Renders text with the style applied, including the reset sequence.

Returns a style with silver as the foreground color.

Returns a style with teal as the foreground color.

Returns the ANSI escape sequence for the style as iodata.

Adds the underline effect to the style.

Returns a style with violet as the foreground color.

Returns a style with white as the foreground color.

Returns a style with yellow as the foreground color.

Types

color_input()

@type color_input() :: atom() | binary() | Pote.rgb()

effect()

@type effect() :: :bold | :dim | :italic | :underline | :inverse | :blink | :hidden

t()

@type t() :: %Pote.Style{
  bg: Pote.rgb() | nil,
  effects: [effect()],
  fg: Pote.rgb() | nil
}

Functions

aqua(style \\ %__MODULE__{})

@spec aqua(t()) :: t()

Returns a style with aqua as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

bg(style \\ %__MODULE__{}, color)

@spec bg(t(), color_input()) :: t()

Sets the background color on a style. Alias of on/2.

Examples

iex> Pote.Style.new() |> Pote.Style.bg("#1e1e2e")
%Pote.Style{fg: nil, bg: {30, 30, 46}, effects: []}

black(style \\ %__MODULE__{})

@spec black(t()) :: t()

Returns a style with black as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

blink(style \\ %__MODULE__{})

@spec blink(t()) :: t()

Adds the blink effect to the style.

Examples

iex> Pote.Style.bold().effects
[:bold]

blue(style \\ %__MODULE__{})

@spec blue(t()) :: t()

Returns a style with blue as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

bold(style \\ %__MODULE__{})

@spec bold(t()) :: t()

Adds the bold effect to the style.

Examples

iex> Pote.Style.bold().effects
[:bold]

bright_black(style \\ %__MODULE__{})

@spec bright_black(t()) :: t()

Returns a style with bright_black as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

bright_blue(style \\ %__MODULE__{})

@spec bright_blue(t()) :: t()

Returns a style with bright_blue as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

bright_cyan(style \\ %__MODULE__{})

@spec bright_cyan(t()) :: t()

Returns a style with bright_cyan as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

bright_green(style \\ %__MODULE__{})

@spec bright_green(t()) :: t()

Returns a style with bright_green as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

bright_magenta(style \\ %__MODULE__{})

@spec bright_magenta(t()) :: t()

Returns a style with bright_magenta as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

bright_red(style \\ %__MODULE__{})

@spec bright_red(t()) :: t()

Returns a style with bright_red as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

bright_white(style \\ %__MODULE__{})

@spec bright_white(t()) :: t()

Returns a style with bright_white as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

bright_yellow(style \\ %__MODULE__{})

@spec bright_yellow(t()) :: t()

Returns a style with bright_yellow as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

cyan(style \\ %__MODULE__{})

@spec cyan(t()) :: t()

Returns a style with cyan as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

dim(style \\ %__MODULE__{})

@spec dim(t()) :: t()

Adds the dim effect to the style.

Examples

iex> Pote.Style.bold().effects
[:bold]

fg(style \\ %__MODULE__{}, color)

@spec fg(t(), color_input()) :: t()

Sets the foreground color on a style.

Accepts a color name atom (:red), an RGB tuple, or a hex string ("#ff0000").

Examples

iex> Pote.Style.new() |> Pote.Style.fg(:red)
%Pote.Style{fg: {255, 0, 0}, bg: nil, effects: []}

fuchsia(style \\ %__MODULE__{})

@spec fuchsia(t()) :: t()

Returns a style with fuchsia as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

gray(style \\ %__MODULE__{})

@spec gray(t()) :: t()

Returns a style with gray as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

green(style \\ %__MODULE__{})

@spec green(t()) :: t()

Returns a style with green as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

grey(style \\ %__MODULE__{})

@spec grey(t()) :: t()

Returns a style with grey as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

hidden(style \\ %__MODULE__{})

@spec hidden(t()) :: t()

Adds the hidden effect to the style.

Examples

iex> Pote.Style.bold().effects
[:bold]

indigo(style \\ %__MODULE__{})

@spec indigo(t()) :: t()

Returns a style with indigo as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

inverse(style \\ %__MODULE__{})

@spec inverse(t()) :: t()

Adds the inverse effect to the style.

Examples

iex> Pote.Style.bold().effects
[:bold]

italic(style \\ %__MODULE__{})

@spec italic(t()) :: t()

Adds the italic effect to the style.

Examples

iex> Pote.Style.bold().effects
[:bold]

lime(style \\ %__MODULE__{})

@spec lime(t()) :: t()

Returns a style with lime as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

magenta(style \\ %__MODULE__{})

@spec magenta(t()) :: t()

Returns a style with magenta as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

maroon(style \\ %__MODULE__{})

@spec maroon(t()) :: t()

Returns a style with maroon as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

new()

@spec new() :: t()

Returns an empty style (no fg, no bg, no effects).

Examples

iex> Pote.Style.new()
%Pote.Style{fg: nil, bg: nil, effects: []}

olive(style \\ %__MODULE__{})

@spec olive(t()) :: t()

Returns a style with olive as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

on(style \\ %__MODULE__{}, color)

@spec on(t(), color_input()) :: t()

Sets the background color on a style (terminal-idiomatic "on").

Examples

iex> Pote.Style.red() |> Pote.Style.on(:black)
%Pote.Style{fg: {255, 0, 0}, bg: {0, 0, 0}, effects: []}

orange(style \\ %__MODULE__{})

@spec orange(t()) :: t()

Returns a style with orange as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

pink(style \\ %__MODULE__{})

@spec pink(t()) :: t()

Returns a style with pink as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

purple(style \\ %__MODULE__{})

@spec purple(t()) :: t()

Returns a style with purple as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

red(style \\ %__MODULE__{})

@spec red(t()) :: t()

Returns a style with red as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

render(style, text)

@spec render(t(), binary()) :: iodata()

Renders text with the style applied, including the reset sequence.

Examples

iex> Pote.Style.red() |> Pote.Style.render("hi") |> IO.iodata_to_binary()
"hi"

silver(style \\ %__MODULE__{})

@spec silver(t()) :: t()

Returns a style with silver as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

teal(style \\ %__MODULE__{})

@spec teal(t()) :: t()

Returns a style with teal as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

to_ansi(style)

@spec to_ansi(t()) :: iodata()

Returns the ANSI escape sequence for the style as iodata.

The result is a binary suitable to be prepended to text; it does not include the reset sequence (use render/2 for that).

Examples

iex> Pote.Style.red() |> Pote.Style.to_ansi()
""

underline(style \\ %__MODULE__{})

@spec underline(t()) :: t()

Adds the underline effect to the style.

Examples

iex> Pote.Style.bold().effects
[:bold]

violet(style \\ %__MODULE__{})

@spec violet(t()) :: t()

Returns a style with violet as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

white(style \\ %__MODULE__{})

@spec white(t()) :: t()

Returns a style with white as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}

yellow(style \\ %__MODULE__{})

@spec yellow(t()) :: t()

Returns a style with yellow as the foreground color.

Examples

iex> Pote.Style.red().fg
{255, 0, 0}