fix: add bg/fg aliases for theme color resolution (#6546)

* fix: add bg/fg aliases for theme color resolution

Themes define bg/fg but the template system expects
background/foreground. The fallback chain only checked color0/color7,
leaving background/foreground empty for themes using bg/fg naming.

* Complete legacy theme palette compatibility

---------

Co-authored-by: David Heinemeier Hansson <david@hey.com>
This commit is contained in:
Luke Walker
2026-08-04 13:26:26 -05:00
committed by GitHub
co-authored by David Heinemeier Hansson
parent fd02c26230
commit caeffdc27b
3 changed files with 134 additions and 3 deletions
+26 -2
View File
@@ -161,8 +161,24 @@ parse_colors_file() {
resolve_theme_colors() {
local key
# Canonical palette keys are background/foreground. Themes generated before
# the semantic palette existed may only define the ANSI names.
# Accept the complete legacy short-name palette before applying ANSI
# fallbacks or deriving shades. Canonical names take precedence when a theme
# defines both forms.
declare -A legacy_palette_alias=(
[background]=bg
[dark_background]=dark_bg
[darker_background]=darker_bg
[lighter_background]=lighter_bg
[foreground]=fg
[dark_foreground]=dark_fg
[light_foreground]=light_fg
[bright_foreground]=bright_fg
)
for key in "${!legacy_palette_alias[@]}"; do
alias_theme_color "$key" "${legacy_palette_alias[$key]}"
done
# Themes generated before the semantic palette may only define ANSI names.
[[ ${THEME_COLORS[background]} ]] || THEME_COLORS[background]="${THEME_COLORS[color0]}"
[[ ${THEME_COLORS[foreground]} ]] || THEME_COLORS[foreground]="${THEME_COLORS[color7]}"
[[ ${THEME_COLORS[background]} ]] && THEME_COLORS[color0]="${THEME_COLORS[background]}"
@@ -237,6 +253,14 @@ resolve_theme_colors() {
alias_theme_color "$key" "${ansi_alias[$key]}"
done
# Keep canonical themes compatible with old user templates and consumers
# that still query the short palette names directly.
for key in "${!legacy_palette_alias[@]}"; do
if [[ ${THEME_COLORS[$key]} ]]; then
THEME_COLORS["${legacy_palette_alias[$key]}"]="${THEME_COLORS[$key]}"
fi
done
resolve_theme_mode
THEME_COLORS[theme_type]="${THEME_COLORS[mode]}"
}