Skip to main content

Module theme

Module theme 

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

DefaultTextStyle
Default text styling applied to body content (not backgrounds).
MarkdownOptions
Markdown parse options.
MarkdownTheme
Theme functions for markdown elements (ANSI wrappers).
ResolvedTheme
A fully resolved product theme: ANSI emitters for every slot plus mode.
Rgb
One resolved color: an 8-bit-per-channel RGB triple.
ThemeJson
Parsed (not yet resolved) theme document.

Enums§

ColorMode
Terminal color depth selected at startup.
ThemeBg
Product background color slots (see reference ThemeBg).
ThemeColor
Product foreground/text color slots (see reference ThemeColor).
ThemeError
Errors produced while loading or validating a theme JSON document.

Constants§

ALL_BG
All background slots in schema order.
ALL_FG
All foreground slots in schema order.

Functions§

bold
Bold text (\x1b[1m…\x1b[22m).
current
Clone the current thread-local theme (None installed ⇒ built-in dark).
dark
Built-in dark theme (interned). Mirrors dark.json with 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.json with 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) -> String for color that resolves against current() at call time.
markdown_theme
Build a markdown theme from current(). Mirrors getMarkdownTheme().
rgb_to_256
Map an RGB triple to the nearest 256-color palette index.
select_list_theme
Select-list theme from current(). Mirrors getSelectListTheme().
set_current
Permanently install theme as this thread’s current theme.
settings_list_theme
Settings-list theme from current(). Mirrors getSettingsListTheme().
strikethrough
Strikethrough text.
truncate_line
Helper to truncate a single line to width with an ellipsis.
underline
Underline text.
user_markdown_options
Markdown options matching the user-message renderer.
with_theme
Install theme as the thread-local current theme for the duration of f.