TermUI.Style (TermUI v0.2.0)
View SourceStyle system for consistent visual presentation.
Styles define colors, text attributes, and visual properties for components. Styles are immutable—modifications return new styles.
Color Types
- Named colors:
:black,:red,:green,:yellow,:blue,:magenta,:cyan,:white - Bright variants:
:bright_black,:bright_red, etc. - Indexed (256):
{:indexed, 0..255} - RGB (true color):
{:rgb, r, g, b}
Examples
# Build a style
style = Style.new()
|> Style.fg(:blue)
|> Style.bg(:white)
|> Style.bold()
|> Style.underline()
# Merge styles
merged = Style.merge(base, override)
# Inherit from parent
effective = Style.inherit(child, parent)
# Variants
variants = %{
normal: Style.new() |> Style.fg(:white),
focused: Style.new() |> Style.fg(:blue) |> Style.bold()
}
style = Style.get_variant(variants, :focused)
Summary
Functions
Sets the background color.
Adds blink attribute.
Adds bold attribute.
Builds a complete variant map from partial definitions.
Clears all attributes.
Converts color for a specific terminal capability.
Creates a variant that inherits from the normal variant.
Adds dim attribute.
Sets the foreground color.
Creates a style from a keyword list or map.
Gets a variant style from a variant map.
Checks if style has an attribute.
Adds hidden attribute.
Inherits unset properties from parent style.
Adds italic attribute.
Merges two styles, with the second overriding the first.
Creates a new style with default values.
Removes an attribute from the style.
Resets style to defaults, breaking inheritance.
Adds reverse attribute.
Converts RGB to nearest 256-color palette index.
Returns a semantic color.
Adds strikethrough attribute.
Converts any color to nearest 16-color.
Converts any color to RGB tuple.
Adds underline attribute.
Types
@type attr() ::
:bold
| :dim
| :italic
| :underline
| :blink
| :reverse
| :hidden
| :strikethrough
@type color() :: named_color() | indexed_color() | rgb_color()
@type indexed_color() :: {:indexed, 0..255}
@type named_color() ::
:black
| :red
| :green
| :yellow
| :blue
| :magenta
| :cyan
| :white
| :bright_black
| :bright_red
| :bright_green
| :bright_yellow
| :bright_blue
| :bright_magenta
| :bright_cyan
| :bright_white
| :default
@type rgb_color() :: {:rgb, 0..255, 0..255, 0..255}
Functions
Sets the background color.
Adds blink attribute.
Adds bold attribute.
Builds a complete variant map from partial definitions.
Each variant inherits from :normal.
Clears all attributes.
Converts color for a specific terminal capability.
:true_color- returns as-is:color_256- converts to indexed:color_16- converts to named
Creates a variant that inherits from the normal variant.
Only non-nil values in the variant override the normal style.
Adds dim attribute.
Sets the foreground color.
Creates a style from a keyword list or map.
Examples
Style.from(fg: :blue, bg: :white, bold: true)
Gets a variant style from a variant map.
Falls back to :normal if variant not found.
Checks if style has an attribute.
Inherits unset properties from parent style.
Unlike merge, this only fills in nil values from parent.
Adds italic attribute.
Merges two styles, with the second overriding the first.
Only non-nil values from the override style replace base values. Attributes are combined.
@spec new() :: t()
Creates a new style with default values.
Removes an attribute from the style.
Resets style to defaults, breaking inheritance.
Adds reverse attribute.
Converts RGB to nearest 256-color palette index.
Returns a semantic color.
These can be overridden by themes.
Adds strikethrough attribute.
@spec to_named(color()) :: named_color()
Converts any color to nearest 16-color.
Converts any color to RGB tuple.
Adds underline attribute.