Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added ability to quit early #126

Merged
merged 10 commits into from
Jun 27, 2024
12 changes: 10 additions & 2 deletions src/pick/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Picker(Generic[OPTION_T]):
screen: Optional["curses._CursesWindow"] = None
position: Position = Position(0, 0)
clear_screen: bool = True
keys_quit: Optional[Tuple[int]] = None
Henri-ColibrITD marked this conversation as resolved.
Show resolved Hide resolved

def __post_init__(self) -> None:
if len(self.options) == 0:
Expand Down Expand Up @@ -182,7 +183,12 @@ def run_loop(
while True:
self.draw(screen)
c = screen.getch()
if c in KEYS_UP:
if self.keys_quit is not None and c in self.keys_quit:
if self.multiselect:
return []
else:
return None, -1
elif c in KEYS_UP:
self.move_up()
elif c in KEYS_DOWN:
self.move_down()
Expand Down Expand Up @@ -231,7 +237,8 @@ def pick(
min_selection_count: int = 0,
screen: Optional["curses._CursesWindow"] = None,
position: Position = Position(0, 0),
clear_screen = True,
clear_screen: bool = True,
keys_quit: Optional[Tuple[int]] = None,
):
picker: Picker = Picker(
options,
Expand All @@ -243,5 +250,6 @@ def pick(
screen,
position,
clear_screen,
keys_quit,
)
return picker.start()