Skip to content

Tokens

Tokens are the semantic layer between raw palette colors and composed styles. They give meaning to colors: accent.primary means "the main accent color" regardless of whether it's purple, blue, or green.

Token Namespaces

Opaline's core token contract defines 28 tokens across 6 namespaces:

Text

TokenPurpose
text.primaryMain body text
text.secondaryLess prominent text
text.mutedDe-emphasized text
text.dimVery subtle text

Background

TokenPurpose
bg.baseMain canvas: the color an app paints the whole screen with
bg.highlightHighlighted or hovered line background
bg.panelSidebars, secondary panes, status areas
bg.codeCode block background
bg.elevatedRaised surfaces: popups, modals, dropdowns
bg.activeActive or pressed element background
bg.selectionSelection background

The bg.* tokens form a layering ladder. bg.base is the surface everything else sits on, and bg.highlight, bg.elevated, and bg.active step progressively toward the text color so each layer reads as closer to the viewer. bg.panel is one step away from bg.base in whichever direction the source palette prefers: SilkCircuit and Rose Pine raise panels slightly lighter, while Catppuccin and Kanagawa recess them slightly darker, matching how those palettes treat sidebars upstream.

Accent

TokenPurpose
accent.primaryMain accent (keywords, active states)
accent.secondarySecondary accent (functions, links)
accent.tertiaryThird accent (types, special elements)
accent.deepDeep/saturated accent for emphasis

Status

TokenPurpose
successSuccess states
errorError states
warningWarning states
infoInformational states

Border

TokenPurpose
border.focusedFocused panel border
border.unfocusedUnfocused panel border

Code

TokenPurpose
code.keywordLanguage keywords
code.functionFunction names
code.stringString literals
code.numberNumeric literals
code.commentComments
code.typeType names
code.line_numberLine numbers

Accessing Tokens

rust
let theme = opaline::Theme::default();

// Get a resolved color (falls back to neutral gray if missing)
let color = theme.color("accent.primary");

// Strict lookup: None if missing
let color = theme.try_color("accent.primary");

// Check existence
if theme.has_token("accent.primary") {
    // ...
}

// List all token names
let names = theme.token_names();

Name Constants

Use the names module for autocomplete-friendly constants instead of raw strings:

rust
use opaline::names::{tokens, styles, gradients};

let accent = theme.color(tokens::ACCENT_PRIMARY);
let bg = theme.color(tokens::BG_BASE);
let kw = theme.style(styles::KEYWORD);
let has_aurora = theme.has_gradient(gradients::AURORA);

All 28 required tokens, 14 required styles, and 5 required gradients have corresponding constants.

App-Specific Tokens

Git status colors, diff colors, mode indicators, file path/hash colors, and similar domain-specific semantics are intentionally not part of Opaline's core contract. Consumer apps should derive those from the generic token set with register_default_token() / register_default_style().

Token Resolution

Tokens resolve through the palette. A token value is a palette key:

toml
[palette]
electric_purple = "#e135ff"

[tokens]
"accent.primary" = "electric_purple"  # → OpalineColor(225, 53, 255)

Tokens can also reference other tokens (transitive resolution):

toml
[tokens]
"accent.primary" = "electric_purple"
"code.keyword" = "accent.primary"     # → also resolves to #e135ff

The resolver detects circular references and reports them as errors.

Released under the MIT License.