Skip to content

Support the terminal color palette update notifications protocol (terminal dark/light mode detection)#6151

Open
yorickvP wants to merge 3 commits into
Textualize:mainfrom
yorickvP:color-palette-updates
Open

Support the terminal color palette update notifications protocol (terminal dark/light mode detection)#6151
yorickvP wants to merge 3 commits into
Textualize:mainfrom
yorickvP:color-palette-updates

Conversation

@yorickvP

@yorickvP yorickvP commented Oct 2, 2025

Copy link
Copy Markdown

This PR adds support for the color palette update notifications protocol. Changing the terminal color theme will generate a Messages.TerminalColorTheme, and one will be generated at the start.

This can be used to implement auto light/dark theme switching.
In the future, this could be extended to the web and to implement automatic theme switching inside textual (maybe using TEXTUAL_THEME=dark=textual-dark,light=textual-light or something similar).

Please review the following checklist.

  • Docstrings on all new or modified functions / classes
  • Updated documentation
  • Updated CHANGELOG.md (where appropriate)

@yorickvP

yorickvP commented Oct 2, 2025

Copy link
Copy Markdown
Author

I'm using this in my own app with

class TApp(App):
    def on_terminal_color_theme(self, message: TerminalColorTheme):
        match message.theme:
            case "light":
                self.theme = "catppuccin-latte" # "textual-light"
            case "dark":
                self.theme = "catppuccin-mocha" # "textual-dark"

@yorickvP

Copy link
Copy Markdown
Author

@willmcgugan I'm getting a lot of mileage out of this, could you share some thoughts on it?

@mdrxy

mdrxy commented May 8, 2026

Copy link
Copy Markdown

Would love to see this landed!

mdrxy added a commit to langchain-ai/deepagents that referenced this pull request May 10, 2026
Fixes part 1 of #2146

---

Add per-terminal theme mapping so users switching between terminals
(e.g. dark iTerm vs. light Apple Terminal) get the right theme
automatically without re-picking each time.

## Changes
- Add `[ui.terminal_themes]` config table keyed on `TERM_PROGRAM` —
looked up before the saved global preference in
`_load_theme_preference`, after the `DEEPAGENTS_CLI_THEME` env var
override
- Introduce `_resolve_theme_name` to canonicalize theme values (registry
key, human label, case-insensitive, whitespace-tolerant, plus
`textual-ansi` → `ansi-light` legacy migration) shared across env var,
terminal mapping, and saved-preference resolution paths
- Add `save_terminal_theme_mapping` for atomic TOML writes to
`[ui.terminal_themes]`; preserves existing table entries and repairs
malformed scalar values with a warning
- Extend `ThemeSelectorScreen` with `n` to toggle between human-readable
labels and canonical registry keys, and `t` to persist the highlighted
theme for the current `TERM_PROGRAM` without touching `[ui].theme` — the
picker stays open and the `(default)` badge updates in place, so users
can keep browsing
- Badge the option list with `(default)` when a theme matches the
current terminal's saved mapping; combine with `(current)` as `(current,
default)` when both apply
- Serialize `config.toml` writes with a process-local lock so a quick
`t`-then-Enter sequence can't clobber either mutation

PR 1 of 2 — system dark/light auto-detection will follow once
Textualize/textual#6151 lands upstream.

---------

Co-authored-by: Mason Daugherty <github@mdrxy.com>
Co-authored-by: Mason Daugherty <mason@langchain.dev>
@yorickvP
yorickvP force-pushed the color-palette-updates branch from 67b0855 to 79d44ce Compare July 23, 2026 08:00
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.

2 participants