Expand description
Product theme: resolved colors, built-in defaults, JSON loading, and conversion to pi-tui component themes.
Ports .references/pi/packages/coding-agent/src/modes/interactive/theme/
(theme.ts, dark.json, light.json). The reference uses a global
singleton theme; pi-tui component themes take fn(&str) -> String hooks
that cannot capture state, so this module mirrors the singleton with a
thread-local current Arc<ResolvedTheme> that the fn-pointer color
helpers read. Built-in themes are LazyLock interns; loaded themes are
returned as owned Arc handles (no leaks).
§Fallibility
ThemeJson validates structure. ThemeJson::resolve fails on missing
colors, bad hex, unknown variable references, or circular variable chains.
The view-model falls back to the built-in dark theme on any error so a bad
theme.json never breaks the terminal — see dark and the
theme_invalid_falls_back_to_dark test.
Structs§
- Default
Text Style - Default text styling applied to body content (not backgrounds).
- Markdown
Options - Markdown parse options.
- Markdown
Theme - Theme functions for markdown elements (ANSI wrappers).
- Resolved
Theme - A fully resolved product theme: ANSI emitters for every slot plus mode.
- Rgb
- One resolved color: an 8-bit-per-channel RGB triple.
- Theme
Json - Parsed (not yet resolved) theme document.
Enums§
- Color
Mode - Terminal color depth selected at startup.
- ThemeBg
- Product background color slots (see reference
ThemeBg). - Theme
Color - Product foreground/text color slots (see reference
ThemeColor). - Theme
Error - Errors produced while loading or validating a theme JSON document.
Constants§
Functions§
- bold
- Bold text (
\x1b[1m…\x1b[22m). - current
- Clone the current thread-local theme (
Noneinstalled ⇒ built-in dark). - dark
- Built-in dark theme (interned). Mirrors
dark.jsonwith vars resolved. - default_
text_ style - Default text style for assistant body markdown (no decoration).
- inverse
- Inverse video.
- italic
- Italic text.
- light
- Built-in light theme (interned). Mirrors
light.jsonwith vars resolved. - load_
by_ name - Load a theme by name from the configured theme directories.
- load_
or_ dark - Load a theme, falling back to the built-in dark theme on any error.
- make_fg
- Build a foreground
fn(&str) -> Stringforcolorthat resolves againstcurrent()at call time. - markdown_
theme - Build a markdown theme from
current(). MirrorsgetMarkdownTheme(). - rgb_
to_ 256 - Map an RGB triple to the nearest 256-color palette index.
- select_
list_ theme - Select-list theme from
current(). MirrorsgetSelectListTheme(). - set_
current - Permanently install
themeas this thread’s current theme. - settings_
list_ theme - Settings-list theme from
current(). MirrorsgetSettingsListTheme(). - strikethrough
- Strikethrough text.
- truncate_
line - Helper to truncate a single line to
widthwith an ellipsis. - underline
- Underline text.
- user_
markdown_ options - Markdown options matching the user-message renderer.
- with_
theme - Install
themeas the thread-local current theme for the duration off.