refactor: improve mainsail theme installer
better printer selection for installing and removing themes Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
@@ -326,7 +326,7 @@ function print_theme_list() {
|
|||||||
|
|
||||||
while IFS="," read -r col1 col2 col3 col4; do
|
while IFS="," read -r col1 col2 col3 col4; do
|
||||||
if [[ ${col1} != "name" ]]; then
|
if [[ ${col1} != "name" ]]; then
|
||||||
printf "| ${i}) %-50s|\n" "[${col1}]"
|
printf "| ${i}) %-51s|\n" "[${col1}]"
|
||||||
fi
|
fi
|
||||||
i=$(( i + 1 ))
|
i=$(( i + 1 ))
|
||||||
done <<< "${theme_list}"
|
done <<< "${theme_list}"
|
||||||
@@ -338,18 +338,18 @@ function ms_theme_installer_menu() {
|
|||||||
theme_list=$(curl -s -L "${theme_csv_url}")
|
theme_list=$(curl -s -L "${theme_csv_url}")
|
||||||
|
|
||||||
top_border
|
top_border
|
||||||
echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${white} | "
|
echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${white} |"
|
||||||
hr
|
hr
|
||||||
echo -e "| ${green}A preview of each Mainsail theme can be found here:${white} | "
|
echo -e "| ${green}A preview of each Mainsail theme can be found here:${white} |"
|
||||||
echo -e "| https://docs.mainsail.xyz/theming/themes | "
|
echo -e "| https://docs.mainsail.xyz/theming/themes |"
|
||||||
blank_line
|
blank_line
|
||||||
echo -e "| ${yellow}Important note:${white} | "
|
echo -e "| ${yellow}Important note:${white} |"
|
||||||
echo -e "| Installing a theme from this menu will overwrite an | "
|
echo -e "| Installing a theme from this menu will overwrite an |"
|
||||||
echo -e "| already installed theme or modified custom.css file! | "
|
echo -e "| already installed theme or modified custom.css file! |"
|
||||||
hr
|
hr
|
||||||
print_theme_list "${theme_list}"
|
print_theme_list "${theme_list}"
|
||||||
echo -e "| | "
|
echo -e "| |"
|
||||||
echo -e "| R) [Remove Theme] | "
|
echo -e "| R) [Remove Theme] |"
|
||||||
back_footer
|
back_footer
|
||||||
|
|
||||||
while IFS="," read -r col1 col2 col3 col4; do
|
while IFS="," read -r col1 col2 col3 col4; do
|
||||||
@@ -379,27 +379,41 @@ function ms_theme_installer_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ms_theme_install() {
|
function ms_theme_install() {
|
||||||
local path moonraker_count theme_url=${1} theme_name theme_note
|
local theme_url=${1} theme_name theme_note
|
||||||
theme_name=${2} theme_note=${3}
|
theme_name=${2} theme_note=${3}
|
||||||
path="$(get_klipper_cfg_dir)"
|
|
||||||
moonraker_count=$(moonraker_systemd | wc -w)
|
|
||||||
|
|
||||||
if (( moonraker_count > 1 )); then
|
local config_folders target_folders=()
|
||||||
|
config_folders=$(find "${KLIPPER_CONFIG}" -mindepth 1 -maxdepth 1 -type d | sort)
|
||||||
|
|
||||||
|
### build target folder array
|
||||||
|
for folder in ${config_folders}; do
|
||||||
|
target_folders+=("${folder}")
|
||||||
|
done
|
||||||
|
|
||||||
|
if (( ${#target_folders[@]} > 1 )); then
|
||||||
top_border
|
top_border
|
||||||
echo -e "| More than one printer was found on this system! | "
|
echo -e "| Please select the printer you want to apply the theme |"
|
||||||
echo -e "| Please select the printer to which you want to | "
|
echo -e "| installation to: |"
|
||||||
echo -e "| apply the previously selected action. | "
|
for (( i=0; i < ${#target_folders[@]}; i++ )); do
|
||||||
|
folder=$(echo "${target_folders[${i}]}" | rev | cut -d "/" -f1 | rev)
|
||||||
|
printf "|${cyan}%-55s${white}|\n" " ${i}) ${folder}"
|
||||||
|
done
|
||||||
bottom_border
|
bottom_border
|
||||||
#TODO: list printers depending on moonraker instance names for the user to select from
|
|
||||||
read -p "${cyan}Select printer:${white} " printer
|
local target re="^[0-9]*$"
|
||||||
path="${path}/printer_${printer}"
|
while true; do
|
||||||
|
read -p "${cyan}###### Select printer:${white} " target
|
||||||
|
### break while loop if input is valid, else display error
|
||||||
|
[[ ${target} =~ ${re} && ${target} -lt ${#target_folders[@]} ]] && break
|
||||||
|
error_msg "Invalid command!"
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ ! -d ${path} ]] && mkdir -p "${path}"
|
[[ -d "${target_folders[${target}]}/.theme" ]] && rm -rf "${target_folders[${target}]}/.theme"
|
||||||
[[ -d "${path}/.theme" ]] && rm -rf "${path}/.theme"
|
|
||||||
|
|
||||||
status_msg "Installing ${theme_name[${option}]} ..."
|
status_msg "Installing ${theme_name[${option}]} ..."
|
||||||
cd "${path}" &&
|
cd "${target_folders[${target}]}"
|
||||||
|
|
||||||
if git clone "${theme_url}" ".theme"; then
|
if git clone "${theme_url}" ".theme"; then
|
||||||
ok_msg "Theme installation complete!"
|
ok_msg "Theme installation complete!"
|
||||||
[[ -n ${theme_note} ]] && echo "${yellow}###### Theme Info: ${theme_note}${white}"
|
[[ -n ${theme_note} ]] && echo "${yellow}###### Theme Info: ${theme_note}${white}"
|
||||||
@@ -410,27 +424,40 @@ function ms_theme_install() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ms_theme_delete() {
|
function ms_theme_delete() {
|
||||||
local path moonraker_count
|
local theme_folders target_folders=()
|
||||||
path="$(get_klipper_cfg_dir)"
|
theme_folders=$(find "${KLIPPER_CONFIG}" -mindepth 1 -type d -name ".theme" | sort)
|
||||||
moonraker_count=$(moonraker_systemd | wc -w)
|
|
||||||
|
|
||||||
if (( moonraker_count > 1 )); then
|
### build target folder array
|
||||||
|
for folder in ${theme_folders}; do
|
||||||
|
target_folders+=("${folder}")
|
||||||
|
done
|
||||||
|
|
||||||
|
if (( ${#target_folders[@]} > 0 )); then
|
||||||
top_border
|
top_border
|
||||||
echo -e "| More than one printer was found on this system! | "
|
echo -e "| Please select the printer you want to remove the |"
|
||||||
echo -e "| Please select the printer to which you want to | "
|
echo -e "| theme installation from. |"
|
||||||
echo -e "| apply the previously selected action. | "
|
for (( i=0; i < ${#target_folders[@]}; i++ )); do
|
||||||
|
folder=$(echo "${target_folders[${i}]}" | rev | cut -d "/" -f2 | rev)
|
||||||
|
printf "|${cyan}%-55s${white}|\n" " ${i}) ${folder}"
|
||||||
|
done
|
||||||
bottom_border
|
bottom_border
|
||||||
#TODO: list all found .theme folders and let the user select
|
|
||||||
read -p "${cyan}Select printer:${white} " printer
|
local target re="^[0-9]*$"
|
||||||
path="${path}/printer_${printer}"
|
while true; do
|
||||||
|
read -p "${cyan}###### Select printer:${white} " target
|
||||||
|
### break while loop if input is valid, else display error
|
||||||
|
[[ ${target} =~ ${re} && ${target} -lt ${#target_folders[@]} ]] && break
|
||||||
|
error_msg "Invalid command!"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
status_msg "No Themes installed!\n"
|
||||||
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -d "${path}/.theme" ]]; then
|
status_msg "Removing Theme ..."
|
||||||
status_msg "Removing Theme ..."
|
rm -rf "${target_folders[${target}]}" && ok_msg "Theme removed!\n"
|
||||||
rm -rf "${path}/.theme" && ok_msg "Theme removed!\n"
|
|
||||||
else
|
return
|
||||||
status_msg "No Theme installed!\n"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#================================================#
|
#================================================#
|
||||||
|
|||||||
Reference in New Issue
Block a user