Skip to content

API turboframe.ui.themes

rafageist edited this page Dec 4, 2026 · 5 revisions

turboframe.ui.themes

Source: turboframe/ui/themes.py. Generated from the code of TurboFrame 0.3.0 by tools/wiki_api.py.

Colour themes: every colour a Turbo Vision desktop draws, in one place.

A theme (Palette) has four parts:

  • ansi: its 16 colours, by the names of the BIOS text-mode slots (black, blue, ... yellow, white). File marks and the Borland themes speak in slots.
  • chrome: the Textual theme of textual-vision's widgets (menus, dialogs, buttons, frames, status line). The Borland themes are textual-vision's own.
  • ui: the roles of the desktop's windows (desktop, editor, output, debug and help windows, lists, progress bar, shadow...). Each is a slot name or a #RRGGBB; the CSS sees them as $tf-<role> and the code asks palette.colour(role).
  • syntax: the colours of the syntax roles (keyword, variable, string...). TOKENS says which role, and which attributes, each token kind takes, the same in every theme: a theme only chooses colours.

TurboFrame registers only the token kinds it draws itself (diagnostics and diffs). An application registers its own with token() when it starts (its lexer's or tree-sitter's names), and its phosphor attributes in PHOSPHOR_ATTRS. An application whose CSS says $myapp-<role> calls add_css_alias("myapp") and keeps it.

Colours are written in full RGB; Textual (through Rich) sends them as the terminal can show them: true colour, the 256-colour cube or the 16 ANSI colours (set_ansi16), by what the terminal says it supports.

Contents

CGA, CSS_PREFIX, DEFAULT, DEPTHS, DEPTH_LABELS, PHOSPHORS, PHOSPHOR_ATTRS, SLOTS, SYNTAX_ROLES, THEMES, TOKENS, UI_ROLES, Palette, Phosphor, add_css_alias, ansi16, current, get, recolour, set_ansi16, token, treesitter_tokens, use

CGA

dict (16 entries)

CSS_PREFIX

'tf'

DEFAULT

'turbo-pascal'

DEPTHS

{'auto': 'auto', 'truecolor': 'truecolor', '256': '256', '16': 'standard'}

DEPTH_LABELS

dict (4 entries)

PHOSPHORS

dict (5 entries)

PHOSPHOR_ATTRS

{'diag.error': {'bold': True}, 'diag.warning': {'underline': True}, 'diff.del': {'strike': True}}

SLOTS

tuple (16 entries)

SYNTAX_ROLES

tuple (41 entries)

THEMES

dict (9 entries)

TOKENS

dict (7 entries)

UI_ROLES

tuple (67 entries)

class Palette

class Palette
Palette(name: str, label: str, description: str, ansi: Mapping[str, str], chrome: Theme, ui: Mapping[str, str], syntax: Mapping[str, str], ansi16_slots: tuple[str, ...] | None = None, token_attrs: Mapping[str, Mapping[str, bool]] = <factory>, marks: bool = False, menu_active: str | None = None, hotkey_style: str = 'none', _styles: dict = <factory>)

Palette(name: 'str', label: 'str', description: 'str', ansi: 'Mapping[str, str]', chrome: 'Theme', ui: 'Mapping[str, str]', syntax: 'Mapping[str, str]', ansi16_slots: 'tuple[str, ...] | None' = None, token_attrs: 'Mapping[str, Mapping[str, bool]]' = , marks: 'bool' = False, menu_active: 'str | None' = None, hotkey_style: 'str' = 'none', _styles: 'dict' = )

  • hex(colour: str) -> str: A slot name or a #RRGGBB, as #RRGGBB (as the terminal's 16 colours, when that is all it has: see set_ansi16).
  • slot_of(value: str) -> str: The slot of this palette a #RRGGBB is, or is nearest to.
  • slot16_of(value: str) -> str: The slot value becomes with 16 colours: its own (slot_of), or for a monochrome theme the nearest of the few it may use, by light (so it stays one hue, never another).
  • snap(value: str) -> str: value as its slot's CGA colour: Rich sends exactly that ANSI colour.
  • colour(role: str) -> str: The #RRGGBB of a UI role (or a syntax role).
  • style(fg: str | None = None, bg: str | None = None, **attrs: bool) -> Style: A Rich style from roles.
  • token_styles() -> dict[str, Style]: Token kind -> style, for the editor and everything that shows code.
  • textual_theme() -> Theme: The chrome, with the roles as $tf-<role> variables (and as $<alias>-<role>, for each add_css_alias).

class Phosphor

class Phosphor
Phosphor(bg: str, panel: str, raised: str, mid: str, dim: str, text: str, bright: str, max: str, slots16: tuple[str, ...])

Phosphor(bg: 'str', panel: 'str', raised: 'str', mid: 'str', dim: 'str', text: 'str', bright: 'str', max: 'str', slots16: 'tuple[str, ...]')

add_css_alias

def add_css_alias(prefix: str) -> None

The roles are $<prefix>-<role> too, for an application whose CSS already says so.

ansi16

def ansi16() -> bool

current

def current() -> Palette

The palette of the running app (one app runs at a time).

get

def get(name: str | None) -> Palette

recolour

def recolour(theme: Theme, table: Mapping[str, str], name: str) -> Theme

theme (in CGA colours) with each CGA colour replaced by its slot in table.

set_ansi16

def set_ansi16(only16: bool) -> None

With 16 colours, each colour goes to the slot it stands for in its palette (Campbell's light green stays light green, modern-dark's surfaces black), not to the ANSI colour nearest in RGB, which loses what it meant.

token

def token(fg: str | None, *kinds: str, bg: str | None = None, **attrs: bool) -> None

Each of kinds takes the syntax role fg (and bg) and attrs (bold, italic...).

treesitter_tokens

def treesitter_tokens(prefix: str = '') -> None

Register the capture names of Textual's tree-sitter highlight queries (Python, XML, HTML, JavaScript, CSS, JSON, YAML, TOML, Markdown, SQL, Bash...) as token kinds, each with its syntax role, prefix before each name (an application whose own highlighter renames them: "ts."). turboframe.ui.editor registers them without a prefix.

use

def use(name: str) -> Palette

Clone this wiki locally