diff --git a/theme-set.d/50-cliamp.sh b/theme-set.d/50-cliamp.sh index f5846f4..d7d2eee 100755 --- a/theme-set.d/50-cliamp.sh +++ b/theme-set.d/50-cliamp.sh @@ -8,13 +8,47 @@ fi theme_dir="$HOME/.config/cliamp/themes" mkdir -p "$theme_dir" +# Relative luminance scaled to 0-255 (integer, no external deps). +_lum() { + local r=$((16#${1:0:2})) g=$((16#${1:2:2})) b=$((16#${1:4:2})) + echo $(( (2126 * r + 7152 * g + 722 * b) / 10000 )) +} + +# cliamp maps bright_fg -> normal text, fg -> dimmed text, so bright_fg must be +# the brighter of the two. Some palettes define color15 darker than color7, which +# would invert that, so pick by luminance instead of trusting the names. +if [ "$(_lum "$bright_white")" -ge "$(_lum "$normal_white")" ]; then + fg_bright="$bright_white"; fg_dim="$normal_white" +else + fg_bright="$normal_white"; fg_dim="$bright_white" +fi + +# cliamp uses accent for the title, seek bar AND the key-hint background, so it +# must stand out from the terminal background. Prefer the theme's blue, but if it +# sits too close to the background (e.g. monochrome themes) fall back to the most +# contrasting candidate so those elements stay readable. +bg_lum="$(_lum "$primary_background")" +accent="$normal_blue" +acc_diff=$(( $(_lum "$accent") - bg_lum )); acc_diff=${acc_diff#-} +if [ "$acc_diff" -lt 80 ]; then + accent="" + # first try a readable *coloured* accent (keeps a visual accent)… + for cand in "$bright_blue" "$normal_cyan" "$normal_yellow" "$normal_green" "$normal_red"; do + [ -n "$cand" ] || continue + cand_diff=$(( $(_lum "$cand") - bg_lum )); cand_diff=${cand_diff#-} + [ "$cand_diff" -ge 80 ] && { accent="$cand"; break; } + done + # …otherwise fall back to the readable foreground colour + [ -n "$accent" ] || accent="$fg_bright" +fi + cat > "$theme_dir/omarchy.toml" << EOF # Omarchy theme for cliamp # Generated by thpm — do not edit manually. -accent = "#${normal_blue}" -bright_fg = "#${bright_white}" -fg = "#${normal_white}" +accent = "#${accent}" +bright_fg = "#${fg_bright}" +fg = "#${fg_dim}" green = "#${normal_green}" yellow = "#${normal_yellow}" red = "#${normal_red}"