Skip to main content

Module theme

Module theme 

Source
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§

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.
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.
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.

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.
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.
resolve_syntax_style
Resolve a syntax category to its concrete lattice_theme::Style via the resolved table. The replacement for the deleted Theme::syntax_style color match — 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 host Style to its renderer-native form.
syntax_element_id
Map a Style syntax category to its builtin syntax.* 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§

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