Implement semantic theme color system
This commit is contained in:
@@ -182,6 +182,24 @@ selection_background=${selection_background:-$foreground}
|
||||
selection_foreground=${selection_foreground:-$background}
|
||||
accent=$color4
|
||||
|
||||
# Remap ANSI slots to semantic names for the output palette
|
||||
bg=$color0
|
||||
red=$color1
|
||||
green=$color2
|
||||
yellow=$color3
|
||||
blue=$color4
|
||||
purple=$color5
|
||||
cyan=$color6
|
||||
fg=$color7
|
||||
muted=$color8
|
||||
bright_red=$color9
|
||||
bright_green=$color10
|
||||
bright_yellow=$color11
|
||||
bright_blue=$color12
|
||||
bright_purple=$color13
|
||||
bright_cyan=$color14
|
||||
bright_fg=$color15
|
||||
|
||||
mkdir -p "$THEME_SOURCE"
|
||||
|
||||
cat > "$COLORS_OUTPUT" <<EOF
|
||||
@@ -192,20 +210,20 @@ background = "$background"
|
||||
selection_foreground = "$selection_foreground"
|
||||
selection_background = "$selection_background"
|
||||
|
||||
color0 = "$color0"
|
||||
color1 = "$color1"
|
||||
color2 = "$color2"
|
||||
color3 = "$color3"
|
||||
color4 = "$color4"
|
||||
color5 = "$color5"
|
||||
color6 = "$color6"
|
||||
color7 = "$color7"
|
||||
color8 = "$color8"
|
||||
color9 = "$color9"
|
||||
color10 = "$color10"
|
||||
color11 = "$color11"
|
||||
color12 = "$color12"
|
||||
color13 = "$color13"
|
||||
color14 = "$color14"
|
||||
color15 = "$color15"
|
||||
color0 = "$bg"
|
||||
color1 = "$red"
|
||||
color2 = "$green"
|
||||
color3 = "$yellow"
|
||||
color4 = "$blue"
|
||||
color5 = "$purple"
|
||||
color6 = "$cyan"
|
||||
color7 = "$fg"
|
||||
color8 = "$muted"
|
||||
color9 = "$bright_red"
|
||||
color10 = "$bright_green"
|
||||
color11 = "$bright_yellow"
|
||||
color12 = "$bright_blue"
|
||||
color13 = "$bright_purple"
|
||||
color14 = "$bright_cyan"
|
||||
color15 = "$bright_fg"
|
||||
EOF
|
||||
|
||||
@@ -3,7 +3,20 @@
|
||||
# omarchy:summary=Apply the current theme to GNOME color mode and icon settings
|
||||
# omarchy:hidden=true
|
||||
|
||||
if [[ -f ~/.config/omarchy/current/theme/light.mode ]]; then
|
||||
# Detect mode (light|dark) with this precedence:
|
||||
# 1. `mode` key in the active theme's colors.toml
|
||||
# 2. legacy `light.mode` file shipped beside the theme
|
||||
THEME_DIR=~/.config/omarchy/current/theme
|
||||
COLORS_FILE="$THEME_DIR/colors.toml"
|
||||
mode=""
|
||||
if [[ -f $COLORS_FILE ]] && command -v tomlq >/dev/null; then
|
||||
mode=$(tomlq -r '.mode // empty' "$COLORS_FILE" 2>/dev/null)
|
||||
fi
|
||||
if [[ -z $mode && -f $THEME_DIR/light.mode ]]; then
|
||||
mode="light"
|
||||
fi
|
||||
|
||||
if [[ $mode == "light" ]]; then
|
||||
gsettings set org.gnome.desktop.interface color-scheme "prefer-light"
|
||||
gsettings set org.gnome.desktop.interface gtk-theme "Adwaita"
|
||||
else
|
||||
|
||||
@@ -304,9 +304,60 @@ if [[ -f $COLORS_FILE ]]; then
|
||||
value="${value%%[\"\']*}" # extract value between quotes (ignores inline comments)
|
||||
|
||||
THEME_COLORS[$key]="$value"
|
||||
add_template_value "$key" "$value"
|
||||
done <"$COLORS_FILE"
|
||||
|
||||
# Legacy compatibility: map ANSI color0..color15 and raw bg/fg to semantic names
|
||||
declare -A legacy_alias=(
|
||||
[bg]=background [fg]=foreground
|
||||
[red]=color1 [green]=color2 [yellow]=color3
|
||||
[blue]=color4 [purple]=color5 [cyan]=color6
|
||||
[bright_red]=color9 [bright_green]=color10 [bright_yellow]=color11
|
||||
[bright_blue]=color12 [bright_purple]=color13 [bright_cyan]=color14
|
||||
)
|
||||
for key in "${!legacy_alias[@]}"; do
|
||||
[[ ${THEME_COLORS[$key]} ]] || THEME_COLORS[$key]="${THEME_COLORS[${legacy_alias[$key]}]}"
|
||||
done
|
||||
|
||||
[[ ${THEME_COLORS[light_fg]} ]] || THEME_COLORS[light_fg]="${THEME_COLORS[color7]:-${THEME_COLORS[foreground]}}"
|
||||
[[ ${THEME_COLORS[bright_fg]} ]] || THEME_COLORS[bright_fg]="${THEME_COLORS[color15]:-${THEME_COLORS[foreground]}}"
|
||||
[[ ${THEME_COLORS[lighter_bg]} ]] || THEME_COLORS[lighter_bg]="${THEME_COLORS[color0]:-${THEME_COLORS[background]}}"
|
||||
[[ ${THEME_COLORS[dark_fg]} ]] || THEME_COLORS[dark_fg]="${THEME_COLORS[color8]:-${THEME_COLORS[foreground]}}"
|
||||
[[ ${THEME_COLORS[muted]} ]] || THEME_COLORS[muted]="${THEME_COLORS[color8]:-${THEME_COLORS[dark_fg]}}"
|
||||
[[ ${THEME_COLORS[selection]} ]] || THEME_COLORS[selection]="${THEME_COLORS[selection_background]:-${THEME_COLORS[color8]:-${THEME_COLORS[color0]}}}"
|
||||
[[ ${THEME_COLORS[orange]} ]] || THEME_COLORS[orange]="${THEME_COLORS[yellow]}"
|
||||
[[ ${THEME_COLORS[brown]} ]] || THEME_COLORS[brown]=$(mix_color "${THEME_COLORS[orange]}" "#000000" 50%)
|
||||
|
||||
# Auto-derive shades from base accents when not defined and not aliased from colorN
|
||||
[[ ${THEME_COLORS[dark_bg]} ]] || THEME_COLORS[dark_bg]=$(mix_color "${THEME_COLORS[background]}" "#000000" 25%)
|
||||
[[ ${THEME_COLORS[darker_bg]} ]] || THEME_COLORS[darker_bg]=$(mix_color "${THEME_COLORS[background]}" "#000000" 50%)
|
||||
[[ ${THEME_COLORS[bright_red]} ]] || THEME_COLORS[bright_red]=$(mix_color "${THEME_COLORS[red]}" "#ffffff" 20%)
|
||||
[[ ${THEME_COLORS[bright_yellow]} ]] || THEME_COLORS[bright_yellow]=$(mix_color "${THEME_COLORS[yellow]}" "#ffffff" 20%)
|
||||
[[ ${THEME_COLORS[bright_green]} ]] || THEME_COLORS[bright_green]=$(mix_color "${THEME_COLORS[green]}" "#ffffff" 20%)
|
||||
[[ ${THEME_COLORS[bright_cyan]} ]] || THEME_COLORS[bright_cyan]=$(mix_color "${THEME_COLORS[cyan]}" "#ffffff" 20%)
|
||||
[[ ${THEME_COLORS[bright_blue]} ]] || THEME_COLORS[bright_blue]=$(mix_color "${THEME_COLORS[blue]}" "#ffffff" 20%)
|
||||
[[ ${THEME_COLORS[bright_purple]} ]] || THEME_COLORS[bright_purple]=$(mix_color "${THEME_COLORS[purple]}" "#ffffff" 20%)
|
||||
|
||||
# Resolve theme mode (dark|light) with this precedence:
|
||||
# 1. `mode` key in colors.toml
|
||||
# 2. legacy `light.mode` file shipped beside the theme
|
||||
# 3. background luminance auto-detect
|
||||
# `theme_type` is kept as an alias so existing templates ({{ theme_type }}) keep working.
|
||||
[[ ${THEME_COLORS[mode]} ]] || THEME_COLORS[mode]="${THEME_COLORS[theme_type]}"
|
||||
if [[ ! ${THEME_COLORS[mode]} ]]; then
|
||||
if [[ -f $NEXT_THEME_DIR/light.mode ]]; then
|
||||
THEME_COLORS[mode]="light"
|
||||
else
|
||||
bg_hex="${THEME_COLORS[background]#\#}"
|
||||
lum=$(( $(printf "%d" "0x${bg_hex:0:2}") + $(printf "%d" "0x${bg_hex:2:2}") + $(printf "%d" "0x${bg_hex:4:2}") ))
|
||||
[[ $lum -gt 382 ]] && THEME_COLORS[mode]="light" || THEME_COLORS[mode]="dark"
|
||||
fi
|
||||
fi
|
||||
THEME_COLORS[theme_type]="${THEME_COLORS[mode]}"
|
||||
|
||||
for key in "${!THEME_COLORS[@]}"; do
|
||||
add_template_value "$key" "${THEME_COLORS[$key]}"
|
||||
done
|
||||
|
||||
add_mix_values
|
||||
add_gradient_function_values
|
||||
|
||||
|
||||
@@ -4,21 +4,67 @@
|
||||
# omarchy:hidden=true
|
||||
|
||||
VS_CODE_THEME="$HOME/.config/omarchy/current/theme/vscode.json"
|
||||
GENERATED_THEME="$HOME/.config/omarchy/current/theme/vscode-theme.json"
|
||||
|
||||
# Install generated theme as a local extension for a given editor
|
||||
install_generated_extension() {
|
||||
local ext_dir="$1"
|
||||
local theme_type
|
||||
|
||||
theme_type=$(jq -r '.type // "dark"' "$GENERATED_THEME")
|
||||
|
||||
mkdir -p "$ext_dir/themes"
|
||||
cp "$GENERATED_THEME" "$ext_dir/themes/omarchy-color-theme.json"
|
||||
|
||||
cat > "$ext_dir/package.json" <<EOF
|
||||
{
|
||||
"name": "omarchy-theme",
|
||||
"displayName": "Omarchy",
|
||||
"description": "Omarchy color theme",
|
||||
"publisher": "local",
|
||||
"version": "1.0.0",
|
||||
"engines": { "vscode": "^1.70.0" },
|
||||
"categories": ["Themes"],
|
||||
"contributes": {
|
||||
"themes": [{
|
||||
"label": "Omarchy",
|
||||
"uiTheme": "vs-${theme_type}",
|
||||
"path": "./themes/omarchy-color-theme.json"
|
||||
}]
|
||||
}
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
set_theme() {
|
||||
local editor_cmd="$1"
|
||||
local settings_path="$2"
|
||||
local ext_base="$3"
|
||||
|
||||
omarchy-cmd-present "$editor_cmd" || return 0
|
||||
|
||||
if [[ -f $VS_CODE_THEME ]]; then
|
||||
local theme_name=""
|
||||
|
||||
# Always deploy the generated theme so it's available in the theme picker
|
||||
if [[ -f "$GENERATED_THEME" ]]; then
|
||||
install_generated_extension "$ext_base/omarchy-theme"
|
||||
fi
|
||||
|
||||
if [[ -f "$VS_CODE_THEME" ]]; then
|
||||
# Theme specifies a preferred 3rd-party extension
|
||||
theme_name=$(jq -r '.name' "$VS_CODE_THEME")
|
||||
local extension
|
||||
extension=$(jq -r '.extension' "$VS_CODE_THEME")
|
||||
|
||||
if [[ -n $extension ]] && ! "$editor_cmd" --list-extensions 2>/dev/null | grep -Fxq "$extension"; then
|
||||
"$editor_cmd" --install-extension "$extension" >/dev/null 2>&1
|
||||
fi
|
||||
elif [[ -f "$GENERATED_THEME" ]]; then
|
||||
# No 3rd-party preference, activate the generated theme
|
||||
theme_name="Omarchy"
|
||||
fi
|
||||
|
||||
if [[ -n "$theme_name" ]]; then
|
||||
mkdir -p "$(dirname "$settings_path")"
|
||||
[[ -f $settings_path ]] || printf '{\n}\n' >"$settings_path"
|
||||
|
||||
@@ -34,7 +80,7 @@ set_theme() {
|
||||
fi
|
||||
}
|
||||
|
||||
! omarchy-toggle-enabled skip-vscode-theme-changes && set_theme "code" "$HOME/.config/Code/User/settings.json"
|
||||
! omarchy-toggle-enabled skip-vscode-insiders-theme-changes && set_theme "code-insiders" "$HOME/.config/Code - Insiders/User/settings.json"
|
||||
! omarchy-toggle-enabled skip-codium-theme-changes && set_theme "codium" "$HOME/.config/VSCodium/User/settings.json"
|
||||
! omarchy-toggle-enabled skip-cursor-theme-changes && set_theme "cursor" "$HOME/.config/Cursor/User/settings.json"
|
||||
! omarchy-toggle-enabled skip-vscode-theme-changes && set_theme "code" "$HOME/.config/Code/User/settings.json" "$HOME/.vscode/extensions"
|
||||
! omarchy-toggle-enabled skip-vscode-insiders-theme-changes && set_theme "code-insiders" "$HOME/.config/Code - Insiders/User/settings.json" "$HOME/.vscode-insiders/extensions"
|
||||
! omarchy-toggle-enabled skip-codium-theme-changes && set_theme "codium" "$HOME/.config/VSCodium/User/settings.json" "$HOME/.vscode-oss/extensions"
|
||||
! omarchy-toggle-enabled skip-cursor-theme-changes && set_theme "cursor" "$HOME/.config/Cursor/User/settings.json" "$HOME/.cursor/extensions"
|
||||
|
||||
Reference in New Issue
Block a user