Skip to content

Conversation

@patrick91
Copy link
Owner

@patrick91 patrick91 commented Nov 27, 2025

Summary

  • Fixes issue where menus break when the terminal screen is not tall enough to contain all options
  • Adds automatic scrolling for menus with more options than can fit on screen
  • Shows scroll indicators (↑ more / ↓ more) when there are more options above/below
  • Reserves consistent space for indicators to prevent UI shifting during navigation

Changes

  • menu.py: Added scroll state tracking (scroll_offset, max_visible), scroll helper methods, and scroll indicators
  • styles/base.py: Updated render_menu() to render only visible options with scroll indicators
  • styles/border.py: Updated render_menu() with same scrolling logic (was missing it entirely)
  • examples/scrolling-menu.py: New example demonstrating the scrolling feature

Test plan

  • Run uv run pytest tests/ - all tests pass
  • Run uv run python examples/scrolling-menu.py to test scrolling interactively
  • Test with both TaggedStyle and BorderedStyle
  • Test filtering with scrolling (country picker example)
  • Verify menu height stays constant during scrolling (no UI shifting)
CleanShot 2025-11-27 at 11 06 08@2x

🤖 Generated with Claude Code

When a menu has more options than can fit on the screen, it now
automatically scrolls as the user navigates. This prevents the UI
from breaking when the terminal is too small.

Changes:
- Add scroll state tracking to Menu class (scroll_offset, max_visible)
- Add scroll indicators ("↑ more" / "↓ more") to show when more options exist
- Reserve consistent space for indicators to prevent UI shifting
- Update both BaseStyle and BorderedStyle render_menu methods
- Reset scroll position when filter text changes
- Add scrolling-menu.py example demonstrating the feature

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@github-actions
Copy link

github-actions bot commented Nov 27, 2025

Thanks for adding the RELEASE.md file!

Below is the changelog that will be used for the release.


Add scrolling support for menus with many options.

When a menu has more options than can fit on the terminal screen, it now
automatically scrolls as the user navigates with arrow keys. This prevents
the UI from breaking when the terminal is too small to display all options.

Features:

  • Automatic scrolling based on terminal height
  • Scroll indicators (↑ more / ↓ more) show when more options exist
  • Works with both TaggedStyle and BorderedStyle
  • Works with filterable menus (scroll resets when filter changes)
  • Optional max_visible parameter for explicit control

Example usage:

from rich_toolkit import RichToolkit
from rich_toolkit.styles.tagged import TaggedStyle

# Auto-scrolling based on terminal height
with RichToolkit(style=TaggedStyle()) as app:
    result = app.ask(
        "Select a country:",
        options=[{"name": country, "value": country} for country in countries],
        allow_filtering=True,
    )

# Or with explicit max_visible limit
from rich_toolkit.menu import Menu

menu = Menu(
    label="Pick an option:",
    options=[{"name": f"Option {i}", "value": i} for i in range(50)],
    max_visible=10,  # Only show 10 options at a time
)
result = menu.ask()

This release was contributed by @patrick91 in #41

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@patrick91
Copy link
Owner Author

Code looks good! 😊

@patrick91 patrick91 merged commit ee14dd1 into main Nov 27, 2025
13 checks passed
@github-actions
Copy link

This PR was published as 0.17.0

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

Successfully merging this pull request may close these issues.

2 participants