@@ -304,9 +304,60 @@ if [[ -f $COLORS_FILE ]]; then
304304 value=" ${value%% [\"\']* } " # extract value between quotes (ignores inline comments)
305305
306306 THEME_COLORS[$key ]=" $value "
307- add_template_value " $key " " $value "
308307 done < " $COLORS_FILE "
309308
309+ # Legacy compatibility: map ANSI color0..color15 and raw bg/fg to semantic names
310+ declare -A legacy_alias=(
311+ [bg]=background [fg]=foreground
312+ [red]=color1 [green]=color2 [yellow]=color3
313+ [blue]=color4 [purple]=color5 [cyan]=color6
314+ [bright_red]=color9 [bright_green]=color10 [bright_yellow]=color11
315+ [bright_blue]=color12 [bright_purple]=color13 [bright_cyan]=color14
316+ )
317+ for key in " ${! legacy_alias[@]} " ; do
318+ [[ ${THEME_COLORS[$key]} ]] || THEME_COLORS[$key ]=" ${THEME_COLORS[${legacy_alias[$key]} ]}"
319+ done
320+
321+ [[ ${THEME_COLORS[light_fg]} ]] || THEME_COLORS[light_fg]=" ${THEME_COLORS[color7]:- ${THEME_COLORS[foreground]} } "
322+ [[ ${THEME_COLORS[bright_fg]} ]] || THEME_COLORS[bright_fg]=" ${THEME_COLORS[color15]:- ${THEME_COLORS[foreground]} } "
323+ [[ ${THEME_COLORS[lighter_bg]} ]] || THEME_COLORS[lighter_bg]=" ${THEME_COLORS[color0]:- ${THEME_COLORS[background]} } "
324+ [[ ${THEME_COLORS[dark_fg]} ]] || THEME_COLORS[dark_fg]=" ${THEME_COLORS[color8]:- ${THEME_COLORS[foreground]} } "
325+ [[ ${THEME_COLORS[muted]} ]] || THEME_COLORS[muted]=" ${THEME_COLORS[color8]:- ${THEME_COLORS[dark_fg]} } "
326+ [[ ${THEME_COLORS[selection]} ]] || THEME_COLORS[selection]=" ${THEME_COLORS[selection_background]:- ${THEME_COLORS[color8]:- ${THEME_COLORS[color0]} } } "
327+ [[ ${THEME_COLORS[orange]} ]] || THEME_COLORS[orange]=" ${THEME_COLORS[yellow]} "
328+ [[ ${THEME_COLORS[brown]} ]] || THEME_COLORS[brown]=$( mix_color " ${THEME_COLORS[orange]} " " #000000" 50%)
329+
330+ # Auto-derive shades from base accents when not defined and not aliased from colorN
331+ [[ ${THEME_COLORS[dark_bg]} ]] || THEME_COLORS[dark_bg]=$( mix_color " ${THEME_COLORS[background]} " " #000000" 25%)
332+ [[ ${THEME_COLORS[darker_bg]} ]] || THEME_COLORS[darker_bg]=$( mix_color " ${THEME_COLORS[background]} " " #000000" 50%)
333+ [[ ${THEME_COLORS[bright_red]} ]] || THEME_COLORS[bright_red]=$( mix_color " ${THEME_COLORS[red]} " " #ffffff" 20%)
334+ [[ ${THEME_COLORS[bright_yellow]} ]] || THEME_COLORS[bright_yellow]=$( mix_color " ${THEME_COLORS[yellow]} " " #ffffff" 20%)
335+ [[ ${THEME_COLORS[bright_green]} ]] || THEME_COLORS[bright_green]=$( mix_color " ${THEME_COLORS[green]} " " #ffffff" 20%)
336+ [[ ${THEME_COLORS[bright_cyan]} ]] || THEME_COLORS[bright_cyan]=$( mix_color " ${THEME_COLORS[cyan]} " " #ffffff" 20%)
337+ [[ ${THEME_COLORS[bright_blue]} ]] || THEME_COLORS[bright_blue]=$( mix_color " ${THEME_COLORS[blue]} " " #ffffff" 20%)
338+ [[ ${THEME_COLORS[bright_purple]} ]] || THEME_COLORS[bright_purple]=$( mix_color " ${THEME_COLORS[purple]} " " #ffffff" 20%)
339+
340+ # Resolve theme mode (dark|light) with this precedence:
341+ # 1. `mode` key in colors.toml
342+ # 2. legacy `light.mode` file shipped beside the theme
343+ # 3. background luminance auto-detect
344+ # `theme_type` is kept as an alias so existing templates ({{ theme_type }}) keep working.
345+ [[ ${THEME_COLORS[mode]} ]] || THEME_COLORS[mode]=" ${THEME_COLORS[theme_type]} "
346+ if [[ ! ${THEME_COLORS[mode]} ]]; then
347+ if [[ -f $NEXT_THEME_DIR /light.mode ]]; then
348+ THEME_COLORS[mode]=" light"
349+ else
350+ bg_hex=" ${THEME_COLORS[background]# \# } "
351+ lum=$(( $(printf "% d" "0 x${bg_hex: 0: 2} ") + $(printf "% d" "0 x${bg_hex: 2: 2} ") + $(printf "% d" "0 x${bg_hex: 4: 2} ") ))
352+ [[ $lum -gt 382 ]] && THEME_COLORS[mode]=" light" || THEME_COLORS[mode]=" dark"
353+ fi
354+ fi
355+ THEME_COLORS[theme_type]=" ${THEME_COLORS[mode]} "
356+
357+ for key in " ${! THEME_COLORS[@]} " ; do
358+ add_template_value " $key " " ${THEME_COLORS[$key]} "
359+ done
360+
310361 add_mix_values
311362 add_gradient_function_values
312363
0 commit comments