less hardcoding in theme selection and row highlighting

This commit is contained in:
ksyasuda 2022-02-13 12:06:06 -08:00
parent e29d3f7db3
commit 90dec870e0
2 changed files with 20 additions and 79 deletions

34
ani-cli
View File

@ -4,7 +4,7 @@ CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper"
HISTORY_DB="$CFG_DIR/history.sqlite3"
ROFI_CFG="$CFG_DIR/themes/aniwrapper.rasi"
ROFI_THEME="aniwrapper.rasi"
THEMES="aniwrapper (default)|dracula|doomone|fancy|material|nord|nord2|onedark"
THEMES="aniwrapper|dracula|doomone|fancy|material|nord|nord2|onedark"
ANIWRAPPER_ICON_PATH="$CFG_DIR/icons/icon-64.png"
MAISAN_ICON_PATH="$CFG_DIR/icons/MYsan.png"
DPI=96
@ -723,35 +723,15 @@ parse_args() {
t)
theme="$OPTARG"
case "$theme" in
aniwrapper)
aniwrapper | default)
ROFI_THEME=aniwrapper.rasi
;;
default)
ROFI_THEME=aniwrapper.rasi
;;
dracula)
ROFI_THEME=aniwrapper-dracula.rasi
;;
doomone | doom-one)
ROFI_THEME=aniwrapper-doomone.rasi
;;
fancy)
ROFI_THEME=aniwrapper-fancy.rasi
;;
material)
ROFI_THEME=aniwrapper-material.rasi
;;
nord)
ROFI_THEME=aniwrapper-nord.rasi
;;
nord2)
ROFI_THEME=aniwrapper-nord2.rasi
;;
onedark)
ROFI_THEME=aniwrapper-onedark.rasi
;;
*)
die "$theme not a valid theme file. Themes: [$THEMES]"
if [[ "$theme" =~ ($THEMES) ]]; then
ROFI_THEME="aniwrapper-$theme.rasi"
else
die "Invalid theme: $theme. Please choose from: $THEMES"
fi
;;
esac
lg "Setting theme for ani-cli -> $ROFI_THEME"

View File

@ -133,36 +133,18 @@ get_quality() {
# return the index in $THEMES of $ROFI_THEME
get_theme_idx() {
case "$ROFI_THEME" in
aniwrapper.rasi)
theme_idx=0
;;
aniwrapper-dracula.rasi)
theme_idx=1
;;
aniwrapper-doomone.rasi)
theme_idx=2
;;
aniwrapper-fancy.rasi)
theme_idx=3
;;
aniwrapper-material.rasi)
theme_idx=4
;;
aniwrapper-nord.rasi)
theme_idx=5
;;
aniwrapper-nord2.rasi)
theme_idx=6
;;
aniwrapper-onedark.rasi)
theme_idx=7
;;
*)
exit 1
;;
esac
printf "%s" "$theme_idx"
themeslist="aniwrapper.rasi|aniwrapper-dracula.rasi|aniwrapper-doomone.rasi|aniwrapper-fancy.rasi|aniwrapper-material.rasi|aniwrapper-nord.rasi|aniwrapper-nord2.rasi|aniwrapper-onedark.rasi"
idx=0
while IFS='|' read -ra themes; do
for t in "${themes[@]}"; do
if [[ "$t" == "$ROFI_THEME" ]]; then
lg "theme -> $t | theme index -> $idx" > /dev/stderr
printf "%s\n" "$idx"
break
fi
((++idx))
done
done <<< "$themeslist"
}
# generates a span mesg for rofi given
@ -179,29 +161,8 @@ set_theme() {
aniwrapper)
ROFI_THEME=aniwrapper.rasi
;;
dracula)
ROFI_THEME=aniwrapper-dracula.rasi
;;
doomone | doom-one)
ROFI_THEME=aniwrapper-doomone.rasi
;;
fancy)
ROFI_THEME=aniwrapper-fancy.rasi
;;
material)
ROFI_THEME=aniwrapper-material.rasi
;;
nord)
ROFI_THEME=aniwrapper-nord.rasi
;;
nord2)
ROFI_THEME=aniwrapper-nord2.rasi
;;
onedark)
ROFI_THEME=aniwrapper-onedark.rasi
;;
*)
seppuku "$theme not a valid theme file. Themes: [$THEMES]"
ROFI_THEME="aniwrapper-$new_theme.rasi"
;;
esac
lg "Chosen theme -> $ROFI_THEME"