Skip to content

fix: account for escape sequences in prefixes - #631

Merged
43081j merged 1 commit into
mainfrom
jg/ansi-witchcraft
Oct 30, 2026
Merged

43081j merged 1 commit into
mainfrom
jg/ansi-witchcraft

Conversation

@43081j

@43081j 43081j commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

This is a known bug we've had for quite some time. Basically, we were
checking prefix.length to calculate how much space the prefix (e.g.
the guide) takes up.

This is incorrect since the prefix usually contains escape sequences, so
it can be off by several characters. Using fast-string-width instead
means we get the actual width.

Note that fast-string-width is already a deep dependency, so this just
declares it at the root.

As part of this, I also wrapped the footer of select-like prompts FYI.

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

AI-generated code disclosure

  • This PR includes AI-generated code

This is a known bug we've had for quite some time. Basically, we were
checking `prefix.length` to calculate how much space the prefix (e.g.
the guide) takes up.

This is incorrect since the prefix usually contains escape sequences, so
it can be off by several characters. Using fast-string-width instead
means we get the actual width.

Note that fast-string-width is already a deep dependency, so this just
declares it at the root.
@changeset-bot

changeset-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3cdb798

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

This PR includes changesets to release 2 packages
Name Type
@clack/prompts Patch
@clack/core 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

@pkg-pr-new

pkg-pr-new Bot commented Oct 29, 2026

Copy link
Copy Markdown

commit: 3cdb798

@43081j
43081j requested a review from dreyfus92 October 29, 2026 10:38

@dreyfus92 dreyfus92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hey james, awesome job. one thing i think it's lacking, could be a follow up, is checking limitOptions. the same overcount is still in columnPadding: prefix.length in select.ts, multi-select.ts and group-multi-select.ts. afaik also limitOptions subtracts it from the width, so options will wrap 10 columns early. switching those to stringWidth(prefix) should fix it.

@43081j

43081j commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator Author

let's do it in a follow up (or multiple) since there's probably a few places that can gain from a similar fix

@43081j
43081j merged commit 9053625 into main Oct 30, 2026
11 checks passed
@43081j
43081j deleted the jg/ansi-witchcraft branch October 30, 2026 09:40
@bombshell-bot bombshell-bot Bot mentioned this pull request Oct 30, 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.

2 participants