Clean up semantic theme compatibility
This commit is contained in:
@@ -182,24 +182,6 @@ selection_background=${selection_background:-$foreground}
|
|||||||
selection_foreground=${selection_foreground:-$background}
|
selection_foreground=${selection_foreground:-$background}
|
||||||
accent=$color4
|
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"
|
mkdir -p "$THEME_SOURCE"
|
||||||
|
|
||||||
cat > "$COLORS_OUTPUT" <<EOF
|
cat > "$COLORS_OUTPUT" <<EOF
|
||||||
@@ -210,20 +192,20 @@ background = "$background"
|
|||||||
selection_foreground = "$selection_foreground"
|
selection_foreground = "$selection_foreground"
|
||||||
selection_background = "$selection_background"
|
selection_background = "$selection_background"
|
||||||
|
|
||||||
color0 = "$bg"
|
color0 = "$color0"
|
||||||
color1 = "$red"
|
color1 = "$color1"
|
||||||
color2 = "$green"
|
color2 = "$color2"
|
||||||
color3 = "$yellow"
|
color3 = "$color3"
|
||||||
color4 = "$blue"
|
color4 = "$color4"
|
||||||
color5 = "$purple"
|
color5 = "$color5"
|
||||||
color6 = "$cyan"
|
color6 = "$color6"
|
||||||
color7 = "$fg"
|
color7 = "$color7"
|
||||||
color8 = "$muted"
|
color8 = "$color8"
|
||||||
color9 = "$bright_red"
|
color9 = "$color9"
|
||||||
color10 = "$bright_green"
|
color10 = "$color10"
|
||||||
color11 = "$bright_yellow"
|
color11 = "$color11"
|
||||||
color12 = "$bright_blue"
|
color12 = "$color12"
|
||||||
color13 = "$bright_purple"
|
color13 = "$color13"
|
||||||
color14 = "$bright_cyan"
|
color14 = "$color14"
|
||||||
color15 = "$bright_fg"
|
color15 = "$color15"
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
@@ -3,20 +3,19 @@
|
|||||||
# omarchy:summary=Apply the current theme to GNOME color mode and icon settings
|
# omarchy:summary=Apply the current theme to GNOME color mode and icon settings
|
||||||
# omarchy:hidden=true
|
# omarchy:hidden=true
|
||||||
|
|
||||||
# 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
|
THEME_DIR=~/.config/omarchy/current/theme
|
||||||
COLORS_FILE="$THEME_DIR/colors.toml"
|
COLORS_FILE="$THEME_DIR/colors.toml"
|
||||||
|
|
||||||
theme_color() {
|
# In-tree light themes now declare `mode = "light"` in colors.toml instead of
|
||||||
local key="$1"
|
# shipping a separate light.mode marker. Keep light.mode as a user-theme fallback.
|
||||||
|
theme_mode() {
|
||||||
|
[[ -f $COLORS_FILE ]] || return
|
||||||
|
|
||||||
awk -F= -v key="$key" '
|
awk -F= '
|
||||||
{
|
{
|
||||||
field = $1
|
field = $1
|
||||||
gsub(/^[[:space:]]+|[[:space:]]+$/, "", field)
|
gsub(/^[[:space:]]+|[[:space:]]+$/, "", field)
|
||||||
if (field == key) {
|
if (field == "mode") {
|
||||||
value = $2
|
value = $2
|
||||||
gsub(/^[[:space:]]+|[[:space:]]+$/, "", value)
|
gsub(/^[[:space:]]+|[[:space:]]+$/, "", value)
|
||||||
if (value ~ /^"/) {
|
if (value ~ /^"/) {
|
||||||
@@ -30,10 +29,7 @@ theme_color() {
|
|||||||
' "$COLORS_FILE"
|
' "$COLORS_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
mode=""
|
mode=$(theme_mode)
|
||||||
if [[ -f $COLORS_FILE ]]; then
|
|
||||||
mode=$(theme_color mode)
|
|
||||||
fi
|
|
||||||
if [[ -z $mode && -f $THEME_DIR/light.mode ]]; then
|
if [[ -z $mode && -f $THEME_DIR/light.mode ]]; then
|
||||||
mode="light"
|
mode="light"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -290,6 +290,30 @@ add_gradient_function_values() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
alias_theme_color() {
|
||||||
|
local key="$1"
|
||||||
|
local fallback="$2"
|
||||||
|
|
||||||
|
[[ ${THEME_COLORS[$key]} ]] || THEME_COLORS[$key]="${THEME_COLORS[$fallback]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve_theme_mode() {
|
||||||
|
local bg_hex lum
|
||||||
|
|
||||||
|
[[ ${THEME_COLORS[mode]} ]] || THEME_COLORS[mode]="${THEME_COLORS[theme_type]}"
|
||||||
|
[[ ${THEME_COLORS[mode]} ]] && return
|
||||||
|
|
||||||
|
if [[ -f $NEXT_THEME_DIR/light.mode ]]; then
|
||||||
|
THEME_COLORS[mode]="light"
|
||||||
|
elif [[ ${THEME_COLORS[background]} =~ ^#[0-9A-Fa-f]{6}$ ]]; then
|
||||||
|
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 > 382 )) && THEME_COLORS[mode]="light" || THEME_COLORS[mode]="dark"
|
||||||
|
else
|
||||||
|
THEME_COLORS[mode]="dark"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Only generate dynamic templates for themes with a colors.toml definition
|
# Only generate dynamic templates for themes with a colors.toml definition
|
||||||
if [[ -f $COLORS_FILE ]]; then
|
if [[ -f $COLORS_FILE ]]; then
|
||||||
sed_script=$(mktemp)
|
sed_script=$(mktemp)
|
||||||
@@ -308,14 +332,23 @@ if [[ -f $COLORS_FILE ]]; then
|
|||||||
|
|
||||||
# Legacy compatibility: map ANSI color0..color15 and raw bg/fg to semantic names
|
# Legacy compatibility: map ANSI color0..color15 and raw bg/fg to semantic names
|
||||||
declare -A legacy_alias=(
|
declare -A legacy_alias=(
|
||||||
[bg]=background [fg]=foreground
|
[bg]=background
|
||||||
[red]=color1 [green]=color2 [yellow]=color3
|
[fg]=foreground
|
||||||
[blue]=color4 [purple]=color5 [cyan]=color6
|
[red]=color1
|
||||||
[bright_red]=color9 [bright_green]=color10 [bright_yellow]=color11
|
[green]=color2
|
||||||
[bright_blue]=color12 [bright_purple]=color13 [bright_cyan]=color14
|
[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
|
for key in "${!legacy_alias[@]}"; do
|
||||||
[[ ${THEME_COLORS[$key]} ]] || THEME_COLORS[$key]="${THEME_COLORS[${legacy_alias[$key]}]}"
|
alias_theme_color "$key" "${legacy_alias[$key]}"
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ ${THEME_COLORS[light_fg]} ]] || THEME_COLORS[light_fg]="${THEME_COLORS[color7]:-${THEME_COLORS[foreground]}}"
|
[[ ${THEME_COLORS[light_fg]} ]] || THEME_COLORS[light_fg]="${THEME_COLORS[color7]:-${THEME_COLORS[foreground]}}"
|
||||||
@@ -340,15 +373,25 @@ if [[ -f $COLORS_FILE ]]; then
|
|||||||
# Keep semantic themes compatible with user templates that still reference
|
# Keep semantic themes compatible with user templates that still reference
|
||||||
# the legacy ANSI placeholders directly.
|
# the legacy ANSI placeholders directly.
|
||||||
declare -A ansi_alias=(
|
declare -A ansi_alias=(
|
||||||
[color0]=bg [color1]=red [color2]=green
|
[color0]=bg
|
||||||
[color3]=yellow [color4]=blue [color5]=purple
|
[color1]=red
|
||||||
[color6]=cyan [color7]=fg [color8]=muted
|
[color2]=green
|
||||||
[color9]=bright_red [color10]=bright_green [color11]=bright_yellow
|
[color3]=yellow
|
||||||
[color12]=bright_blue [color13]=bright_purple [color14]=bright_cyan
|
[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
|
[color15]=bright_fg
|
||||||
)
|
)
|
||||||
for key in "${!ansi_alias[@]}"; do
|
for key in "${!ansi_alias[@]}"; do
|
||||||
[[ ${THEME_COLORS[$key]} ]] || THEME_COLORS[$key]="${THEME_COLORS[${ansi_alias[$key]}]}"
|
alias_theme_color "$key" "${ansi_alias[$key]}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Resolve theme mode (dark|light) with this precedence:
|
# Resolve theme mode (dark|light) with this precedence:
|
||||||
@@ -356,16 +399,7 @@ if [[ -f $COLORS_FILE ]]; then
|
|||||||
# 2. legacy `light.mode` file shipped beside the theme
|
# 2. legacy `light.mode` file shipped beside the theme
|
||||||
# 3. background luminance auto-detect
|
# 3. background luminance auto-detect
|
||||||
# `theme_type` is kept as an alias so existing templates ({{ theme_type }}) keep working.
|
# `theme_type` is kept as an alias so existing templates ({{ theme_type }}) keep working.
|
||||||
[[ ${THEME_COLORS[mode]} ]] || THEME_COLORS[mode]="${THEME_COLORS[theme_type]}"
|
resolve_theme_mode
|
||||||
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]}"
|
THEME_COLORS[theme_type]="${THEME_COLORS[mode]}"
|
||||||
|
|
||||||
for key in "${!THEME_COLORS[@]}"; do
|
for key in "${!THEME_COLORS[@]}"; do
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
# omarchy:summary=Sync Omarchy theme to VS Code, VSCodium, and Cursor
|
# omarchy:summary=Sync Omarchy theme to VS Code, VSCodium, and Cursor
|
||||||
# omarchy:hidden=true
|
# omarchy:hidden=true
|
||||||
|
|
||||||
VS_CODE_THEME="$HOME/.config/omarchy/current/theme/vscode.json"
|
VS_CODE_THEME_DESCRIPTOR="$HOME/.config/omarchy/current/theme/vscode.json"
|
||||||
GENERATED_THEME="$HOME/.config/omarchy/current/theme/vscode-theme.json"
|
GENERATED_THEME="$HOME/.config/omarchy/current/theme/vscode-theme.json"
|
||||||
|
|
||||||
# Install generated theme as a local extension for a given editor
|
# Install generated theme as a local extension for a given editor
|
||||||
@@ -50,22 +50,18 @@ set_theme() {
|
|||||||
|
|
||||||
local theme_name=""
|
local theme_name=""
|
||||||
|
|
||||||
# Always deploy the generated theme so it's available in the theme picker
|
if [[ -f "$VS_CODE_THEME_DESCRIPTOR" ]]; then
|
||||||
if [[ -f "$GENERATED_THEME" ]]; then
|
# Theme specifies a preferred 3rd-party extension/theme pair.
|
||||||
install_generated_extension "$ext_base/omarchy-theme"
|
theme_name=$(jq -r '.name' "$VS_CODE_THEME_DESCRIPTOR")
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -f "$VS_CODE_THEME" ]]; then
|
|
||||||
# Theme specifies a preferred 3rd-party extension
|
|
||||||
theme_name=$(jq -r '.name' "$VS_CODE_THEME")
|
|
||||||
local extension
|
local extension
|
||||||
extension=$(jq -r '.extension' "$VS_CODE_THEME")
|
extension=$(jq -r '.extension' "$VS_CODE_THEME_DESCRIPTOR")
|
||||||
|
|
||||||
if [[ -n $extension ]] && ! "$editor_cmd" --list-extensions 2>/dev/null | grep -Fxq "$extension"; then
|
if [[ -n $extension ]] && ! "$editor_cmd" --list-extensions 2>/dev/null | grep -Fxq "$extension"; then
|
||||||
"$editor_cmd" --install-extension "$extension" >/dev/null 2>&1
|
"$editor_cmd" --install-extension "$extension" >/dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
elif [[ -f "$GENERATED_THEME" ]]; then
|
elif [[ -f "$GENERATED_THEME" ]]; then
|
||||||
# No 3rd-party preference, activate the generated theme
|
# VS Code only discovers local color themes through an extension package.
|
||||||
|
install_generated_extension "$ext_base/omarchy-theme"
|
||||||
theme_name="Omarchy"
|
theme_name="Omarchy"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user