mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 00:33:37 +05:00
refactor: use 1-based indexing for klipper instance selection
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -32,6 +32,7 @@ def print_instance_overview(
|
||||
display_type: DisplayType = DisplayType.SERVICE_NAME,
|
||||
show_headline=True,
|
||||
show_index=False,
|
||||
start_index=0,
|
||||
show_select_all=False,
|
||||
):
|
||||
dialog = "╔═══════════════════════════════════════════════════════╗\n"
|
||||
@@ -55,7 +56,7 @@ def print_instance_overview(
|
||||
name = s.get_service_file_name()
|
||||
else:
|
||||
name = s.data_dir
|
||||
line = f"{COLOR_CYAN}{f'{i})' if show_index else '●'} {name}{RESET_FORMAT}"
|
||||
line = f"{COLOR_CYAN}{f'{i + start_index})' if show_index else '●'} {name}{RESET_FORMAT}"
|
||||
dialog += f"║ {line:<63}║\n"
|
||||
dialog += "╟───────────────────────────────────────────────────────╢\n"
|
||||
|
||||
|
||||
@@ -50,11 +50,17 @@ def run_klipper_removal(
|
||||
def select_instances_to_remove(
|
||||
instances: List[Klipper],
|
||||
) -> Union[List[Klipper], None]:
|
||||
print_instance_overview(instances, show_index=True, show_select_all=True)
|
||||
|
||||
options = [str(i) for i in range(len(instances))]
|
||||
start_index = 1
|
||||
options = [str(i + start_index) for i in range(len(instances))]
|
||||
options.extend(["a", "A", "b", "B"])
|
||||
instance_map = {options[i]: instances[i] for i in range(len(instances))}
|
||||
|
||||
print_instance_overview(
|
||||
instances,
|
||||
start_index=start_index,
|
||||
show_index=True,
|
||||
show_select_all=True,
|
||||
)
|
||||
selection = get_selection_input("Select Klipper instance to remove", options)
|
||||
|
||||
instances_to_remove = []
|
||||
@@ -63,8 +69,7 @@ def select_instances_to_remove(
|
||||
elif selection == "a".lower():
|
||||
instances_to_remove.extend(instances)
|
||||
else:
|
||||
instance = instances[int(selection)]
|
||||
instances_to_remove.append(instance)
|
||||
instances_to_remove.append(instance_map[selection])
|
||||
|
||||
return instances_to_remove
|
||||
|
||||
|
||||
Reference in New Issue
Block a user