InteractiveItemSelector: Allow quitting with 'q'
This commit is contained in:
+3
-1
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user