Skip to main content

Crate lattice_theme

Crate lattice_theme 

Source
Expand description

Renderer-neutral theme primitives.

The Color / Style / Modifiers / NamedColor value types, the rich-vocabulary attribute types (FontScale / Weight / FamilyId), and the parse_color helper. Every type here is pure data with no renderer-specific dependency. Renderer crates (lattice-ui-tui, lattice-ui-gpui) ship adapters that convert these into their native style types (ratatui Style / Color, GPUI Hsla + per-run font shaping).

Until T.1 (theme-system slice plan) these lived in lattice-host/src/ui/theme.rs; they moved here so cells, modes, the host, and both renderers share one definition. The host re-exports them from their old path so existing call sites are unchanged. The element registry + palette + resolution land here next (T.2/T.3).

Design: docs/dev/architecture/theme-system.md.

Structs§

BuiltinElementIds
The interned ElementIds for the builtin elements the renderers read, captured once at boot from the ThemeRegistry and held for the process lifetime. Copy + small, so it snapshots into RenderState per publish for free; a read is then resolved.get(ids.<elem>) — an array index, no per-frame name lookup (design §7).
ElementId
Interned, process-stable index for a registered theme element. Allocated at registration; the hot-path read is resolved.get(id) — an array index, no string hashing.
ElementInfo
Introspection snapshot for a single registered element, returned by ThemeRegistry::describe and rendered by :describe-element (T.9.d). Bundles the element’s identity + owner + authoring (reference-form) StyleSpec default + doc string + its concrete resolved Style under the active theme — everything the help view needs in one read, no second registry round-trip.
ElementName
A theme element’s dotted, hierarchical name (markdown.heading.1). Fallback walks the dotted parents (markdown.heading.1 → markdown.heading → markdown) when the more-specific element is unstyled by the active theme.
FamilyId
An interned font-family selector. The name→id interning + the id→family resolution live with the renderer-side font table (T.10); the id is renderer-neutral so a Style can name a family without the theme crate depending on a font stack.
FontScale
Relative font-height multiplier, stored as hundredths (100 = 1.0×, 160 = 1.6×). Fixed-point rather than f32 so Style stays Eq + Hash (the theme is content-hashed into the cell-matrix version). An authoring StyleSpec carries an f32 ratio; resolution quantizes it here.
InMemoryThemeRegistry
In-memory ThemeRegistry. Holds the element table + active palette behind an RwLock, and the resolved read table behind an ArcSwap for lock-free reads.
ModifierSet
Tri-state modifier set: Some(true) sets, Some(false) clears, None inherits. Inheritance can therefore clear a parent’s bold, not only add — emacs faces distinguish “unspecified” from “off”.
Modifiers
Text-attribute modifiers. Bools rather than bitflags so a new modifier (strikethrough, blink, …) is a struct-field add instead of a flag-byte expansion; the renderers’ adapter code pattern-matches against the explicit field set rather than chasing flag bits.
NamedTheme
A named theme: a palette + a (possibly empty) element-override set. The unit a :colorscheme <name> swap resolves to.
Palette
A named set of base colors. StyleSpec colors reference these by key; resolution looks them up here.
PaletteKey
A palette entry’s name ("purple", "ansi.red", "diff.add.bg").
ResolvedTheme
The flat, resolved read table for the active theme. styles[id] is the fully-resolved Style for element id. Rebuilt on theme/palette change; published via ArcSwap so the renderer’s read is lock-free.
Style
A single style: optional foreground + optional background + modifiers (bold/italic/etc) + the rich-vocabulary attributes (scale / family / weight). None for fg/bg means “do not set this channel” (matches ratatui’s empty-style semantics and GPUI’s Style::transparent_black background semantics).
StyleSpec
How an element is styled, by reference. The form a mode default, a theme override, or a buffer-local remap is written in. Resolution (crate::registry) produces a concrete Style.
ThemeElement
A registered theme element: identity + metadata + the owner-supplied default (itself a reference-form StyleSpec).

Enums§

Color
Renderer-neutral color. The variants cover every shape any terminal-or-GPU renderer ever needs: Default for “use the terminal/window’s default”, Named for the 16 ANSI palette names (TUI’s 16-color fallback path), Indexed for the 256-color palette, Rgb for 24-bit truecolor.
ColorRef
A color by reference. Palette is the normal path; Literal is the escape hatch for a one-off a palette entry would over-generalize; Default means the terminal/window default channel.
ElementOwner
Who owns an element (and thus owns its default styling). Core elements ship with the editor; modes/plugins register their own.
NamedColor
The 16 named ANSI colors. Order matches ratatui’s Color::Black..White enumeration so the adapter is a straightforward variant-by-variant match.
Weight
Font weight, finer-grained than the bold Modifiers flag. Maps onto the GPUI peer’s font-weight axis; the TUI renders any weight at SemiBold or heavier as its bold attribute.

Traits§

ThemeRegistry
Registration + resolution surface. Lives as a ServiceRegistry service (T.3); modes reach it through the handle, never through &mut Editor.

Functions§

builtin_themes
Every builtin theme, by name. :colorscheme matches name case-sensitively against this list. The first entry (catppuccin-mocha) is the boot default — its palette equals default_palette, so swapping to it is a no-op restore.
default_palette
The default palette (Catppuccin Mocha accents + ANSI chrome + tints). See module docs for why all three families exist.
macchiato_palette
The Catppuccin Macchiato palette (T.9.b). Same key SET as default_palette — every element references the same keys — but the accent RGB values are Macchiato’s. The ansi.* named entries stay IDENTICAL to mocha’s: the chrome’s degradation-on-16-color intent is theme-independent, so a colorscheme swap must not flip a named ANSI entry to a truecolor. The one-off tints also stay identical EXCEPT cursor_line.bg, which Macchiato carries as a distinct RGB tint matching its lighter surface.
parse_color
Parse a user-typed color name into a Color. Accepts the 16 ANSI names (lowercase + dark-prefixed variants), default / reset for terminal-default, and 6-digit hex (#cba6f7 or cba6f7, case-insensitive) → Color::Rgb. T.9.c: hex unblocks a theme/:set ui.* author writing a one-off truecolor without a palette entry. A #-prefixed string that is NOT exactly 6 hex digits, or any other unknown word, returns the unknown color error rather than guessing.
register_builtins
Register every core element with its palette-referencing default. Idempotent (safe to call once at boot). The defaults reproduce today’s Theme::default() + syntax_style() values exactly — the resolved table is byte-identical to the legacy literals (the parity pin), while every color goes through the palette.

Type Aliases§

ThemeRegistryHandle
The canonical handle type. Register and look up under THIS type in the ServiceRegistry ([[feedback_servicesregistry_arc_typeid]]).