Atui.Style (Atui v0.1.0)

Copy Markdown View Source

Colour and text attributes for a cell.

A style is data, not escape codes: views build %Atui.Style{} structs and the screen turns runs of equally-styled cells into SGR sequences when it renders. That keeps views comparable — two frames differ when their styles differ, not when someone reordered the escape codes.

Style.new(fg: :bright_cyan, bold: true)
Style.new(fg: 208, bg: :black)            # 256-colour palette
Style.new(fg: {:rgb, 255, 128, 0})        # truecolor

Colours are a named colour (:red, :bright_red, …), an integer 0..255 from the 256-colour palette, or {:rgb, r, g, b}.

Summary

Functions

The terminal's own colours and attributes — renders as no escape codes.

True when the style asks for nothing (nil counts as default).

Builds a style; see the module docs for the accepted colours.

The sequence returning the terminal to its default style.

The SGR sequence that turns this style on, or "" for the default.

The escape codes to move from previous to next.

Types

color()

@type color() :: atom() | 0..255 | {:rgb, 0..255, 0..255, 0..255} | nil

t()

@type t() :: %Atui.Style{
  bg: color(),
  bold: boolean(),
  dim: boolean(),
  fg: color(),
  italic: boolean(),
  reverse: boolean(),
  underline: boolean()
}

Functions

default()

The terminal's own colours and attributes — renders as no escape codes.

default?(style)

True when the style asks for nothing (nil counts as default).

new(opts \\ [])

Builds a style; see the module docs for the accepted colours.

reset()

The sequence returning the terminal to its default style.

to_ansi(style)

The SGR sequence that turns this style on, or "" for the default.

transition(previous, next)

The escape codes to move from previous to next.

Styles are absolute rather than incremental, so any change resets first — a cell's appearance never depends on what was drawn before it.