Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions invokeai/frontend/install/import_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,14 @@ def select_board_option(self, board_names, timestamp_string):
def select_item_from_list(self, items, entity_name, allow_cancel, cancel_string):
"""A general function to render a list of items to select in the console, prompt the user for a selection and ensure a valid entry is selected."""
print(f"Select a {entity_name.lower()} from the following list:")
index = 1
for item in items:
print(f"{index}) {item}")
index += 1
n_items = len(items)
if n_items:
# Use single print call for item list, which is significantly faster for large lists.
lines = [f"{i}) {item}" for i, item in enumerate(items, 1)]
print("\n".join(lines))
index = n_items + 1
else:
index = 1
if allow_cancel:
print(f"{index}) {cancel_string}")
while True:
Expand All @@ -553,7 +557,7 @@ def select_item_from_list(self, items, entity_name, allow_cancel, cancel_string)
continue
if allow_cancel and option_number == index:
return None
if option_number >= 1 and option_number <= len(items):
if 1 <= option_number <= n_items:
return items[option_number - 1]

def import_image(self, filepath: str, board_name_option: str, db_mapper: DatabaseMapper, config: Config):
Expand Down