-
Notifications
You must be signed in to change notification settings - Fork 65
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
Add excluded indexes. #105
Changes from all commits
1c0fd90
50bdd41
3fd6549
8378d1f
1a44cdc
a4ea078
b8ccb5e
416da13
ae2b998
a7ebf68
9294daa
f9ac0aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To implement @wong2 's suggestion, you can add an extra attribute to the class
Then, if you implement my suggestions, everything should work as intended |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -32,6 +32,7 @@ class Picker(Generic[OPTION_T]): | |||||||||||||||||||
multiselect: bool = False | ||||||||||||||||||||
min_selection_count: int = 0 | ||||||||||||||||||||
selected_indexes: List[int] = field(init=False, default_factory=list) | ||||||||||||||||||||
excluded_indexes: List[int] = field(default_factory=list) | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
index: int = field(init=False, default=0) | ||||||||||||||||||||
screen: Optional["curses._CursesWindow"] = None | ||||||||||||||||||||
|
||||||||||||||||||||
|
@@ -48,14 +49,23 @@ def __post_init__(self) -> None: | |||||||||||||||||||
) | ||||||||||||||||||||
|
||||||||||||||||||||
self.index = self.default_index | ||||||||||||||||||||
while self.index in self.excluded_indexes: | ||||||||||||||||||||
self.index += 1 | ||||||||||||||||||||
Comment on lines
+52
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
def move_up(self) -> None: | ||||||||||||||||||||
self.index -= 1 | ||||||||||||||||||||
|
||||||||||||||||||||
while self.index in self.excluded_indexes: | ||||||||||||||||||||
self.index -= 1 | ||||||||||||||||||||
if self.index < 0: | ||||||||||||||||||||
self.index = len(self.options) - 1 | ||||||||||||||||||||
Comment on lines
+58
to
62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
def move_down(self) -> None: | ||||||||||||||||||||
self.index += 1 | ||||||||||||||||||||
|
||||||||||||||||||||
while self.index in self.excluded_indexes: | ||||||||||||||||||||
self.index += 1 | ||||||||||||||||||||
if self.index >= len(self.options): | ||||||||||||||||||||
self.index = 0 | ||||||||||||||||||||
Comment on lines
+66
to
70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
|
@@ -126,7 +136,7 @@ def draw(self, screen: "curses._CursesWindow") -> None: | |||||||||||||||||||
if current_line > max_rows: | ||||||||||||||||||||
scroll_top = current_line - max_rows | ||||||||||||||||||||
|
||||||||||||||||||||
lines_to_draw = lines[scroll_top : scroll_top + max_rows] | ||||||||||||||||||||
lines_to_draw = lines[scroll_top: scroll_top + max_rows] | ||||||||||||||||||||
|
||||||||||||||||||||
for line in lines_to_draw: | ||||||||||||||||||||
screen.addnstr(y, x, line, max_x - 2) | ||||||||||||||||||||
|
@@ -187,15 +197,20 @@ def pick( | |||||||||||||||||||
default_index: int = 0, | ||||||||||||||||||||
multiselect: bool = False, | ||||||||||||||||||||
min_selection_count: int = 0, | ||||||||||||||||||||
excluded_indexes = None, | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
screen: Optional["curses._CursesWindow"] = None, | ||||||||||||||||||||
): | ||||||||||||||||||||
if excluded_indexes is None: | ||||||||||||||||||||
excluded_indexes = [] | ||||||||||||||||||||
|
||||||||||||||||||||
Comment on lines
+203
to
+205
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
picker: Picker = Picker( | ||||||||||||||||||||
options, | ||||||||||||||||||||
title, | ||||||||||||||||||||
indicator, | ||||||||||||||||||||
default_index, | ||||||||||||||||||||
multiselect, | ||||||||||||||||||||
min_selection_count, | ||||||||||||||||||||
excluded_indexes, | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
screen, | ||||||||||||||||||||
) | ||||||||||||||||||||
return picker.start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.