fix(cli): fix Prompt.select clear when descriptions wrap by kingstarfly · Pull Request #5979 · Effect-TS/effect

Summary

Fixes #5978

When using Prompt.select with choices that have long descriptions, navigating between options causes duplicate prompt lines to appear instead of updating in place. This happens because handleClear doesn't account for terminal line wrapping.

Changes

  • Modified handleClear in select.ts to calculate actual rendered line lengths
  • Pass state to handleClear to determine which choice has its description displayed
  • Calculate wrapped lines using actual content (prefix + title + description) instead of empty newlines

Root Cause

The previous implementation used:

const text = "\n".repeat(Math.min(options.choices.length, options.maxPerPage)) + options.message

This assumes each choice takes exactly 1 terminal row. However:

  1. Choices render as prefix (2 chars) + title + description
  2. Descriptions are only shown for the selected item
  3. When content length > terminal width, the line wraps to multiple rows

The fix calculates actual content length per choice to properly determine rows to erase.

Testing

Tested locally with long descriptions in a narrow terminal - navigation now updates cleanly without leaving artifacts.