Overview
TheTheme class provides a declarative visual style system for Kraken TUI. Themes define default styles that cascade to all widgets in a subtree, unless overridden by explicit widget styles.
Key features:
- Global style defaults (colors, text decorations, borders, opacity)
- Per-widget-type style overrides (e.g., all
Inputwidgets use a specific color) - Built-in themes: Dark and Light
- Custom theme creation
- Theme binding to widget subtrees
Explicit widget styles always win over theme defaults (ADR-T12).
Creating Themes
create()
Create a new custom theme with empty defaults.A new theme instance.
dark()
Get a reference to the built-in dark theme.The built-in dark theme (handle = 1).
light()
Get a reference to the built-in light theme.The built-in light theme (handle = 2).
destroy()
Destroy a custom theme and free its resources. Built-in themes (Dark, Light) cannot be destroyed.Global Style Defaults
These methods set style defaults that apply to all widgets in the themed subtree, unless overridden.setForeground()
Set the default foreground (text) color.Color value:
"#RRGGBB": Hex RGB (24-bit true color)"red","blue", etc.: Named colornumber: 256-color palette index (0-255)
setBackground()
Set the default background color.Color value (same format as
setForeground).setBorderColor()
Set the default border color.Color value (same format as
setForeground).setBold()
Set the default bold text decoration.Whether bold is enabled by default.
setItalic()
Set the default italic text decoration.Whether italic is enabled by default.
setUnderline()
Set the default underline text decoration.Whether underline is enabled by default.
setBorderStyle()
Set the default border style.Border style:
"none": No border"single": Single-line box drawing"double": Double-line box drawing"rounded": Rounded corners"bold": Bold/thick lines
setOpacity()
Set the default opacity.Opacity value from 0.0 (fully transparent) to 1.0 (fully opaque).
Per-Widget-Type Defaults
These methods set style defaults for specific widget types (e.g., allInput widgets).
setTypeColor()
Set a color default for a specific widget type.Widget type:
"box": Box container"text": Text display"input": Single-line input"select": Select/dropdown"scrollBox": Scrollable container"textarea": Multi-line text areanumber: RawNodeTypeenum value
Color property:
"fg": Foreground (text) color"bg": Background color"borderColor": Border color
Color value (same format as global colors).
setTypeFlag()
Set a text decoration default for a specific widget type.Widget type (same as
setTypeColor).Text decoration property.
Whether the decoration is enabled.
setTypeBorderStyle()
Set a border style default for a specific widget type.Widget type (same as
setTypeColor).Border style (same as global border style).
setTypeOpacity()
Set an opacity default for a specific widget type.Widget type (same as
setTypeColor).Opacity value from 0.0 to 1.0.
Applying Themes
applyTo()
Apply this theme to a widget subtree. All descendants inherit the theme unless they have their own theme binding.Widget to apply the theme to (and its descendants).
clearFrom()
Remove theme binding from a widget. The widget reverts to inheriting its parent’s theme.Widget to clear the theme from.
Style Resolution Order
When a widget is rendered, styles are resolved in this priority order (highest to lowest):- Explicit widget style (e.g.,
widget.setForeground("red")) - Per-widget-type theme default (e.g.,
theme.setTypeColor("input", "fg", "blue")) - Global theme default (e.g.,
theme.setForeground("white")) - Built-in system default (terminal default colors)
Built-in Themes
Dark Theme
The built-in dark theme provides sensible defaults for dark terminal backgrounds.- Light text on dark backgrounds
- Muted border colors
- Handle: 1 (constant)
Light Theme
The built-in light theme provides sensible defaults for light terminal backgrounds.- Dark text on light backgrounds
- Visible border colors
- Handle: 2 (constant)