Skip to content

Commit

Permalink
Ignore Seperator when calculating length of choices in select (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
weiduhuo authored Jan 11, 2024
1 parent bba92b4 commit ed4025c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions questionary/prompts/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,16 @@ 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 ed4025c

Please sign in to comment.