Localize.Message.Formatter.ANSI (Localize v0.25.0)

Copy Markdown View Source

ANSI terminal formatter for MF2 highlight tokens.

Wraps each token in ANSI colour escape codes suitable for IEx output, mix task messages, or anywhere a terminal is assumed. Colours are chosen for legibility on both light and dark backgrounds using ANSI 4-bit colours only (no truecolor).

Summary

Functions

Renders a token list as an ANSI-coloured string.

Types

options()

@type options() :: [
  {:palette, %{required(Localize.Message.Highlighter.class()) => [atom()]}}
]

Functions

render(tokens, options \\ [])

Renders a token list as an ANSI-coloured string.

Arguments

  • tokens is a list of t:Highlighter.token/0 tuples.

  • options is a keyword list.

Options

  • :palette — a map %{class => [ansi_atom]} overriding the default colour for specific classes.

Returns

  • A string containing ANSI escape codes.