✨ feat: add fzf-style interactive selection for lists and dictionaries - #524
Open
guptadev21 wants to merge 2 commits into
Open
✨ feat: add fzf-style interactive selection for lists and dictionaries#524guptadev21 wants to merge 2 commits into
guptadev21 wants to merge 2 commits into
Conversation
|
🤖 Pull Request Artifacts (#25719838141) 🎉 |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an interactive, fzf-style selector (fuzzy search + arrow navigation) to improve large list/dict selections (notably org/project selection during rio auth login), while keeping the existing numbered-list prompt as a non-TTY fallback.
Changes:
- Detects TTY and switches
show_selection()to an interactive prompt_toolkit-based picker. - Introduces prompt_toolkit UI rendering + keybindings for fuzzy filtering and selection.
- Preserves legacy numbered-list behavior for non-interactive environments.
Comment on lines
+75
to
+80
| chosen_label = _run_fuzzy_picker(labels, labels, header) | ||
| # Return the key whose value matches the chosen label | ||
| for k, v in ranger.items(): | ||
| if v == chosen_label: | ||
| return k | ||
| return keys[0] |
Comment on lines
+119
to
+126
| def _matches(query: str, text: str) -> bool: | ||
| """Simple case-insensitive substring / fuzzy match.""" | ||
| query = query.lower() | ||
| text = text.lower() | ||
| # Fuzzy: every character of query must appear in order in text | ||
| it = iter(text) | ||
| return all(c in it for c in query) | ||
|
|
Comment on lines
+159
to
+160
| _add(f"<ansibrightblack> > </ansibrightblack>{_escape(state['query'])}\n") | ||
| _add(f"<ansibrightblack> {'─' * 60}</ansibrightblack>\n") |
| style=style, | ||
| full_screen=False, | ||
| mouse_support=False, | ||
| refresh_interval=0.05, |
Comment on lines
+46
to
+52
| # Use interactive fuzzy selector when stdout is a real TTY | ||
| if sys.stdout.isatty() and sys.stdin.isatty(): | ||
| if isinstance(ranger, dict): | ||
| return _fuzzy_selection_dict(ranger, header) | ||
| if isinstance(ranger, list): | ||
| return _fuzzy_selection_list(ranger, header) | ||
|
|
…matching algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When running rio auth login, organizations and projects are displayed as a numbered list in the terminal. Users must scroll through the entire list and type a number to select an entry. With 50+ projects this becomes tedious and error-prone.
Solution
Replaced the numbered list with an fzf-style interactive picker when running in a real terminal (TTY). Users can now type to fuzzy-search and use arrow keys to navigate, then press Enter to confirm. The old numbered list behavior is preserved as a fallback for non-interactive use (pipes, scripts, CI).
Controls
No new dependencies — uses prompt_toolkit, which is already available as a transitive dependency of click.