scripts: switch print_msg and main_menu to whiptail

This commit is contained in:
Yifei Ding
2021-11-09 11:41:56 -08:00
parent 415d057efe
commit e231c6b2d6
2 changed files with 77 additions and 59 deletions

View File

@@ -3,7 +3,7 @@
### Gettext Configuration ### Gettext Configuration
alias GETTEXT='gettext "KIAUH"' alias GETTEXT='gettext "KIAUH"'
clear #clear
set -e set -e
### set color variables ### set color variables
@@ -41,18 +41,12 @@ print_unkown_cmd(){
print_msg(){ print_msg(){
if [[ "$ERROR_MSG" != "" ]]; then if [[ "$ERROR_MSG" != "" ]]; then
echo -e "${red}" whiptail --title "$KIAUH_TITLE" --msgbox "$ERROR_MSG"\
echo -e "#########################################################" "$KIAUH_WHIPTAIL_SINGLE_LINE_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH"
echo -e " $ERROR_MSG "
echo -e "#########################################################"
echo -e "${default}"
fi fi
if [ "$CONFIRM_MSG" != "" ]; then if [ "$CONFIRM_MSG" != "" ]; then
echo -e "${green}" whiptail --title "$KIAUH_TITLE" --msgbox "$CONFIRM_MSG"\
echo -e "#########################################################" "$KIAUH_WHIPTAIL_SINGLE_LINE_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH"
echo -e " $CONFIRM_MSG "
echo -e "#########################################################"
echo -e "${default}"
fi fi
} }

View File

@@ -1,22 +1,22 @@
main_ui(){ #main_ui(){
#[ $KIAUH_UPDATE_REMIND="true" ] && kiauh_update_reminder #[ $KIAUH_UPDATE_REMIND="true" ] && kiauh_update_reminder
top_border # top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" # echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |"
hr # hr
echo -e "| 0) [Upload Log] | Klipper: $KLIPPER_STATUS|" # echo -e "| 0) [Upload Log] | Klipper: $KLIPPER_STATUS|"
echo -e "| | Branch: ${cyan}$PRINT_BRANCH${default}|" # echo -e "| | Branch: ${cyan}$PRINT_BRANCH${default}|"
echo -e "| 1) [Install] | |" # echo -e "| 1) [Install] | |"
echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|" # echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|"
echo -e "| 3) [Remove] | |" # echo -e "| 3) [Remove] | |"
echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" # echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|"
echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|" # echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|"
echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|" # echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|"
echo -e "| 6) [Settings] | Telegram Bot: $MOONRAKER_TELEGRAM_BOT_STATUS|" # echo -e "| 6) [Settings] | Telegram Bot: $MOONRAKER_TELEGRAM_BOT_STATUS|"
echo -e "| | |" # echo -e "| | |"
echo -e "| | DWC2: $DWC2_STATUS|" # echo -e "| | DWC2: $DWC2_STATUS|"
echo -e "| ${cyan}$KIAUH_VER${default}| Octoprint: $OCTOPRINT_STATUS|" # echo -e "| ${cyan}$KIAUH_VER${default}| Octoprint: $OCTOPRINT_STATUS|"
quit_footer # quit_footer
} #}
print_kiauh_version(){ print_kiauh_version(){
cd ${SRCDIR}/kiauh cd ${SRCDIR}/kiauh
@@ -40,7 +40,7 @@ kiauh_update_dialog(){
} }
main_menu(){ main_menu(){
print_header # print_header
#print KIAUH update msg if update available #print KIAUH update msg if update available
if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then
kiauh_update_dialog kiauh_update_dialog
@@ -57,36 +57,60 @@ main_menu(){
MoonrakerTelegramBot_status MoonrakerTelegramBot_status
print_branch print_branch
print_msg && clear_msg print_msg && clear_msg
main_ui
while true; do while true; do
read -p "${cyan}Perform action:${default} " action; echo MAIN_MENU=$(whiptail --title "$KIAUH_TITLE" --cancel-button "Quit" --menu "Choose an option:"\
case "$action" in "$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" 8\
"start klipper") do_action_service "start" "klipper"; main_ui;; "0 Upload Log" "Upload Log For Bug Report"\
"stop klipper") do_action_service "stop" "klipper"; main_ui;; "1 Status" "Status Page"\
"restart klipper") do_action_service "restart" "klipper"; main_ui;; "2 Install" "Install Instances"\
"start moonraker") do_action_service "start" "moonraker"; main_ui;; "3 Update" "Update Instances"\
"stop moonraker") do_action_service "stop" "moonraker"; main_ui;; "4 Remove" "Remove Instances"\
"restart moonraker")do_action_service "restart" "moonraker"; main_ui;; "5 Advanced" "Advanced Settings"\
"start dwc") do_action_service "start" "dwc"; main_ui;; "6 Backup" "Backup"\
"stop dwc") do_action_service "stop" "dwc"; main_ui;; "7 Settings" "Configure KIAUH" 3>&1 1>&2 2>&3)
"restart dwc") do_action_service "restart" "dwc"; main_ui;; case "$MAIN_MENU" in
"start octoprint") do_action_service "start" "octoprint"; main_ui;; 1\ *) echo "Current status" ;;
"stop octoprint") do_action_service "stop" "octoprint"; main_ui;; 2\ *) install_menu ;;
"restart octoprint") do_action_service "restart" "octoprint"; main_ui;; 3\ *) remove_menu ;;
update) do_action "update_kiauh" "main_ui";; 4\ *) advanced_menu ;;
0) do_action "upload_selection" "main_ui";; 5\ *) backup_menu ;;
1) clear && install_menu && break;; 6\ *) settings_menu ;;
2) clear && update_menu && break;; 7\ *) settings_menu ;;
3) clear && remove_menu && break;; 0\ *) upload_selection;;
4) clear && advanced_menu && break;; *) echo "Unknown Command";;
5) clear && backup_menu && break;;
6) clear && settings_menu && break;;
Q|q)
echo -e "${green}###### Happy printing! ######${default}"; echo
exit -1;;
*)
deny_action "main_ui";;
esac esac
done done
clear; main_menu
# while true; do
# read -p "${cyan}Perform action:${default} " action; echo
# case "$action" in
# "start klipper") do_action_service "start" "klipper"; main_ui;;
# "stop klipper") do_action_service "stop" "klipper"; main_ui;;
# "restart klipper") do_action_service "restart" "klipper"; main_ui;;
# "start moonraker") do_action_service "start" "moonraker"; main_ui;;
# "stop moonraker") do_action_service "stop" "moonraker"; main_ui;;
# "restart moonraker")do_action_service "restart" "moonraker"; main_ui;;
# "start dwc") do_action_service "start" "dwc"; main_ui;;
# "stop dwc") do_action_service "stop" "dwc"; main_ui;;
# "restart dwc") do_action_service "restart" "dwc"; main_ui;;
# "start octoprint") do_action_service "start" "octoprint"; main_ui;;
# "stop octoprint") do_action_service "stop" "octoprint"; main_ui;;
# "restart octoprint") do_action_service "restart" "octoprint"; main_ui;;
# update) do_action "update_kiauh" "main_ui";;
# 0) do_action "upload_selection" "main_ui";;
# 1) clear && install_menu && break;;
# 2) clear && update_menu && break;;
# 3) clear && remove_menu && break;;
# 4) clear && advanced_menu && break;;
# 5) clear && backup_menu && break;;
# 6) clear && settings_menu && break;;
# Q|q)
# echo -e "${green}###### Happy printing! ######${default}"; echo
# exit -1;;
# *)
# deny_action "main_ui";;
# esac
# done
# clear; main_menu
} }