Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow menu pages to loop on themselves #14

Open
Drapersniper opened this issue Aug 10, 2020 · 1 comment
Open

Allow menu pages to loop on themselves #14

Drapersniper opened this issue Aug 10, 2020 · 1 comment

Comments

@Drapersniper
Copy link

Current implementation of MenuPages.show_checked_page() is the following:

    async def show_checked_page(self, page_number):
        max_pages = self._source.get_max_pages()
        try:
            if max_pages is None:
                # If it doesn't give maximum pages, it cannot be checked
                await self.show_page(page_number)
            elif max_pages > page_number >= 0:
                await self.show_page(page_number)
        except IndexError:
            # An error happened that can be handled, so ignore it.
            pass

Before making a PR I wanted to check if the following implementation is something you would like to see implemented Danny.

    async def show_checked_page(self, page_number: int) -> None:
        max_pages = self._source.get_max_pages()
        try:
            if max_pages is None:
                # If it doesn't give maximum pages, it cannot be checked
                await self.show_page(page_number)
            elif page_number >= max_pages:
                await self.show_page(0)
            elif page_number < 0:
                await self.show_page(max_pages - 1)
            elif max_pages > page_number >= 0:
                await self.show_page(page_number)
        except IndexError:
            # An error happened that can be handled, so ignore it.
            pass

This implementation would allow the menu to go to the last page when pressing back on Page 0, and go to first page when pressing Next on Page -1

@Rapptz
Copy link
Owner

Rapptz commented Aug 11, 2020

This is by design at the moment since I support asynchronous iterators which can generally only go forward until they can't anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants