From b19ba840ea441071c131d13b4e1064d84f1faddf Mon Sep 17 00:00:00 2001 From: dw-0 Date: Thu, 27 Jun 2024 20:15:29 +0200 Subject: [PATCH] refactor: add padding option to dialog Signed-off-by: Dominik Willner --- kiauh/components/crowsnest/crowsnest.py | 1 - kiauh/components/klipper/klipper_setup.py | 1 - kiauh/components/klipper/klipper_utils.py | 3 +-- .../menus/klipper_flash_menu.py | 1 - .../components/klipperscreen/klipperscreen.py | 1 - kiauh/components/mobileraker/mobileraker.py | 1 - .../components/webui_client/client_dialogs.py | 2 -- kiauh/core/menus/settings_menu.py | 1 - kiauh/core/settings/kiauh_settings.py | 1 - .../obico/moonraker_obico_extension.py | 4 ---- kiauh/utils/common.py | 1 - kiauh/utils/logger.py | 19 ++++++++----------- 12 files changed, 9 insertions(+), 27 deletions(-) diff --git a/kiauh/components/crowsnest/crowsnest.py b/kiauh/components/crowsnest/crowsnest.py index 99a30db..ed774c0 100644 --- a/kiauh/components/crowsnest/crowsnest.py +++ b/kiauh/components/crowsnest/crowsnest.py @@ -88,7 +88,6 @@ def print_multi_instance_warning(instances: List[Klipper]) -> None: "The following instances were found:", *_instances, ], - end="", ) diff --git a/kiauh/components/klipper/klipper_setup.py b/kiauh/components/klipper/klipper_setup.py index 4196f1f..85d7469 100644 --- a/kiauh/components/klipper/klipper_setup.py +++ b/kiauh/components/klipper/klipper_setup.py @@ -145,7 +145,6 @@ def update_klipper() -> None: "All Klipper instances will be restarted during the update process and " "ongoing prints WILL FAIL.", ], - end="", ) if not get_confirm("Update Klipper now?"): diff --git a/kiauh/components/klipper/klipper_utils.py b/kiauh/components/klipper/klipper_utils.py index d5c16ac..7ec7741 100644 --- a/kiauh/components/klipper/klipper_utils.py +++ b/kiauh/components/klipper/klipper_utils.py @@ -220,7 +220,6 @@ def check_user_groups(): "INFO:", "Relog required for group assignments to take effect!", ], - end="", ) if not get_confirm(f"Add user '{CURRENT_USER}' to group(s) now?"): @@ -272,7 +271,7 @@ def handle_disruptive_system_packages() -> None: "Please fix the problem manually. Otherwise, this may have " "undesirable effects on the operation of Klipper." ], - end="", + padding_bottom="", ) diff --git a/kiauh/components/klipper_firmware/menus/klipper_flash_menu.py b/kiauh/components/klipper_firmware/menus/klipper_flash_menu.py index eccd772..8af866c 100644 --- a/kiauh/components/klipper_firmware/menus/klipper_flash_menu.py +++ b/kiauh/components/klipper_firmware/menus/klipper_flash_menu.py @@ -353,7 +353,6 @@ class KlipperSelectSDFlashBoardMenu(BaseMenu): "\n\n", "If you are unsure, stick to the default 250000!", ], - end="", ) self.flash_options.selected_baudrate = get_number_input( question="Please set the baud rate", diff --git a/kiauh/components/klipperscreen/klipperscreen.py b/kiauh/components/klipperscreen/klipperscreen.py index ae522c5..d64d500 100644 --- a/kiauh/components/klipperscreen/klipperscreen.py +++ b/kiauh/components/klipperscreen/klipperscreen.py @@ -62,7 +62,6 @@ def install_klipperscreen() -> None: "KlipperScreens update manager configuration for Moonraker " "will not be added to any moonraker.conf.", ], - end="", ) if not get_confirm( "Continue KlipperScreen installation?", diff --git a/kiauh/components/mobileraker/mobileraker.py b/kiauh/components/mobileraker/mobileraker.py index 17416a2..5fee326 100644 --- a/kiauh/components/mobileraker/mobileraker.py +++ b/kiauh/components/mobileraker/mobileraker.py @@ -58,7 +58,6 @@ def install_mobileraker() -> None: "Mobileraker's companion's update manager configuration for Moonraker " "will not be added to any moonraker.conf.", ], - end="", ) if not get_confirm( "Continue Mobileraker's companion installation?", diff --git a/kiauh/components/webui_client/client_dialogs.py b/kiauh/components/webui_client/client_dialogs.py index f737410..e723274 100644 --- a/kiauh/components/webui_client/client_dialogs.py +++ b/kiauh/components/webui_client/client_dialogs.py @@ -100,7 +100,6 @@ def print_install_client_config_dialog(client: BaseWebClient) -> None: "If you already use these macros skip this step. Otherwise you should " "consider to answer with 'Y' to download the recommended macros.", ], - end="", ) @@ -115,5 +114,4 @@ def print_ipv6_warning_dialog() -> None: "If you think this warning is a false alarm, and you are sure that " "IPv6 is disabled, you can continue with the installation.", ], - end="", ) diff --git a/kiauh/core/menus/settings_menu.py b/kiauh/core/menus/settings_menu.py index 579c098..322c80d 100644 --- a/kiauh/core/menus/settings_menu.py +++ b/kiauh/core/menus/settings_menu.py @@ -144,7 +144,6 @@ class SettingsMenu(BaseMenu): f"New {display_name} repository branch:", f"● {branch}", ], - end="", ) if get_confirm("Apply changes?", allow_go_back=True): diff --git a/kiauh/core/settings/kiauh_settings.py b/kiauh/core/settings/kiauh_settings.py index 7aff799..a813c0f 100644 --- a/kiauh/core/settings/kiauh_settings.py +++ b/kiauh/core/settings/kiauh_settings.py @@ -219,6 +219,5 @@ class KiauhSettings: "● default.kiauh.cfg", "● kiauh.cfg", ], - end="", ) kill() diff --git a/kiauh/extensions/obico/moonraker_obico_extension.py b/kiauh/extensions/obico/moonraker_obico_extension.py index bd70d79..2b18cf1 100644 --- a/kiauh/extensions/obico/moonraker_obico_extension.py +++ b/kiauh/extensions/obico/moonraker_obico_extension.py @@ -192,7 +192,6 @@ class ObicoExtension(BaseExtension): "http://server_ip:port", "For instance, 'http://192.168.0.5:3334'.", ], - end="", ) def _print_moonraker_instances(self, mr_instances) -> None: @@ -206,7 +205,6 @@ class ObicoExtension(BaseExtension): "\n\n", "The setup will apply the same names to Obico!", ], - end="", ) def _print_is_already_installed(self) -> None: @@ -221,7 +219,6 @@ class ObicoExtension(BaseExtension): "L) Link printer to the Obico server", "R) Repair installation", ], - end="", ) def _get_server_url(self) -> None: @@ -324,7 +321,6 @@ class ObicoExtension(BaseExtension): "If you don't want to link the printer now, you can restart the " "linking process later by running this installer again.", ], - end="", ) if not get_confirm("Do you want to link the printers now?"): Logger.print_info("Linking to Obico server skipped ...") diff --git a/kiauh/utils/common.py b/kiauh/utils/common.py index 28b0a6f..98d982b 100644 --- a/kiauh/utils/common.py +++ b/kiauh/utils/common.py @@ -150,7 +150,6 @@ def moonraker_exists(name: str = "") -> bool: "No Moonraker instances found!", f"{info}. Please install Moonraker first!", ], - end="", ) return False return True diff --git a/kiauh/utils/logger.py b/kiauh/utils/logger.py index ef25ee5..b4d7ae0 100644 --- a/kiauh/utils/logger.py +++ b/kiauh/utils/logger.py @@ -90,7 +90,8 @@ class Logger: center_content: bool = False, custom_title: str = None, custom_color: DialogCustomColor = None, - end: str = "\n", + padding_top: int = 1, + padding_bottom: int = 1, ) -> None: dialog_color = Logger._get_dialog_color(title, custom_color) dialog_title = Logger._get_dialog_title(title, custom_title) @@ -99,10 +100,12 @@ class Logger: top = Logger._format_top_border(dialog_color) bottom = Logger._format_bottom_border() + print("\n" * padding_top) print( f"{top}{dialog_title_formatted}{dialog_content}{bottom}", - end=end, + end="", ) + print("\n" * padding_bottom) @staticmethod def _get_dialog_title(title: DialogType, custom_title: str = None) -> str: @@ -120,18 +123,12 @@ class Logger: @staticmethod def _format_top_border(color: str) -> str: - return textwrap.dedent( - f""" - {color}┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ - """ - )[1:-1] + return f"{color}┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓" @staticmethod def _format_bottom_border() -> str: - return textwrap.dedent( - f""" - ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ - {RESET_FORMAT}""" + return ( + f"\n┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛{RESET_FORMAT}" ) @staticmethod