Back to Projects
TUIX v0.1Alpha

Last Updated: 2026-05-20

Styles API Reference

Full API reference for the Styles class, accessible via engine.styles.

set_type(type: str)

Sets the rendering type. Valid values: 'adaptive', 'strict'. Raises ValueError for unknown types.

set_style(style: str)

Switches the active preset style. The default preset is 'classic'. Additional presets can be registered with define_style(). Raises ValueError for unknown styles.

set_custom_style(*, key, option=None, value)

Overrides a single style property. The behavior depends on the key:

Key CategoryKeysAccepted Values
RGB-onlybackground, prompt_background, border, text_color, unselected_text, selected_background, selected_textRGB tuple (r, g, b)
Bool/RGBshadow, text_background, unselected_backgroundFalse, or RGB tuple. shadow also accepts True (auto-computes blend)
OptionstextRequires option param ('bold', 'italic', 'underline', 'dim') + bool value

Automatically triggers style cache rebuild.

remove_custom_style(key, option=None)

Resets custom overrides back to None (falling through to preset values). Accepts a single key string or list of keys. For the 'text' key, pass option as a string or list of option names.

engine.styles.remove_custom_style('border')
engine.styles.remove_custom_style(['shadow', 'selected_text'])
engine.styles.remove_custom_style('text', option=['bold', 'dim'])

define_style(*, name, config)

Registers a new preset style. The config dict must have exactly the same keys as the classic preset. Raises ValueError if keys don't match. The name must not conflict with an existing preset.

cached_styles

A read-only dictionary containing the fully resolved styles (preset + custom overrides merged). This is what the RenderEngine reads when drawing components. Updated automatically by _cache_styles() after any style change.

Utility Functions

These module-level functions support the style system:

FunctionSignatureDescription
text_colortext_color(r, g, b) -> strReturns ANSI escape code for 24-bit foreground color
background_colorbackground_color(r, g, b) -> strReturns ANSI escape code for 24-bit background color
is_rgbis_rgb(value) -> boolValidates that value is a 3-tuple of ints/floats in range 0–255
blend_shadowblend_shadow(bg, fg, intensity=0.3) -> tupleBlends two RGB colors for shadow effects
visual_widthvisual_width(s) -> intReturns display width of string using wcwidth (handles CJK, emoji)