Restore semantic theme compatibility
This commit is contained in:
+45
-10
@@ -17,21 +17,56 @@ awk -F= '
|
||||
return value
|
||||
}
|
||||
|
||||
function alias_color(target, source) {
|
||||
if (colors[target] == "" && colors[source] != "") colors[target] = colors[source]
|
||||
}
|
||||
|
||||
function emit_color(color_index, key) {
|
||||
if (colors[key] != "") printf "\033]4;%d;%s\007", color_index, colors[key]
|
||||
}
|
||||
|
||||
{
|
||||
key = $1
|
||||
gsub(/^[[:space:]]+|[[:space:]]+$/, "", key)
|
||||
value = clean($2)
|
||||
colors[key] = value
|
||||
}
|
||||
|
||||
key == "foreground" { printf "\033]10;%s\007", value }
|
||||
key == "background" { printf "\033]11;%s\007", value }
|
||||
key == "cursor" { printf "\033]12;%s\007", value }
|
||||
key == "selection_background" { printf "\033]17;%s\007", value }
|
||||
key == "selection_foreground" { printf "\033]19;%s\007", value }
|
||||
key ~ /^color[0-9]+$/ {
|
||||
color_index = substr(key, 6) + 0
|
||||
if (color_index >= 0 && color_index <= 15) {
|
||||
printf "\033]4;%d;%s\007", color_index, value
|
||||
}
|
||||
END {
|
||||
alias_color("color0", "bg")
|
||||
alias_color("color0", "background")
|
||||
alias_color("color1", "red")
|
||||
alias_color("color2", "green")
|
||||
alias_color("color3", "yellow")
|
||||
alias_color("color4", "blue")
|
||||
alias_color("color5", "purple")
|
||||
alias_color("color6", "cyan")
|
||||
alias_color("color7", "fg")
|
||||
alias_color("color7", "foreground")
|
||||
alias_color("color8", "muted")
|
||||
alias_color("color8", "dark_fg")
|
||||
alias_color("color8", "foreground")
|
||||
alias_color("color9", "bright_red")
|
||||
alias_color("color9", "red")
|
||||
alias_color("color10", "bright_green")
|
||||
alias_color("color10", "green")
|
||||
alias_color("color11", "bright_yellow")
|
||||
alias_color("color11", "yellow")
|
||||
alias_color("color12", "bright_blue")
|
||||
alias_color("color12", "blue")
|
||||
alias_color("color13", "bright_purple")
|
||||
alias_color("color13", "purple")
|
||||
alias_color("color14", "bright_cyan")
|
||||
alias_color("color14", "cyan")
|
||||
alias_color("color15", "bright_fg")
|
||||
alias_color("color15", "foreground")
|
||||
|
||||
if (colors["foreground"] != "") printf "\033]10;%s\007", colors["foreground"]
|
||||
if (colors["background"] != "") printf "\033]11;%s\007", colors["background"]
|
||||
if (colors["cursor"] != "") printf "\033]12;%s\007", colors["cursor"]
|
||||
if (colors["selection_background"] != "") printf "\033]17;%s\007", colors["selection_background"]
|
||||
if (colors["selection_foreground"] != "") printf "\033]19;%s\007", colors["selection_foreground"]
|
||||
|
||||
for (i = 0; i <= 15; i++) emit_color(i, "color" i)
|
||||
}
|
||||
' "$theme"
|
||||
|
||||
@@ -8,9 +8,31 @@
|
||||
# 2. legacy `light.mode` file shipped beside the theme
|
||||
THEME_DIR=~/.config/omarchy/current/theme
|
||||
COLORS_FILE="$THEME_DIR/colors.toml"
|
||||
|
||||
theme_color() {
|
||||
local key="$1"
|
||||
|
||||
awk -F= -v key="$key" '
|
||||
{
|
||||
field = $1
|
||||
gsub(/^[[:space:]]+|[[:space:]]+$/, "", field)
|
||||
if (field == key) {
|
||||
value = $2
|
||||
gsub(/^[[:space:]]+|[[:space:]]+$/, "", value)
|
||||
if (value ~ /^"/) {
|
||||
sub(/^"/, "", value)
|
||||
sub(/".*$/, "", value)
|
||||
}
|
||||
print value
|
||||
exit
|
||||
}
|
||||
}
|
||||
' "$COLORS_FILE"
|
||||
}
|
||||
|
||||
mode=""
|
||||
if [[ -f $COLORS_FILE ]] && command -v tomlq >/dev/null; then
|
||||
mode=$(tomlq -r '.mode // empty' "$COLORS_FILE" 2>/dev/null)
|
||||
if [[ -f $COLORS_FILE ]]; then
|
||||
mode=$(theme_color mode)
|
||||
fi
|
||||
if [[ -z $mode && -f $THEME_DIR/light.mode ]]; then
|
||||
mode="light"
|
||||
|
||||
@@ -337,6 +337,20 @@ if [[ -f $COLORS_FILE ]]; then
|
||||
[[ ${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%)
|
||||
|
||||
# Keep semantic themes compatible with user templates that still reference
|
||||
# the legacy ANSI placeholders directly.
|
||||
declare -A ansi_alias=(
|
||||
[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
|
||||
)
|
||||
for key in "${!ansi_alias[@]}"; do
|
||||
[[ ${THEME_COLORS[$key]} ]] || THEME_COLORS[$key]="${THEME_COLORS[${ansi_alias[$key]}]}"
|
||||
done
|
||||
|
||||
# Resolve theme mode (dark|light) with this precedence:
|
||||
# 1. `mode` key in colors.toml
|
||||
# 2. legacy `light.mode` file shipped beside the theme
|
||||
|
||||
@@ -37,8 +37,11 @@ sync_theme_environment() {
|
||||
|
||||
sync_colorfgbg() {
|
||||
local colorfgbg="15;0"
|
||||
local mode
|
||||
|
||||
if [[ -f $CURRENT_THEME_PATH/light.mode ]]; then
|
||||
mode=$(theme_color mode)
|
||||
|
||||
if [[ $mode == "light" ]] || [[ -z $mode && -f $CURRENT_THEME_PATH/light.mode ]]; then
|
||||
colorfgbg="0;15"
|
||||
fi
|
||||
|
||||
|
||||
@@ -9,9 +9,14 @@ 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
|
||||
local theme_type ui_theme
|
||||
|
||||
theme_type=$(jq -r '.type // "dark"' "$GENERATED_THEME")
|
||||
if [[ $theme_type == "light" ]]; then
|
||||
ui_theme="vs"
|
||||
else
|
||||
ui_theme="vs-dark"
|
||||
fi
|
||||
|
||||
mkdir -p "$ext_dir/themes"
|
||||
cp "$GENERATED_THEME" "$ext_dir/themes/omarchy-color-theme.json"
|
||||
@@ -28,7 +33,7 @@ install_generated_extension() {
|
||||
"contributes": {
|
||||
"themes": [{
|
||||
"label": "Omarchy",
|
||||
"uiTheme": "vs-${theme_type}",
|
||||
"uiTheme": "$ui_theme",
|
||||
"path": "./themes/omarchy-color-theme.json"
|
||||
}]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user