Skip to content

Don't require pressing Return when selecting a gem#9646

Open
eval wants to merge 1 commit into
ruby:masterfrom
eval:single-keypress-select
Open

Don't require pressing Return when selecting a gem#9646
eval wants to merge 1 commit into
ruby:masterfrom
eval:single-keypress-select

Conversation

@eval

@eval eval commented Jun 24, 2026

Copy link
Copy Markdown

I opened this discussion a few weeks ago but it didn't get a response yet - so following up with a concrete implementation to make the proposal easier to evaluate. Happy to adjust the approach based on feedback.

What was the end-user or developer problem that led to this PR?

When using commands info, show, open with an ambiguous search-term (e.g. bundle show rspec), a menu with numbered candidates is shown. Selecting one always required confirming with Return, which adds friction to what is usually a single-digit choice.

What is your fix for the problem, implemented in this PR?

The menu now accepts a selection on a single keypress, so no extra Return is needed in the common case:

  • ≤ 9 options → any digit selects immediately, no Return.
  • ≥ 10 options → only digits that are a prefix of a larger number wait (e.g. 1 when 10/11 exist); everything else (2–9, 0) still fires instantly. Return resolves the prefix to what's typed so far (e.g.
    selecting 1 while 10 exists). Backspace edits the entry, digits that can't lead to any valid option are ignored.

Terminal control keys behave conventionally:

  • Ctrl-C aborts with the standard SIGINT exit status (130), without printing a backtrace. (It can't simply re-raise Interrupt, because with_friendly_errors re-raises SignalException to the interpreter (see Avoid bundle exec rescue of SignalException rubygems/bundler#6092) - which would dump a backtrace; so it exits explicitly with 128 + SIGINT.)
  • Ctrl-D / EOF cancels (no selection), exiting 0. This matches the previous line-based prompt, where EOF made nil.to_i return 0.

The single-keypress path is only used when both stdin and stdout are a TTY and io/console is available. Otherwise (piped input, non-interactive shells, CI) it falls back to the existing line-based prompt, so scripted usage and existing specs are unaffected.

The discussion raised whether this should be opt-in via configuration. I've kept it on by default, since the non-TTY fallback means scripts and CI are unaffected and the change to interactive use is minimal. I'm happy to gate it behind a config setting if maintainers prefer.

Make sure the following tasks are checked

When `bundle info`/`show`/`open` show a numbered menu for an ambiguous
gem name, accept the choice on a single keypress instead of requiring
Enter:

- With <10 options every digit (including 0/exit) selects immediately.
- With >=10 options a digit waits only while it's a prefix of a larger
  valid option (e.g. 1 when 10/11 exist); Enter then resolves the prefix
  to what's typed so far. Backspace edits; invalid digits are ignored.
@eval eval changed the title Don't require pressing <kbd>Enter</kbd> when selecting a gem Don't require pressing Return when selecting a gem Jun 24, 2026
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