Repository navigation
refactor(vt_select): split interactive and non-interactive modes into typed APIs - #1020
Merged
Merged
Conversation
… typed APIs - Replace `select_list`, `Mode`, and `SelectResult` with `select_interactive` (returning `SelectOutcome::Selected(usize) | Cancelled`) and `print_list` (taking `PrintListParams`), eliminating the `&mut usize` out-parameter, ignored interactive-only parameters in non-interactive mode, and the shadow `Option<usize>` in `Session::handle_no_task`. - Replace `RenderParams`'s coupled optional/sentinel fields (`selected`, `prompt`, `query`, `visible_row_range`, `hidden_count`, `show_group_headers`, `line_ending`, `max_line_width: usize::MAX`) with `RenderMode::Interactive` and `RenderMode::NonInteractive`, removing the dead non-interactive selected branch and updating unit tests accordingly. Co-authored-by: Gemini 4 Neon <noreply@google.com>
fspy benchmarklinuxmacoswindows |
- Call `render_non_interactive_items` and `render_interactive_items` directly instead of routing through `RenderMode` / `RenderParams`, so `print_list` no longer discards a line count. - Use `display_rows.get(range).unwrap_or_default()` instead of direct range indexing in `render_interactive_items`. - Place the empty-match comment on the item loop and add a filtered `print_list` unit test. Co-authored-by: gemini-4-neon <noreply@google.com>
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.
Motivation
vt_selectpreviously merged interactive terminal selection and non-interactive list printing behind a singleselect_listAPI and a flatRenderParamsstruct, allowing invalid combinations and requiring callers to track mode state out of band:Mode::Interactive { selected_index: &'a mut usize } | Mode::NonInteractiverelied on an out-parameter, ignoredprompt,page_size, andafter_renderinNonInteractive, and returnedSelectResult::Selectedeven whenNonInteractiveprinted a list without selecting anything.crates/vt/src/session/mod.rshad to maintain a shadowOption<usize>to reconstruct whether selection ran interactively.RenderParamscoupled interactive-only fields (selected,prompt,query,visible_row_range,hidden_count,max_line_widthwithusize::MAXsentinel) with non-interactive rendering viaquery.is_some(), allowing invalidquery: None+selected: Some(_)combinations.Changes
select_listintoselect_interactive(&SelectParams, after_render) -> Result<SelectOutcome>(Selected(usize) | Cancelled) andprint_list(writer, &PrintListParams) -> Result<()>, moving interactive-only fields (prompt,page_size,after_render) exclusively toselect_interactiveand eliminating the&mut usizeout-parameter.crates/vt/src/session/mod.rsto callselect_interactiveorprint_listdirectly without shadowOption<usize>tracking.RenderParamsstruct with separaterender_interactive_items(takingInteractiveRender) andrender_non_interactive_itemshelpers, removing theusize::MAXsentinel, dead non-interactive selection branch, and direct slice range indexing.vt_selectunit tests, including filteredprint_listcoverage.Note
Medium Risk
Touches the
vp runtask-picker UX and terminal I/O paths; behavior is intended to stay the same but deserves interactive and non-interactive regression checks.Overview
Replaces the combined
select_list/Mode/SelectResultAPI withselect_interactive(returnsSelectOutcome::Selected(usize)orCancelled) andprint_list(PrintListParams) so callers no longer pass mode flags, ignorewriter/prompt, or use an out-parameter for the chosen index.Session::handle_no_tasknow branches directly: non-interactive paths callprint_listand exit with success/failure for bare vs typovp run; interactive paths useselect_interactiveand match onSelectOutcomeinstead of maintaining a shadowOption<usize>.Rendering is split into
render_interactive_items(prompt, groups, truncation, raw TTY) andrender_non_interactive_items(flatname: desclines, header-only when nothing matches), dropping the sharedRenderParamspaths that inferred mode from optional fields.Reviewed by Cursor Bugbot for commit 4238c68. Bugbot is set up for automated code reviews on this repo. Configure here.