Skip to content

Commit

Permalink
Allow pick list with non str or Options types (#121)
Browse files Browse the repository at this point in the history
* Allow pick non list of str or Options

* ignore mypy

* fix typo in test
  • Loading branch information
aisk authored Apr 24, 2024
1 parent 72a4604 commit 213db25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/pick/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def draw(self, screen: "curses._CursesWindow") -> None:

description_present = False
for option in self.options:
if isinstance(option, str) or option.description is not None:
if not isinstance(option, Option) or option.description is not None:
description_present = True
break

Expand Down
10 changes: 9 additions & 1 deletion tests/test_pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ def test_get_lines():
def test_no_title():
options = ["option1", "option2", "option3"]
picker = Picker(options)
lines, current_line = picker.get_lines()
_, current_line = picker.get_lines()
assert current_line == 1


def test_pick_list_of_non_str_and_option():
# More details: https://github.com/aisk/pick/issues/120
options = [{"key1": "value1"}, {"key2": "value2"}]
picker = Picker(options) # type: ignore
lines, _ = picker.get_lines()
assert lines == ["* {'key1': 'value1'}", " {'key2': 'value2'}"]


def test_multi_select():
title = "Please choose an option: "
options = ["option1", "option2", "option3"]
Expand Down

0 comments on commit 213db25

Please sign in to comment.