petereon / beaupy

A Python library of interactive CLI elements you have been looking for
https://petereon.github.io/beaupy/
MIT License
200 stars 13 forks source link

pagination=False for select_multiple is not working #62

Closed anentropic closed 1 year ago

anentropic commented 1 year ago

Currently if len(options) > page_size then the select list doesn't work properly - all items are shown but checks are misattributed to different options and some options are not selectable

pagination=False is the default, my code was like:

        indices = select_multiple(
            options=options,
            ticked_indices=ticked_indices,
            cursor_index=ticked_indices[0],
            minimal_count=1,
            return_indices=True,
        )

(default page size is 5, I had 8 options)

I was able to work around it by setting page_size=len(options),

petereon commented 1 year ago

Hi @anentropic, thanks for reporting the issue. I will investigate!

petereon commented 1 year ago

I have tested this with the following example under version 3.5.3:

from beaupy import select_multiple

options = ["a", "b", "c", "d", "e", "f", "g", "h"]

ticked_indices = [2, 3, 4, 5]

indices = select_multiple(
            options=options,
            ticked_indices=ticked_indices,
            cursor_index=ticked_indices[0],
            minimal_count=1,
            return_indices=True,
        )

print(indices)

I've found a bug which manifests after pressing END key, I am going to track that one down and hope it fixes your issue.

Before pressing END: example1

Immediatelly after pressing END: example2

anentropic commented 1 year ago

I don't think I've pressed the END key

Try with just ticked_indices = [5]

What I would see is the first option was ticked (I guess because index 5 would be first item of second page if paginated)

And then pressing space bar on items 6, 7 or 8 (index 5, 6, 7) would tick options 1, 2 or 3 (presumably index 0, 1, 2 of second page) and the other items not selectable

petereon commented 1 year ago

Right, this manifests for me also. Investigating in select_multiple I am fairly convinced it is the symptom of the same bug. Nonetheless, I think I have found it, I've retried with your configuration and it now seems to work. I'll spend a bit of time adding some tests and then I should release 3.5.4 with a patch later today or tomorrow.

Thanks for cooperation on this!

petereon commented 1 year ago

Released as 3.5.4 also available on PyPI

I am closing! If you run across any more annoyances feel free to reopen or start another issue!

anentropic commented 1 year ago

Thanks, working for me now 👍