Skip to content

Ansi themes#6513

Merged
willmcgugan merged 19 commits intomainfrom
ansi-themes
Apr 30, 2026
Merged

Ansi themes#6513
willmcgugan merged 19 commits intomainfrom
ansi-themes

Conversation

@willmcgugan
Copy link
Copy Markdown
Member

@willmcgugan willmcgugan commented Apr 26, 2026

Fixes #6490

Added two ANSI themes; ansi-dark and ansi-light.

A theme can now explicitly declare itself as an ANSI theme, which will prevent ANSI colors from being promoted to true-color. This means that here is probably no reason to set ansi_color on the app constructor any more. ANSI and truecolor themes can co-exist in the same app.

Fixed an issue related to the ordering of text spans that impacted selection.

ANSI themes

Previously the App constructor accept an ansi_color boolean.

ansi_color Behavior
False Convert ANSI color sequences to RGB to enabled transparency
True Write ANSI color sequences

ansi_color may now also be None which will cause the app to use the value of ansi set on the Theme. Most apps should leave ansi_color as the default (None).

This allows for explicit ANSI themes. ANSI tends to be an all or nothing thing. If you mix RGB colors with ANSI colors you have no way of knowing if your colors + user colors will be legible.

There are two new themes: ansi-light and ansi-dark. Users with a dark terminal theme should pick ansi-dark, users with a light terminal theme should pick ansi-light.

Customizing ANSI themes

Default widgets should work with ANSI themes (open an issue if something breaks), but if you may still want customizations for ANSI only. To do this, you can use the :ansi pseudo class.

The most straightforward way of doing this is to add a single App:ansi rule to your stylesheet with ANSI specific rules. Something like the following:

App:ansi {
    # ansi specific rules
    &:light {
        # ansi specific rules for light themes
    }
    &:dark {
        # ansi specific rules for dark themes
    }
}

This should ensure that the rules have greater specificity.

Screenshot 2026-04-26 at 21 39 16

@willmcgugan willmcgugan marked this pull request as draft April 26, 2026 14:44
@willmcgugan willmcgugan marked this pull request as ready for review April 30, 2026 04:58
@willmcgugan willmcgugan merged commit 5fdea0d into main Apr 30, 2026
38 of 41 checks passed
@willmcgugan willmcgugan deleted the ansi-themes branch April 30, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ANSI-based builtin theme

1 participant