Skip to main content

Module theme

Module theme 

Source
Expand description

Role-based theme system. Segments declare semantic roles; themes map roles to colors; the render path emits ANSI SGR around each segment based on the terminal’s detected capability. Full contract in docs/specs/theming.md.

Built-ins compiled in: default (Palette16, terminal-default anchor), minimal (decoration-only), the four Catppuccin flavors, plus Dracula, Nord, Gruvbox, Tokyo Night, and Rose Pine. User themes load from ~/.config/linesmith/themes/*.toml via user::ThemeRegistry.

Re-exports§

pub use style_syntax::parse_style;
pub use style_syntax::StyleParseError;
pub use user::RegisteredTheme;
pub use user::ThemeRegistry;
pub use user::ThemeSource;

Modules§

style_syntax
Style-string parser per docs/specs/theming.md §Style syntax. Accepts whitespace-separated tokens in any order:
user
User-authored theme TOML loading. Parses files from ~/.config/linesmith/themes/*.toml per docs/specs/theming.md §Theme file format and merges them with the compiled-in themes into a ThemeRegistry. The registry is the single source of truth the driver consults for theme = "..." resolution.

Structs§

Style
Text decorations a segment may layer over its theme color. role is the role the segment wants; fg is an explicit color override that wins over role. hyperlink carries an OSC 8 URL that crate::layout::runs_to_ansi wraps around the run’s text when the terminal advertises hyperlink support. bg lives in the spec but isn’t wired through.
StyledRun
Text + style emitted by the layout engine. The flat run sequence is what crate::layout::render_to_runs returns: one run per segment plus one run per non-empty inter-segment separator. Consumers map runs to their target surface — ANSI SGR for terminal stdout, ratatui Span for the TUI preview pane — without re-parsing escape sequences.
Theme
Named color palette keyed by Role. colors[role as usize] is either Some(color) when the theme defines it or None so Theme::color falls back via Role::fallback. Fields stay crate-private so callers can’t mint themes with arbitrary names or bypass the fallback contract; user-authored themes will go through a validated constructor when TOML loading lands.

Enums§

AnsiColor
Standard 16-color ANSI palette. Stored as the foreground base (30..=37 for normal, 90..=97 for bright); we add offsets at emit time.
Capability
Terminal color capability detected from the environment. Truecolor is preferred when available; None strips all color and keeps only decorations.
Color
Concrete color value a theme resolves a role to.
Role
Semantic color slot a segment targets. Themes map every role to a concrete color; segments never reference hex values directly. Variants are ordered to match the 16-slot role array themes store.

Functions§

built_in
Look up a built-in theme by name. Unknown names return None so callers can warn and fall back to default.
builtin_names
Names of all compiled-in themes, in registration order.
default_theme
The default theme when config names none (or names an unknown one). Guaranteed to exist.
sgr_open
Emit the ANSI SGR prefix for style under cap. Returns an empty string when the style is plain or the capability is None with no decorations.
sgr_reset
SGR reset. Emitted after every styled span so color and decorations don’t leak across segment boundaries.