refactor(klipper): refactor the printing of the dialogs into own functions

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
th33xitus
2022-11-01 19:51:07 +01:00
parent a5aa250271
commit 82c4490071

View File

@@ -56,16 +56,7 @@ function start_klipper_setup() {
[[ -n ${error} ]] && print_error "${error}" && return [[ -n ${error} ]] && print_error "${error}" && return
### user selection for python version ### user selection for python version
top_border print_dialog_user_select_python_version
echo -e "| Please select the preferred Python version. | "
echo -e "| The recommended version is Python 2.7. | "
blank_line
echo -e "| Installing Klipper with Python 3 is officially not | "
echo -e "| recommended and should be considered as experimental. | "
hr
echo -e "| 1) [Python 2.7] (recommended) | "
echo -e "| 2) [Python 3.x] ${yellow}(experimental)${white} | "
back_footer
while true; do while true; do
read -p "${cyan}###### Select Python version:${white} " input read -p "${cyan}###### Select Python version:${white} " input
case "${input}" in case "${input}" in
@@ -85,15 +76,7 @@ function start_klipper_setup() {
done && unset input done && unset input
### user selection for instance count ### user selection for instance count
top_border print_dialog_user_select_instance_count
echo -e "| Please select the number of Klipper instances to set |"
echo -e "| up. The number of Klipper instances will determine |"
echo -e "| the amount of printers you can run from this host. |"
blank_line
echo -e "| ${yellow}WARNING:${white} |"
echo -e "| ${yellow}Setting up too many instances may crash your system.${white} |"
back_footer
regex="^[1-9][0-9]*$" regex="^[1-9][0-9]*$"
while [[ ! ${input} =~ ${regex} ]]; do while [[ ! ${input} =~ ${regex} ]]; do
read -p "${cyan}###### Number of Klipper instances to set up:${white} " input read -p "${cyan}###### Number of Klipper instances to set up:${white} " input
@@ -112,14 +95,7 @@ function start_klipper_setup() {
### user selection for custom names ### user selection for custom names
use_custom_names="false" use_custom_names="false"
if (( instance_count > 1 )); then if (( instance_count > 1 )); then
top_border print_dialog_user_select_custom_name_bool
echo -e "| You can now assign a custom name to each instance. |"
echo -e "| If skipped, each instance will get an index assigned |"
echo -e "| in ascending order, starting at index '1'. |"
blank_line
echo -e "| Info: |"
echo -e "| Only alphanumeric characters for names are allowed! |"
back_footer
while true; do while true; do
read -p "${cyan}###### Assign custom names? (y/N):${white} " input read -p "${cyan}###### Assign custom names? (y/N):${white} " input
case "${input}" in case "${input}" in
@@ -135,7 +111,7 @@ function start_klipper_setup() {
*) *)
error_msg "Invalid Input!";; error_msg "Invalid Input!";;
esac esac
done done && unset input
else else
instance_names+=("printer") instance_names+=("printer")
fi fi
@@ -146,7 +122,6 @@ function start_klipper_setup() {
i=1 i=1
regex="^[0-9a-zA-Z]+$" regex="^[0-9a-zA-Z]+$"
while [[ ! ${input} =~ ${regex} || ${i} -le ${instance_count} ]]; do while [[ ! ${input} =~ ${regex} || ${i} -le ${instance_count} ]]; do
read -p "${cyan}###### Name for instance #${i}:${white} " input read -p "${cyan}###### Name for instance #${i}:${white} " input
@@ -158,9 +133,8 @@ function start_klipper_setup() {
else else
error_msg "Invalid Input!" error_msg "Invalid Input!"
fi fi
done done && unset input
else else
### if no custom names are used, add the respective amount of indices to the user_input array
for (( i=1; i <= instance_count; i++ )); do for (( i=1; i <= instance_count; i++ )); do
instance_names+=("printer_${i}") instance_names+=("printer_${i}")
done done
@@ -172,6 +146,41 @@ function start_klipper_setup() {
run_klipper_setup "${python_version}" "${instance_names[@]}" run_klipper_setup "${python_version}" "${instance_names[@]}"
} }
function print_dialog_user_select_python_version() {
top_border
echo -e "| Please select the preferred Python version. | "
echo -e "| The recommended version is Python 2.7. | "
blank_line
echo -e "| Installing Klipper with Python 3 is officially not | "
echo -e "| recommended and should be considered as experimental. | "
hr
echo -e "| 1) [Python 2.7] (recommended) | "
echo -e "| 2) [Python 3.x] ${yellow}(experimental)${white} | "
back_footer
}
function print_dialog_user_select_instance_count() {
top_border
echo -e "| Please select the number of Klipper instances to set |"
echo -e "| up. The number of Klipper instances will determine |"
echo -e "| the amount of printers you can run from this host. |"
blank_line
echo -e "| ${yellow}WARNING:${white} |"
echo -e "| ${yellow}Setting up too many instances may crash your system.${white} |"
back_footer
}
function print_dialog_user_select_custom_name_bool() {
top_border
echo -e "| You can now assign a custom name to each instance. |"
echo -e "| If skipped, each instance will get an index assigned |"
echo -e "| in ascending order, starting at index '1'. |"
blank_line
echo -e "| Info: |"
echo -e "| Only alphanumeric characters for names are allowed! |"
back_footer
}
function run_klipper_setup() { function run_klipper_setup() {
read_kiauh_ini "${FUNCNAME[0]}" read_kiauh_ini "${FUNCNAME[0]}"