bchao1 / bullet

🚅 Interactive prompts made simple. Build a prompt like stacking blocks.
https://pypi.org/project/bullet/
MIT License
3.55k stars 113 forks source link

ScrollBar fails with "IndexError: list index out of range" when choices contains a single element. #62

Closed idoob closed 4 years ago

idoob commented 4 years ago

I ran into this issue when I was dynamically generating my list of choices. I found that when there was only one choice in the choices list I got the error below. I found that the issue only occured with ScrollBar and so as a workaround I just use Bullet when there is only one choice.

Relevant Snippet

user_response = ScrollBar(
            "make a choice",
            ['single choice'],
            height=5,
            align=5,
            margin=3,
            pointer="⦿",
            background_on_switch=colors.background["black"]
        ).launch()

Cleansed Traceback:

...
  File "my_module.py", line 164, in select_anchor_point_prompt
    background_on_switch=colors.background["black"]
  File "...python3.7/site-packages/bullet/client.py", line 684, in launch
    self.renderRows()
  File "=.../python3.7/site-packages/bullet/client.py", line 609, in renderRows
    self.printRow(i + 1, indicator= self.down_indicator if self.top + self.height != len(self.choices) else '')
  File ".../python3.7/site-packages/bullet/client.py", line 621, in printRow
    utils.cprint(self.choices[idx], word_color, back_color, end = '')
IndexError: list index out of range
rcfox commented 4 years ago

That should have been fixed already: https://github.com/Mckinsey666/bullet/commit/d4b7d1328d3bf7ded498b64889936e073cbaf5a4

It's possible it wasn't pushed out to pip though. Maybe try checking out the repo?

idoob commented 4 years ago

That should have been fixed already: d4b7d13

It's possible it wasn't pushed out to pip though. Maybe try checking out the repo?

Yeap, the latest version on pypi does not include the fix. Thanks.

rcfox commented 4 years ago

Unfortunately, the maintainer seems to have gone AWOL, so I don't know when it will be updated on pypi...

bchao1 commented 4 years ago

Sorry for keeping you all hanging :( I've been quite busy the past year. The newest version of bullet is now on pypi.