From 1c0fd906a1824cc4feecb9b4d145166294110045 Mon Sep 17 00:00:00 2001 From: J3ldo <97303347+J3ldo@users.noreply.github.com> Date: Mon, 15 May 2023 00:04:48 +0200 Subject: [PATCH 01/12] Add excluded limiteds arguments, and support --- src/pick/__init__.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/pick/__init__.py b/src/pick/__init__.py index c54ce83..b2266a0 100644 --- a/src/pick/__init__.py +++ b/src/pick/__init__.py @@ -31,7 +31,8 @@ class Picker(Generic[OPTION_T]): default_index: int = 0 multiselect: bool = False min_selection_count: int = 0 - selected_indexes: List[int] = field(init=False, default_factory=list) + selected_indexes: List[int] = field(init=False, default_factory=list), + excluded_indexes: List[int] = list(), index: int = field(init=False, default=0) screen: Optional["curses._CursesWindow"] = None @@ -53,11 +54,22 @@ def move_up(self) -> None: self.index -= 1 if self.index < 0: self.index = len(self.options) - 1 + + while 1: + if self.index not in excludes_indexes: + break + self.indexes -= 1 def move_down(self) -> None: self.index += 1 if self.index >= len(self.options): self.index = 0 + + while 1: + if self.index not in self.excludes_indexes: + break + self.indexes += 1 + def mark_index(self) -> None: if self.multiselect: @@ -187,6 +199,7 @@ def pick( default_index: int = 0, multiselect: bool = False, min_selection_count: int = 0, + excluded_indexes: [], screen: Optional["curses._CursesWindow"] = None, ): picker: Picker = Picker( @@ -196,6 +209,7 @@ def pick( default_index, multiselect, min_selection_count, + excluded_indexes, screen, ) return picker.start() From 50bdd413ac81b179ef386a88eaf94d7bf98597bb Mon Sep 17 00:00:00 2001 From: J3ldo <97303347+J3ldo@users.noreply.github.com> Date: Mon, 15 May 2023 00:07:14 +0200 Subject: [PATCH 02/12] Add documentation about excluded indexes --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2dd7d38..18555be 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ interactive selection list in the terminal. multiple items by hitting SPACE - `min_selection_count`: (optional) for multi select feature to dictate a minimum of selected items before continuing +- `excluded_indexes`: (optional) indexes excluded from the selector. Excluded indexes will make it that they wont be able to get selected and just skip over them - `screen`: (optional), if you are using `pick` within an existing curses application set this to your existing `screen` object. It is assumed this has initialised in the standard way (e.g. via `curses.wrapper()`, or `curses.noecho(); curses.cbreak(); screen.kepad(True)`) ## Community Projects From 3fd654989a146091c353fac5367264b166acf8af Mon Sep 17 00:00:00 2001 From: J3ldo <97303347+J3ldo@users.noreply.github.com> Date: Mon, 15 May 2023 00:10:47 +0200 Subject: [PATCH 03/12] Passed [] instead of list() as default object. --- src/pick/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pick/__init__.py b/src/pick/__init__.py index b2266a0..4f339d5 100644 --- a/src/pick/__init__.py +++ b/src/pick/__init__.py @@ -199,7 +199,7 @@ def pick( default_index: int = 0, multiselect: bool = False, min_selection_count: int = 0, - excluded_indexes: [], + excluded_indexes = list(), screen: Optional["curses._CursesWindow"] = None, ): picker: Picker = Picker( From 8378d1ff326397685819a6bcb65cc47bf7078aea Mon Sep 17 00:00:00 2001 From: J3ldo <97303347+J3ldo@users.noreply.github.com> Date: Mon, 15 May 2023 00:13:00 +0200 Subject: [PATCH 04/12] Fix small typo --- src/pick/__init__.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pick/__init__.py b/src/pick/__init__.py index 4f339d5..10149f5 100644 --- a/src/pick/__init__.py +++ b/src/pick/__init__.py @@ -54,9 +54,9 @@ def move_up(self) -> None: self.index -= 1 if self.index < 0: self.index = len(self.options) - 1 - + while 1: - if self.index not in excludes_indexes: + if self.index not in self.excluded_indexes: break self.indexes -= 1 @@ -64,13 +64,12 @@ def move_down(self) -> None: self.index += 1 if self.index >= len(self.options): self.index = 0 - + while 1: - if self.index not in self.excludes_indexes: + if self.index not in self.excluded_indexes: break self.indexes += 1 - def mark_index(self) -> None: if self.multiselect: if self.index in self.selected_indexes: @@ -138,7 +137,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) From 1a44cdcc63ec60aeccd618ec48f6f6de217c7111 Mon Sep 17 00:00:00 2001 From: J3ldo <97303347+J3ldo@users.noreply.github.com> Date: Mon, 15 May 2023 00:32:42 +0200 Subject: [PATCH 05/12] Fixed some small bugs Renamed self.indexes to self.index (typo) Removed init=False from excluded indexes --- src/pick/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pick/__init__.py b/src/pick/__init__.py index 10149f5..789eefe 100644 --- a/src/pick/__init__.py +++ b/src/pick/__init__.py @@ -31,8 +31,8 @@ class Picker(Generic[OPTION_T]): default_index: int = 0 multiselect: bool = False min_selection_count: int = 0 - selected_indexes: List[int] = field(init=False, default_factory=list), - excluded_indexes: List[int] = list(), + selected_indexes: List[int] = field(init=False, default_factory=list) + excluded_indexes: List[int] = field(default_factory=list) index: int = field(init=False, default=0) screen: Optional["curses._CursesWindow"] = None @@ -58,17 +58,19 @@ def move_up(self) -> None: while 1: if self.index not in self.excluded_indexes: break - self.indexes -= 1 + self.index -= 1 def move_down(self) -> None: self.index += 1 if self.index >= len(self.options): self.index = 0 + import logging + logging.info(self.excluded_indexes) while 1: if self.index not in self.excluded_indexes: break - self.indexes += 1 + self.index += 1 def mark_index(self) -> None: if self.multiselect: From a4ea078b03e59e8cd53e81ce970159d52da40b28 Mon Sep 17 00:00:00 2001 From: J3ldo <97303347+J3ldo@users.noreply.github.com> Date: Mon, 15 May 2023 00:35:01 +0200 Subject: [PATCH 06/12] Check for excluded indexes post init, and make code cleaner. --- src/pick/__init__.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/pick/__init__.py b/src/pick/__init__.py index 789eefe..781bfec 100644 --- a/src/pick/__init__.py +++ b/src/pick/__init__.py @@ -49,16 +49,16 @@ def __post_init__(self) -> None: ) self.index = self.default_index + while self.index not in self.excluded_indexes: + self.index += 1 def move_up(self) -> None: self.index -= 1 if self.index < 0: self.index = len(self.options) - 1 - while 1: - if self.index not in self.excluded_indexes: - break - self.index -= 1 + while self.index not in self.excluded_indexes: + self.index += 1 def move_down(self) -> None: self.index += 1 @@ -67,11 +67,9 @@ def move_down(self) -> None: import logging logging.info(self.excluded_indexes) - while 1: - if self.index not in self.excluded_indexes: - break - self.index += 1 - + while self.index not in self.excluded_indexes: + self.index -= 1 + def mark_index(self) -> None: if self.multiselect: if self.index in self.selected_indexes: From b8ccb5e14a18b71a3f644d1b0079e79a76f08f40 Mon Sep 17 00:00:00 2001 From: J3ldo <97303347+J3ldo@users.noreply.github.com> Date: Mon, 15 May 2023 00:36:31 +0200 Subject: [PATCH 07/12] Remove not from while self.index not in.... --- src/pick/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pick/__init__.py b/src/pick/__init__.py index 781bfec..fec8215 100644 --- a/src/pick/__init__.py +++ b/src/pick/__init__.py @@ -49,7 +49,7 @@ def __post_init__(self) -> None: ) self.index = self.default_index - while self.index not in self.excluded_indexes: + while self.index in self.excluded_indexes: self.index += 1 def move_up(self) -> None: @@ -57,7 +57,7 @@ def move_up(self) -> None: if self.index < 0: self.index = len(self.options) - 1 - while self.index not in self.excluded_indexes: + while self.index in self.excluded_indexes: self.index += 1 def move_down(self) -> None: @@ -67,9 +67,9 @@ def move_down(self) -> None: import logging logging.info(self.excluded_indexes) - while self.index not in self.excluded_indexes: + while self.index in self.excluded_indexes: self.index -= 1 - + def mark_index(self) -> None: if self.multiselect: if self.index in self.selected_indexes: From 416da13cf87c6f8c4188ead98766c1c3b7a35096 Mon Sep 17 00:00:00 2001 From: J3ldo <97303347+J3ldo@users.noreply.github.com> Date: Mon, 15 May 2023 00:41:52 +0200 Subject: [PATCH 08/12] Removed some logging --- src/pick/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pick/__init__.py b/src/pick/__init__.py index fec8215..bff3fec 100644 --- a/src/pick/__init__.py +++ b/src/pick/__init__.py @@ -65,8 +65,6 @@ def move_down(self) -> None: if self.index >= len(self.options): self.index = 0 - import logging - logging.info(self.excluded_indexes) while self.index in self.excluded_indexes: self.index -= 1 From ae2b99812782e0ff7839e375215539b73d3119ae Mon Sep 17 00:00:00 2001 From: J3ldo <97303347+J3ldo@users.noreply.github.com> Date: Thu, 18 May 2023 19:48:12 +0200 Subject: [PATCH 09/12] Make list value unmutable --- src/pick/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pick/__init__.py b/src/pick/__init__.py index bff3fec..7eead4f 100644 --- a/src/pick/__init__.py +++ b/src/pick/__init__.py @@ -196,7 +196,7 @@ def pick( default_index: int = 0, multiselect: bool = False, min_selection_count: int = 0, - excluded_indexes = list(), + excluded_indexes = list, screen: Optional["curses._CursesWindow"] = None, ): picker: Picker = Picker( From a7ebf68c11e54da6921fcca716f38be312c24ec7 Mon Sep 17 00:00:00 2001 From: J3ldo <97303347+J3ldo@users.noreply.github.com> Date: Thu, 18 May 2023 19:56:42 +0200 Subject: [PATCH 10/12] make excluded_indexes unmutable fix --- src/pick/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pick/__init__.py b/src/pick/__init__.py index 7eead4f..c106694 100644 --- a/src/pick/__init__.py +++ b/src/pick/__init__.py @@ -196,9 +196,12 @@ def pick( default_index: int = 0, multiselect: bool = False, min_selection_count: int = 0, - excluded_indexes = list, + excluded_indexes = None, screen: Optional["curses._CursesWindow"] = None, ): + if excluded_indexes is None: + excluded_indexes = [] + picker: Picker = Picker( options, title, From 9294daa83848f64f3ccdf04a0b55f897cda25c9e Mon Sep 17 00:00:00 2001 From: J3ldo <97303347+J3ldo@users.noreply.github.com> Date: Thu, 18 May 2023 21:01:53 +0200 Subject: [PATCH 11/12] Fix some things (To lazy to say them) --- src/pick/__init__.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/pick/__init__.py b/src/pick/__init__.py index c106694..14fc2e9 100644 --- a/src/pick/__init__.py +++ b/src/pick/__init__.py @@ -52,21 +52,23 @@ def __post_init__(self) -> None: while self.index in self.excluded_indexes: self.index += 1 + def move_up(self) -> None: self.index -= 1 - if self.index < 0: - self.index = len(self.options) - 1 while self.index in self.excluded_indexes: - self.index += 1 + self.index -= 1 + print("Here", self.index) + if self.index < 0: + self.index = len(self.options) - 1 def move_down(self) -> None: self.index += 1 - if self.index >= len(self.options): - self.index = 0 while self.index in self.excluded_indexes: - self.index -= 1 + self.index += 1 + if self.index >= len(self.options): + self.index = 0 def mark_index(self) -> None: if self.multiselect: From f9ac0aae50c9131b3c8fc088688b398f54f167c8 Mon Sep 17 00:00:00 2001 From: J3ldo <97303347+J3ldo@users.noreply.github.com> Date: Thu, 18 May 2023 21:02:24 +0200 Subject: [PATCH 12/12] Remove some logging --- src/pick/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pick/__init__.py b/src/pick/__init__.py index 14fc2e9..eb64d4a 100644 --- a/src/pick/__init__.py +++ b/src/pick/__init__.py @@ -58,7 +58,6 @@ def move_up(self) -> None: while self.index in self.excluded_indexes: self.index -= 1 - print("Here", self.index) if self.index < 0: self.index = len(self.options) - 1