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