diff --git a/kiauh/modules/klipper/klipper_dialogs.py b/kiauh/modules/klipper/klipper_dialogs.py index cc8d15c..9bb46f1 100644 --- a/kiauh/modules/klipper/klipper_dialogs.py +++ b/kiauh/modules/klipper/klipper_dialogs.py @@ -9,6 +9,7 @@ # This file may be distributed under the terms of the GNU GPLv3 license # # ======================================================================= # +import textwrap from typing import List from kiauh.instance_manager.base_instance import BaseInstance @@ -20,96 +21,116 @@ def print_instance_overview( instances: List[BaseInstance], show_index=False, show_select_all=False ): headline = f"{COLOR_GREEN}The following Klipper instances were found:{RESET_FORMAT}" - - print("/=======================================================\\") - print(f"|{'{:^64}'.format(headline)}|") - print("|-------------------------------------------------------|") + dialog = textwrap.dedent( + f""" + /=======================================================\\ + |{'{:^64}'.format(headline)}| + |-------------------------------------------------------| + """ + )[1:] if show_select_all: - select_all = f" {COLOR_YELLOW}a) Select all{RESET_FORMAT}" - print(f"|{'{:64}'.format(select_all)}|") - print("| |") + select_all = f"{COLOR_YELLOW}a) Select all{RESET_FORMAT}" + dialog += f"| {'{:63}'.format(select_all)}|" + dialog += "| |" for i, s in enumerate(instances): - index = f"{i})" if show_index else "●" - instance = s.get_service_file_name() - line = f"{'{:53}'.format(f'{index} {instance}')}" - print(f"| {COLOR_CYAN}{line}{RESET_FORMAT}|") + line = f"{COLOR_CYAN}{'{i})' if show_index else '●'} {s.get_service_file_name()}{RESET_FORMAT}" + dialog += f"| {'{:63}'.format(line)}|" + print(dialog) print_back_footer() def print_select_instance_count_dialog(): - print("/=======================================================\\") - print("| Please select the number of Klipper instances to set |") - print("| up. The number of Klipper instances will determine |") - print("| the amount of printers you can run from this host. |") - print("| |") - print( - f"| {COLOR_YELLOW}WARNING:{RESET_FORMAT} |" - ) - print( - f"| {COLOR_YELLOW}Setting up too many instances may crash your system.{RESET_FORMAT} |" - ) + line1 = f"{COLOR_YELLOW}WARNING:{RESET_FORMAT}" + line2 = f"{COLOR_YELLOW}Setting up too many instances may crash your system.{RESET_FORMAT}" + dialog = textwrap.dedent( + f""" + /=======================================================\\ + | Please select the number of Klipper instances to set | + | up. The number of Klipper instances will determine | + | the amount of printers you can run from this host. | + | | + | {'{:63}'.format(line1)}| + | {'{:63}'.format(line2)}| + """ + )[1:] + + print(dialog, end="") print_back_footer() def print_select_custom_name_dialog(): - print("/=======================================================\\") - print("| You can now assign a custom name to each instance. |") - print("| If skipped, each instance will get an index assigned |") - print("| in ascending order, starting at index '1'. |") - print("| |") - print( - f"| {COLOR_YELLOW}INFO:{RESET_FORMAT} |" - ) - print( - f"| {COLOR_YELLOW}Only alphanumeric characters are allowed!{RESET_FORMAT} |" - ) + line1 = f"{COLOR_YELLOW}INFO:{RESET_FORMAT}" + line2 = f"{COLOR_YELLOW}Only alphanumeric characters are allowed!{RESET_FORMAT}" + dialog = textwrap.dedent( + f""" + /=======================================================\\ + | You can now assign a custom name to each instance. | + | If skipped, each instance will get an index assigned | + | in ascending order, starting at index '1'. | + | | + | {'{:63}'.format(line1)}| + | {'{:63}'.format(line2)}| + """ + )[1:] + + print(dialog, end="") print_back_footer() def print_missing_usergroup_dialog(missing_groups) -> None: - print("/=======================================================\\") - print( - f"| {COLOR_YELLOW}WARNING: Your current user is not in group:{RESET_FORMAT} |" - ) + line1 = f"{COLOR_YELLOW}WARNING: Your current user is not in group:{RESET_FORMAT}" + line2 = f"{COLOR_CYAN}● tty{RESET_FORMAT}" + line3 = f"{COLOR_CYAN}● dialout{RESET_FORMAT}" + line4 = f"{COLOR_YELLOW}INFO:{RESET_FORMAT}" + line5 = f"{COLOR_YELLOW}Relog required for group assignments to take effect!{RESET_FORMAT}" + + dialog = textwrap.dedent( + f""" + /=======================================================\\ + | {'{:63}'.format(line1)}| + """ + )[1:] + if "tty" in missing_groups: - print( - f"| {COLOR_CYAN}● tty{RESET_FORMAT} |" - ) + dialog += f"| {'{:63}'.format(line2)}|\n" if "dialout" in missing_groups: - print( - f"| {COLOR_CYAN}● dialout{RESET_FORMAT} |" - ) - print("| |") - print("| It is possible that you won't be able to successfully |") - print("| connect and/or flash the controller board without |") - print("| your user being a member of that group. |") - print("| If you want to add the current user to the group(s) |") - print("| listed above, answer with 'Y'. Else skip with 'n'. |") - print("| |") - print( - f"| {COLOR_YELLOW}INFO:{RESET_FORMAT} |" - ) - print( - f"| {COLOR_YELLOW}Relog required for group assignments to take effect!{RESET_FORMAT} |" - ) - print("\\=======================================================/") + dialog += f"| {'{:63}'.format(line3)}|\n" + + dialog += textwrap.dedent( + f""" + | | + | It is possible that you won't be able to successfully | + | connect and/or flash the controller board without | + | your user being a member of that group. | + | If you want to add the current user to the group(s) | + | listed above, answer with 'Y'. Else skip with 'n'. | + | | + | {'{:63}'.format(line4)}| + | {'{:63}'.format(line5)}| + \\=======================================================/ + """ + )[1:] + + print(dialog, end="") def print_update_warn_dialog(): - print("/=======================================================\\") - print( - f"| {COLOR_YELLOW}WARNING: {RESET_FORMAT}|" - ) - print( - f"| {COLOR_YELLOW}Do NOT continue if there are ongoing prints running! {RESET_FORMAT}|" - ) - print( - f"| {COLOR_YELLOW}All Klipper instances will be restarted during the {RESET_FORMAT}|" - ) - print( - f"| {COLOR_YELLOW}update process and any ongoing prints WILL FAIL. {RESET_FORMAT}|" - ) - print("\\=======================================================/") + line1 = f"{COLOR_YELLOW}WARNING:{RESET_FORMAT}" + line2 = f"{COLOR_YELLOW}Do NOT continue if there are ongoing prints running!{RESET_FORMAT}" + line3 = f"{COLOR_YELLOW}All Klipper instances will be restarted during the {RESET_FORMAT}" + line4 = f"{COLOR_YELLOW}update process and ongoing prints WILL FAIL.{RESET_FORMAT}" + dialog = textwrap.dedent( + f""" + /=======================================================\\ + | {'{:63}'.format(line1)}| + | {'{:63}'.format(line2)}| + | {'{:63}'.format(line3)}| + | {'{:63}'.format(line4)}| + \\=======================================================/ + """ + )[1:] + + print(dialog, end="")