Expand description
The host Theme + its SyntaxStyle → visual style mapping.
The renderer-neutral primitives — Color, Style,
Modifiers, NamedColor, the rich-vocabulary attribute types,
and parse_color — live in the leaf crate lattice-theme and
are re-exported here so every existing lattice_host::ui::theme
/ host_theme call site is unchanged (T.1, theme-system slice
plan). 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);
the host owns the canonical theme, each renderer maintains a
cached adapted view for hot-path reads.
The SyntaxStyle → visual style bridge (resolve_syntax_style /
syntax_element_id) moved DOWN to lattice-syntax at DX.2 (BC.6
diff extraction) and is re-exported here unchanged — see the
re-export note below. The element registry + palette + resolution
(lattice-theme T.2/T.3) subsume the old flat struct; renderers read
the resolved table via ResolvedTheme + BuiltinElementIds. See
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. - 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. - 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.
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. - 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. - resolve_
syntax_ style - Resolve a syntax category to its concrete
lattice_theme::Stylevia the resolved table. The replacement for the deletedTheme::syntax_stylecolormatch— colors now flow from the active theme’s palette through the resolved table. Every syntax consumer (cell builder, display-line paths, diff overlay) calls this, then adapts the hostStyleto its renderer-native form. - syntax_
element_ id - Map a
Stylesyntax category to its builtinsyntax.*ElementId. The single source of the syntax→element mapping, shared by the cell builder, both renderers’ display-line paths, and the diff overlay.
Type Aliases§
- Theme
Registry Handle - The canonical handle type. Register and look up under THIS type in the ServiceRegistry ([[feedback_servicesregistry_arc_typeid]]).