Skip to content

Commit

Permalink
fix: quitting disabled by default and multiselect taken into account
Browse files Browse the repository at this point in the history
  • Loading branch information
Henri-ColibrITD committed Jun 11, 2024
1 parent ef6ccf9 commit 6c2742b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/pick/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ class Option:
description: Optional[str] = None


KEY_CTRL_C = 3
KEY_ESCAPE = 27
KEYS_QUIT = (KEY_CTRL_C, KEY_ESCAPE, ord("q"))
KEYS_ENTER = (curses.KEY_ENTER, ord("\n"), ord("\r"))
KEYS_UP = (curses.KEY_UP, ord("k"))
KEYS_DOWN = (curses.KEY_DOWN, ord("j"))
Expand All @@ -42,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

def __post_init__(self) -> None:
if len(self.options) == 0:
Expand Down Expand Up @@ -185,8 +183,11 @@ def run_loop(
while True:
self.draw(screen)
c = screen.getch()
if c in KEYS_QUIT:
return None, -1
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:
Expand Down Expand Up @@ -237,6 +238,7 @@ def pick(
screen: Optional["curses._CursesWindow"] = None,
position: Position = Position(0, 0),
clear_screen: bool = True,
keys_quit: Optional[tuple[int]] = None,
):
picker: Picker = Picker(
options,
Expand All @@ -248,5 +250,6 @@ def pick(
screen,
position,
clear_screen,
keys_quit,
)
return picker.start()

0 comments on commit 6c2742b

Please sign in to comment.