Skip to content

Themes and Colors

rafageist edited this page Dec 2, 2026 · 3 revisions

Themes and Colors

Use it for the look of the whole desktop, colours in your own widgets, Options > Colors, shadows, file marks
Import from turboframe.ui import themes, icons, shadow; from turboframe.ui.colors import ColorsMixin
Needs nothing beyond TurboFrame
Extend $tf-* roles in your CSS; themes.token() for your token kinds; colors_sample(); icons.BY_EXTENSION

The themes

Nine palettes (turboframe.ui.themes.THEMES), each a full Turbo Vision look:

Name
turbo-pascal (the default) Turbo Vision's colours: gray menus, blue windows, yellow text
turbo-c Turbo C 2.01's: as Turbo Pascal, white-on-black menu hotkeys
free-pascal Turbo Vision's layout in Windows Terminal's Campbell colours
modern-dark deep grays, light text and a blue accent, high contrast
phosphor-white, phosphor-green, phosphor-green-black, phosphor-amber, phosphor-amber-black monochrome screens: nothing is told by hue, but by brightness, bold, italics, underline and strike-through
Turbo Pascal Free Pascal Modern dark
turbo-pascal free-pascal modern-dark
Phosphor amber Phosphor green
phosphor-amber phosphor-green

app.theme = "modern-dark" switches. DesktopApp registers them all and repaints on a switch (see The Desktop).

Colour roles

Textual's theme colours ($primary, $surface...) colour textual-vision's widgets. TurboFrame adds roles for what a desktop draws, such as desktop, shadow, editor-bg, output-bg (the Output and log windows), debug-bg (the debugger's), help-bg, list-focused, progress-fill and dialog-frame, and syntax roles: keyword, string, comment, diff-add... Every theme gives each role a colour. The full lists are themes.UI_ROLES and themes.SYNTAX_ROLES.

  • In CSS: $tf-<role>.

    MyPanel { background: $tf-output-bg; color: $tf-output-text; }
  • In code: themes.current().colour(role) gives #RRGGBB, or the nearest of the 16 ANSI colours when the terminal has only those. themes.current().hex(slot) gives one of the 16 slots ("lightcyan"...).

An application whose CSS already uses a prefix of its own keeps it: themes.add_css_alias("myapp") defines $myapp-<role> too.

Your own token kinds

A syntax highlighter of yours names its tokens ("sql.keyword", "sql.string"); token() says which syntax role, and which attributes, each takes in every theme:

themes.token("keyword", "sql.keyword", bold=True)
themes.token("string", "sql.string")
themes.PHOSPHOR_ATTRS.update({"sql.comment": {"italic": True}})  # on the monochrome screens

styles = themes.current().token_styles()  # token kind -> Rich Style, for your widget's render

TurboFrame registers its own kinds: diagnostics (diag.*), diffs (diff.*), and, when turboframe.ui.editor is imported, the capture names of Textual's tree-sitter grammars (keyword, string, function.call...), which colour the editor. themes.treesitter_tokens(prefix) registers those names again with a prefix, for a highlighter of yours that renames them ("ts.").

Colour depth

Rich, and so Textual, sends colours as deep as the terminal says it can: true colour, 256 or 16. A terminal sometimes says less than it can (over ssh, COLORTERM is often lost). The colour depth (themes.DEPTHS: auto, truecolor, 256, 16) forces it, from the next start. With 16 colours, roles snap to the 16 ANSI colours (set_ansi16, which DesktopApp calls). Pass it as DesktopApp(colors="256"), or let Options > Colors keep it.

Options > Colors

Options > Colors

ColorsMixin (turboframe.ui.colors, part of DesktopApp) gives choose_colors(). The dialog lists the themes, and each is seen the moment the cursor reaches it, the whole desktop included. Under the list is a sample you give, then the colour depth. OK keeps both in colors_store (palette, colors; see Settings and Recent Files). Cancel goes back to the theme there was. A store that cannot save says so in a notification. Without a store, the choice lasts for the session.

TurboFrame has no command for it: number one of yours, put it in your Options menu, and call choose_colors() from a worker.

from textual import work
from textual.widgets import TextArea
from textual_vision.constants import Command
from textual_vision.menus import MenuItem

from turboframe.ui.app import DesktopApp

CM_COLORS = Command.USER + 3


class MyApp(DesktopApp):
    def colors_sample(self):
        return TextArea("SELECT name FROM users;", read_only=True)  # a widget the themes paint

    def on_command_message(self, message) -> None:
        if message.command == CM_COLORS:              # MenuItem("~C~olors...", CM_COLORS)
            message.stop()
            self.colors()

    @work
    async def colors(self) -> None:
        await self.choose_colors()

Shadows

Menus, dialogs and windows cast Turbo Vision's shadow: what is behind them, darkened, two cells to the right and one below. ShadowScreen (turboframe.ui.shadow) draws them, and install_shadows(screen) gives any screen of yours the same (the local menu uses it). shadow.enabled = False (from turboframe.ui import shadow), before the screens are made, turns them off. A widget of yours casts one when it has tv_shadow = True, as the completion list does. They post-process Textual's private compositor, so a Textual update could affect them: the switch is there for that.

File marks

turboframe.ui.icons.mark_for(path) gives a file a one-cell ASCII mark and a colour, for a file tree: @ for Python, # for Markdown, < for HTML... A mark is never two cells wide, so the tree keeps its width in every terminal. Add your own:

from turboframe.ui import icons

icons.BY_EXTENSION.update({".sql": ("$", "lightgreen")})
icons.BY_NAME.update({"Makefile": ("!", "yellow")})

API: turboframe.ui.themes, turboframe.ui.colors, turboframe.ui.shadow, turboframe.ui.icons.

Clone this wiki locally