smalto/ansi_theme

ANSI terminal color themes for syntax highlighting.

An AnsiTheme maps token types to styling functions that transform plain text into ANSI-colored output. Use default() for the built-in color scheme, or build a custom theme with new() and per-token setters.

Example

import gleam_community/ansi
import smalto/ansi_theme

let theme =
  ansi_theme.new()
  |> ansi_theme.keyword(ansi.yellow)
  |> ansi_theme.string(ansi.green)
  |> ansi_theme.comment(fn(v) { ansi.italic(ansi.gray(v)) })

Types

A theme that maps token types to ANSI styling functions.

Each entry maps a token category to a function fn(String) -> String that applies terminal color codes. Tokens not present in the theme are rendered without styling.

pub opaque type AnsiTheme

Values

pub fn attribute(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for attribute tokens.

pub fn builtin(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for builtin tokens.

pub fn comment(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for comment tokens.

pub fn constant(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for constant tokens.

pub fn custom(
  theme: AnsiTheme,
  name: String,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for a custom token by name.

pub fn default() -> AnsiTheme

Create the default theme matching smalto’s built-in color scheme.

pub fn function(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for function tokens.

pub fn get(
  theme: AnsiTheme,
  token: token.AnsiToken,
) -> fn(String) -> String

Look up the styling function for a token type.

Returns the identity function if the token has no style in the theme.

pub fn keyword(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for keyword tokens.

pub fn module(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for module tokens.

pub fn new() -> AnsiTheme

Create an empty theme where all tokens are unstyled.

pub fn number(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for number tokens.

pub fn operator(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for operator tokens.

pub fn other(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for other (unmatched) tokens.

pub fn property(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for property tokens.

pub fn punctuation(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for punctuation tokens.

pub fn regex(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for regex tokens.

pub fn selector(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for selector tokens.

pub fn string(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for string tokens.

pub fn tag(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for tag tokens.

pub fn type_(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for type tokens.

pub fn variable(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for variable tokens.

pub fn whitespace(
  theme: AnsiTheme,
  style: fn(String) -> String,
) -> AnsiTheme

Set the styling function for whitespace tokens.

Search Document