Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 1 addition & 14 deletions dist/theme/bin/theme
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,6 @@ theme_warn() {
theme_run() {
local arg="${1:-}"

if [[ "$arg" == "--detect" ]]; then
theme_detect
printf '%s\n' "$THEME_APPEARANCE"
return 0
fi

if [[ "$arg" == "--list" ]]; then
theme_list
return 0
fi

theme_source_config

if ! theme_discover_provider; then
Expand All @@ -353,9 +342,7 @@ theme_run() {
;;
esac

if ! theme_detect "$override"; then
return 1
fi
theme_detect "$override"

"$THEME_PROVIDER" "$THEME_APPEARANCE" "$THEME_SOURCE"

Expand Down
29 changes: 29 additions & 0 deletions scripts/theme/main_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ Describe 'theme'
The output should be present
End

It 'falls back to THEME env var when set to light'
# Remove detector so it falls through to THEME env
rm -f "$XDG_CONFIG_HOME/theme/detectors.d/noop.sh"
export THEME=light
When run script "$BIN" -q --detect
The status should be success
The output should equal "light"
End

It 'rejects invalid override with --detect'
When run script "$BIN" --detect invalid
The status should be failure
The stderr should include "invalid appearance"
End

It 'falls back to light when THEME env var is invalid'
export THEME=invalid_value
# Clear any system-level detection by running in isolated env
Expand Down Expand Up @@ -399,6 +414,20 @@ EOF
The output should equal "PROVIDER_RAN"
The stderr should include "no detectors configured"
End

It 'handles non-existent handlers.d directory gracefully'
cat > "$XDG_CONFIG_HOME/theme/provider.sh" << 'EOF'
theme_provider_test() {
echo "PROVIDER_RAN"
}
EOF
# Remove handlers.d directory entirely
rm -rf "$XDG_CONFIG_HOME/theme/handlers.d"
export THEME=dark
When run script "$BIN" -q
The status should be success
The output should equal "PROVIDER_RAN"
End
End

#═══════════════════════════════════════════════════════════════
Expand Down
21 changes: 4 additions & 17 deletions scripts/theme/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,11 @@ theme_warn() {
}

# Main orchestration function
# Usage: theme_run [--detect|--list|dark|light|auto]
# Usage: theme_run [dark|light|auto]
# Note: --detect and --list are handled by main.sh before calling this
theme_run() {
local arg="${1:-}"

# Handle --detect: only detect and print, no provider/handlers
if [[ "$arg" == "--detect" ]]; then
theme_detect
printf '%s\n' "$THEME_APPEARANCE"
return 0
fi

# Handle --list: list provider and handlers
if [[ "$arg" == "--list" ]]; then
theme_list
return 0
fi

# Source user configuration (provider.sh, handlers.d/*.sh)
theme_source_config

Expand All @@ -55,9 +43,8 @@ theme_run() {
;;
esac

if ! theme_detect "$override"; then
return 1
fi
# Note: override is validated above, so theme_detect can't fail here
theme_detect "$override"

# Call provider with appearance and source
"$THEME_PROVIDER" "$THEME_APPEARANCE" "$THEME_SOURCE"
Expand Down