Skip to content

refactor(vt_select): split interactive and non-interactive modes into typed APIs - #1020

Merged
wan9chi merged 2 commits into
mainfrom
refactor/vt-select-typed-modes
Nov 26, 2026
Merged

wan9chi merged 2 commits into
mainfrom
refactor/vt-select-typed-modes

Conversation

@wan9chi

@wan9chi wan9chi commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Motivation

vt_select previously merged interactive terminal selection and non-interactive list printing behind a single select_list API and a flat RenderParams struct, allowing invalid combinations and requiring callers to track mode state out of band:

  • Mode::Interactive { selected_index: &'a mut usize } | Mode::NonInteractive relied on an out-parameter, ignored prompt, page_size, and after_render in NonInteractive, and returned SelectResult::Selected even when NonInteractive printed a list without selecting anything.
  • The caller in crates/vt/src/session/mod.rs had to maintain a shadow Option<usize> to reconstruct whether selection ran interactively.
  • Internal RenderParams coupled interactive-only fields (selected, prompt, query, visible_row_range, hidden_count, max_line_width with usize::MAX sentinel) with non-interactive rendering via query.is_some(), allowing invalid query: None + selected: Some(_) combinations.

Changes

  • Split select_list into select_interactive(&SelectParams, after_render) -> Result<SelectOutcome> (Selected(usize) | Cancelled) and print_list(writer, &PrintListParams) -> Result<()>, moving interactive-only fields (prompt, page_size, after_render) exclusively to select_interactive and eliminating the &mut usize out-parameter.
  • Simplify crates/vt/src/session/mod.rs to call select_interactive or print_list directly without shadow Option<usize> tracking.
  • Replace the flat RenderParams struct with separate render_interactive_items (taking InteractiveRender) and render_non_interactive_items helpers, removing the usize::MAX sentinel, dead non-interactive selection branch, and direct slice range indexing.
  • Update vt_select unit tests, including filtered print_list coverage.

Note

Medium Risk
Touches the vp run task-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 / SelectResult API with select_interactive (returns SelectOutcome::Selected(usize) or Cancelled) and print_list (PrintListParams) so callers no longer pass mode flags, ignore writer/prompt, or use an out-parameter for the chosen index.

Session::handle_no_task now branches directly: non-interactive paths call print_list and exit with success/failure for bare vs typo vp run; interactive paths use select_interactive and match on SelectOutcome instead of maintaining a shadow Option<usize>.

Rendering is split into render_interactive_items (prompt, groups, truncation, raw TTY) and render_non_interactive_items (flat name: desc lines, header-only when nothing matches), dropping the shared RenderParams paths 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.

… 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>
@wan9chi
wan9chi added this pull request to stack #1022 November 26, 2026 01:47
@wan9chi wan9chi changed the title refactor/vt select typed modes refactor(vt_select): split interactive and non-interactive modes into typed APIs Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

fspy benchmark

linux

dynamic/launch             change  -0.86%  [ -8.38% ..  +5.88%]  overhead   +60.76%
dynamic/access             change  +1.07%  [ -8.73% .. +10.67%]  overhead   +18.76%
dynamic/access-relative    change  +0.72%  [ -9.61% .. +16.59%]  overhead   +61.25%
dynamic/access-contended   change  -0.13%  [ -9.31% ..  +8.14%]  overhead   +15.18%
static/launch              change  -0.17%  [ -3.03% ..  +2.77%]  overhead  +198.87%
static/access              change  +0.03%  [ -3.86% .. +11.31%]  overhead +1474.22%
static/access-relative     change  +0.35%  [ -3.03% .. +18.00%]  overhead +1966.17%
static/access-contended    change  +0.25%  [ -1.53% ..  +1.35%]  overhead +1968.45%

macos

dynamic/launch             change  +0.02%  [ -3.60% ..  +2.52%]  overhead  +231.00%
dynamic/access             change  +0.37%  [ -2.74% ..  +4.69%]  overhead    +6.10%
dynamic/access-relative    change  +0.74%  [ -3.80% ..  +6.24%]  overhead  +255.43%
dynamic/access-contended   change  -0.46%  [ -2.60% ..  +1.76%]  overhead    +3.92%

windows

dynamic/launch             change  +0.66%  [ -3.70% ..  +5.34%]  overhead   +26.56%
dynamic/access             change  +0.00%  [ -1.43% ..  +1.31%]  overhead    +1.50%
dynamic/access-relative    change  +0.18%  [ -1.27% ..  +0.91%]  overhead    +1.47%
dynamic/access-contended   change  +0.00%  [ -1.30% ..  +1.94%]  overhead    +1.97%

- 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>
@wan9chi
wan9chi merged commit 5506727 into main Nov 26, 2026
23 checks passed
@wan9chi
wan9chi deleted the refactor/vt-select-typed-modes branch November 26, 2026 02:46
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.

1 participant