Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion bin/omarchy-dev-theme-preview
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ normalize_theme_name() {
printf '%s' "$1" | sed -E 's/<[^>]+>//g' | tr '[:upper:]' '[:lower:]' | tr ' ' '-'
}

# A theme from before colors.toml is previewed with the palette omarchy-theme-set would generate for it.
colors_from_alacritty() {
cp "$1/alacritty.toml" "$SCRATCH_DIR/" || return 1
omarchy_tool omarchy-theme-colors-from-alacritty "$SCRATCH_DIR" >/dev/null
[[ -f $SCRATCH_DIR/colors.toml ]] && printf '%s/colors.toml' "$SCRATCH_DIR"
}

resolve_colors_file() {
local ref="$1"
local theme_name
Expand All @@ -72,6 +79,8 @@ resolve_colors_file() {
printf '%s' "$ref"
elif [[ -d $ref && -f $ref/colors.toml ]]; then
printf '%s/colors.toml' "$ref"
elif [[ -d $ref && -f $ref/alacritty.toml ]]; then
colors_from_alacritty "$ref"
else
for theme_name in "$ref" "$(normalize_theme_name "$ref")"; do
if [[ -f $USER_THEMES_PATH/$theme_name/colors.toml ]]; then
Expand All @@ -80,6 +89,9 @@ resolve_colors_file() {
elif [[ -f $OMARCHY_THEMES_PATH/$theme_name/colors.toml ]]; then
printf '%s/colors.toml' "$OMARCHY_THEMES_PATH/$theme_name"
return
elif [[ -f $USER_THEMES_PATH/$theme_name/alacritty.toml ]]; then
colors_from_alacritty "$USER_THEMES_PATH/$theme_name"
return
fi
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
done
return 1
Expand Down Expand Up @@ -399,6 +411,9 @@ print_neutral_ramp() {
done
}

SCRATCH_DIR=$(mktemp -d) || exit 1
trap 'rm -rf "$SCRATCH_DIR"' EXIT

colors_file=$(resolve_colors_file "$THEME_REF") || {
echo "Theme not found: $THEME_REF" >&2
exit 1
Expand All @@ -425,7 +440,11 @@ fi
apply_terminal_osc

printf 'Theme: %s\n' "$theme_label"
printf 'File: %s\n' "$colors_file"
if [[ $colors_file == "$SCRATCH_DIR"/* ]]; then
printf 'File: generated from alacritty.toml\n'
else
printf 'File: %s\n' "$colors_file"
fi
printf 'Mode: %s\n' "$mode"
if [[ ${COLORS[foreground]} =~ ^#[0-9A-Fa-f]{6}$ && ${COLORS[background]} =~ ^#[0-9A-Fa-f]{6}$ ]]; then
printf 'foreground/background contrast: %s:1\n' "$(contrast_ratio "${COLORS[foreground]}" "${COLORS[background]}")"
Expand Down
28 changes: 28 additions & 0 deletions test/cli
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,34 @@ cp "$NEXT_THEME/colors.toml" "$PI_TMPDIR/.config/omarchy/themes/Walk Handmade Th
preview_output=$(OMARCHY_PATH="$ROOT" HOME="$PI_TMPDIR" "$ROOT/bin/omarchy-dev-theme-preview" "Walk Handmade Theme" --no-color --no-osc)
assert_output_contains "theme preview finds a hand-made theme by its folder name" "$preview_output" "themes/Walk Handmade Theme/colors.toml"

legacy_alacritty_dir="$PI_TMPDIR/.config/omarchy/themes/Gruvbox"
legacy_preview_tmp="$PI_TMPDIR/preview-tmp"
mkdir -p "$legacy_alacritty_dir" "$legacy_preview_tmp"
cat >"$legacy_alacritty_dir/alacritty.toml" <<'EOF'
[colors.primary]
background = "#121314"
foreground = "#e1e2e3"

[colors.normal]
black = "#121314"
red = "#cc241d"
green = "#98971a"
yellow = "#d79921"
blue = "#458588"
magenta = "#b16286"
cyan = "#689d6a"
white = "#e1e2e3"
EOF

preview_output=$(TMPDIR="$legacy_preview_tmp" OMARCHY_PATH="$ROOT" HOME="$PI_TMPDIR" "$ROOT/bin/omarchy-dev-theme-preview" "$legacy_alacritty_dir" --no-color --no-osc)
assert_output_contains "theme preview converts an alacritty-only theme directory" "$preview_output" "#121314"

preview_output=$(TMPDIR="$legacy_preview_tmp" OMARCHY_PATH="$ROOT" HOME="$PI_TMPDIR" "$ROOT/bin/omarchy-dev-theme-preview" "Gruvbox" --no-color --no-osc)
assert_output_contains "theme preview prefers an exact alacritty-only theme name over the bundled normalized theme" "$preview_output" "#e1e2e3"

[[ ! -e $legacy_alacritty_dir/colors.toml && -z $(ls -A "$legacy_preview_tmp") ]] || fail "theme preview leaves an alacritty-only theme and the temp directory as it found them"
pass "theme preview leaves an alacritty-only theme and the temp directory as it found them"

tokyo_fg=$(awk -F'"' '/^foreground =/ { print $2; exit }' "$ROOT/themes/tokyo-night/colors.toml")
tokyo_light_fg=$(awk -F'"' '/^light_foreground =/ { print $2; exit }' "$ROOT/themes/tokyo-night/colors.toml")
tokyo_bright_fg=$(awk -F'"' '/^bright_foreground =/ { print $2; exit }' "$ROOT/themes/tokyo-night/colors.toml")
Expand Down
Loading