Skip to content

Instantly share code, notes, and snippets.

@jake-stewart
jake-stewart / detect-256-theme.py
Last active February 23, 2026 16:07
Detect and handle 256-color themes
#!/usr/bin/env python3
"""
Detects whether the terminal is using a light or dark theme and automatically
adjusts 256-color palette indices so that colors render consistently regardless
of the active theme. This is especially useful when a terminal (e.g. Ghostty)
generates its 256-color palette to match the current theme — or when it doesn't,
and we need to compensate by flipping the indices ourselves.
"""
import os
@jake-stewart
jake-stewart / color256.md
Last active February 24, 2026 11:47
Terminals should generate the 256-color palette

Terminals should generate the 256-color palette from the user's base16 theme.

If you've spent much time in the terminal, you've probably set a custom base16 theme. They work well. You define a handful of colors in one place and all your programs use them.

The drawback is that 16 colors is limiting. Complex and color-heavy programs struggle with such a small palette.