Skip to content

Commit

Permalink
ignore Seperator when calculating length of choices in select
Browse files Browse the repository at this point in the history
  • Loading branch information
weiduhuo committed Nov 12, 2023
1 parent 2df2655 commit ee159aa
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions questionary/prompts/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,18 @@ def select(
if choices is None or len(choices) == 0:
raise ValueError("A list of choices needs to be provided.")

if use_shortcuts and len(choices) > len(InquirerControl.SHORTCUT_KEYS):
raise ValueError(
"A list with shortcuts supports a maximum of {} "
"choices as this is the maximum number "
"of keyboard shortcuts that are available. You"
"provided {} choices!"
"".format(len(InquirerControl.SHORTCUT_KEYS), len(choices))
if use_shortcuts:
real_len_of_choices = sum(
1 for c in choices if not isinstance(c, Separator)
)
if real_len_of_choices > len(InquirerControl.SHORTCUT_KEYS):
raise ValueError(
"A list with shortcuts supports a maximum of {} "
"choices as this is the maximum number "
"of keyboard shortcuts that are available. You "
"provided {} choices!"
"".format(len(InquirerControl.SHORTCUT_KEYS), real_len_of_choices)
)

merged_style = merge_styles_default([style])

Expand Down

0 comments on commit ee159aa

Please sign in to comment.