InteractiveItemSelector: Allow quitting with 'q'

This commit is contained in:
2026-05-30 22:49:36 +02:00
parent e968812858
commit 2406de41ce
+3 -1
View File
@@ -34,7 +34,6 @@ def format_date(date: datetime) -> str:
InteractiveItemSelectorType = TypeVar("InteractiveItemSelectorType") InteractiveItemSelectorType = TypeVar("InteractiveItemSelectorType")
# TODO: We need a way to exit the selector without selecting an item, maybe by entering 'q' or something.
class InteractiveItemSelector(Generic[InteractiveItemSelectorType], Cmd): class InteractiveItemSelector(Generic[InteractiveItemSelectorType], Cmd):
sql_session: Session sql_session: Session
execute_selection: Callable[[Session, type, str], list[Any]] execute_selection: Callable[[Session, type, str], list[Any]]
@@ -92,6 +91,9 @@ class InteractiveItemSelector(Generic[InteractiveItemSelectorType], Cmd):
print(f"Error executing selection: {e}") print(f"Error executing selection: {e}")
if len(result) != 1: if len(result) != 1:
if arg == "q":
self.result = None
return True
print(f"No such {self.cls.__name__} found: {arg}") print(f"No such {self.cls.__name__} found: {arg}")
return return