Skip to content

fix(prompts): keep autocomplete prompts within the terminal height - #634

Open
chenxin-yan wants to merge 1 commit into
bombshell-dev:mainfrom
chenxin-yan:fix/autocomplete-multiselect-overflow
Open

chenxin-yan wants to merge 1 commit into
bombshell-dev:mainfrom
chenxin-yan:fix/autocomplete-multiselect-overflow

Conversation

@chenxin-yan

Copy link
Copy Markdown

What does this PR do?

autocomplete and autocompleteMultiselect size their option list from rows - rowPadding, but rowPadding counted the header and footer lines before they wrap. In a narrow terminal the message or the instructions line wraps, the frame grows taller than the terminal, and each redraw leaves stale rows above the prompt.

This applies the approach select and multiselect already use:

  • Wrap the message with wrapTextWithPrefix, so continuation lines get the guide bar and are counted.
  • Wrap the Search: line and the instructions line with wrapTextWithPrefix before counting them.
  • Pass columnPadding to limitOptions in autocompleteMultiselect, as autocomplete already does, so options are measured against the width left after │ .

The instructions line keeps its state-coloured bar (barStyle). That's why it calls wrapTextWithPrefix directly instead of formatInstructionFooter, which always uses cyan.

Output at normal widths is unchanged; no existing snapshots changed.

Closes #633

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset

Testing

  • New test in packages/prompts/test/autocomplete.test.ts: both prompts, 40x20 output, a message that wraps, 30 long options. It asserts the first frame is no taller than output.rows. Without the fix it fails (21 rows for autocomplete, 27 for autocompleteMultiselect); with it, it passes.
  • pnpm test: core 173 passed; prompts 630 passed, 4 skipped.
  • pnpm types and biome check pass.
  • Replayed both prompts on a virtual terminal (scrolls past the bottom row, clamps cursor-up at the top row) at 100x30, 80x24, 60x24, 60x20, and 60x16 with a 70-item locale list, typing and deleting a query. No rows scroll off at any size; on 1.9.0 autocompleteMultiselect overflows at all three 60-column sizes.

Notes

  • With withGuide: false, wrapTextWithPrefix measures the empty continuation prefix rather than the ◆ start prefix, so a message's first line can still be 3 columns too wide. This copies multiselect's message wrapping, which behaves the same way; I left it out of scope.
  • Validation error lines aren't wrapped before counting, same as in the other prompts.

AI-generated code disclosure

  • This PR includes AI-generated code

Count wrapped message, search, and instruction lines when sizing the option list, and pass columnPadding for the guide prefix in autocompleteMultiselect.
@changeset-bot

changeset-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0631532

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clack/prompts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

});
});

describe('autocomplete prompts in a narrow terminal', () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't belong in its own describe block

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.

[Bug] autocompleteMultiselect grows taller than a narrow terminal and leaves stale rows on redraw

2 participants