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§
- Builtin
Element Ids - The interned
ElementIds for the builtin elements the renderers read, captured once at boot from theThemeRegistryand held for the process lifetime.Copy+ small, so it snapshots intoRenderStateper publish for free; a read is thenresolved.get(ids.<elem>)— an array index, no per-frame name lookup (design §7). - Element
Id - 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. - Element
Info - Introspection snapshot for a single registered element, returned
by
ThemeRegistry::describeand rendered by:describe-element(T.9.d). Bundles the element’s identity + owner + authoring (reference-form)StyleSpecdefault + doc string + its concrete resolvedStyleunder the active theme — everything the help view needs in one read, no second registry round-trip. - Element
Name - 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. - Family
Id - 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
Stylecan name a family without the theme crate depending on a font stack. - Font
Scale - Relative font-height multiplier, stored as hundredths
(
100= 1.0×,160= 1.6×). Fixed-point rather thanf32soStylestaysEq + Hash(the theme is content-hashed into the cell-matrix version). An authoringStyleSpeccarries anf32ratio; resolution quantizes it here. - InMemory
Theme Registry - In-memory
ThemeRegistry. Holds the element table + active palette behind anRwLock, and the resolved read table behind anArcSwapfor lock-free reads. - Modifier
Set - Tri-state modifier set:
Some(true)sets,Some(false)clears,Noneinherits. 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.
- Named
Theme - 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.
StyleSpeccolors reference these by key; resolution looks them up here. - Palette
Key - A palette entry’s name (
"purple","ansi.red","diff.add.bg"). - Resolved
Theme - The flat, resolved read table for the active theme.
styles[id]is the fully-resolvedStylefor elementid. Rebuilt on theme/palette change; published viaArcSwapso 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).Nonefor fg/bg means “do not set this channel” (matches ratatui’s empty-style semantics and GPUI’sStyle::transparent_blackbackground semantics). - Style
Spec - 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 concreteStyle. - Theme
Element - 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:
Defaultfor “use the terminal/window’s default”,Namedfor the 16 ANSI palette names (TUI’s 16-color fallback path),Indexedfor the 256-color palette,Rgbfor 24-bit truecolor. - Color
Ref - A color by reference.
Paletteis the normal path;Literalis the escape hatch for a one-off a palette entry would over-generalize;Defaultmeans the terminal/window default channel. - Element
Owner - Who owns an element (and thus owns its default styling). Core elements ship with the editor; modes/plugins register their own.
- Named
Color - The 16 named ANSI colors. Order matches ratatui’s
Color::Black..Whiteenumeration so the adapter is a straightforward variant-by-variant match. - Weight
- Font weight, finer-grained than the
boldModifiersflag. Maps onto the GPUI peer’s font-weight axis; the TUI renders any weight atSemiBoldor heavier as its bold attribute.
Traits§
- Theme
Registry - 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.
:colorschemematchesnamecase-sensitively against this list. The first entry (catppuccin-mocha) is the boot default — its palette equalsdefault_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. Theansi.*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 EXCEPTcursor_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/resetfor terminal-default, and 6-digit hex (#cba6f7orcba6f7, 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 theunknown colorerror 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§
- Theme
Registry Handle - The canonical handle type. Register and look up under THIS type in the ServiceRegistry ([[feedback_servicesregistry_arc_typeid]]).