Skip to content

ui: truncate long text to terminal width in Select/Prompt templates - #249

Open
mmustafasenoglu wants to merge 1 commit into
smallstep:mainfrom
mmustafasenoglu:fix/text-overflow-trunc
Open

ui: truncate long text to terminal width in Select/Prompt templates#249
mmustafasenoglu wants to merge 1 commit into
smallstep:mainfrom
mmustafasenoglu:fix/text-overflow-trunc

Conversation

@mmustafasenoglu

Copy link
Copy Markdown

Closes smallstep/cli#466

When the terminal is narrower than the rendered text, screenbuf still counts each Write as one line. The wrapped content isn't cleared on the next redraw, so stale characters remain visible.

This adds a truncFunc template helper that measures the terminal width and clips the string so the full rendered line (prefix icons + content) stays within bounds. It's registered in promptui.FuncMap and applied to the default Select and NamedSelect templates (Label, Active, Inactive) with a prefixLen of 4 to account for the page arrow, spacing, and icon characters.

screenbuf assumes each Write() is exactly one terminal line, but when
text is wider than the terminal it wraps, causing stale content to
remain on screen (issue #466).

Add a truncFunc template helper that measures the terminal width via
golang.org/x/term and truncates the string so the rendered line stays
within bounds. The function is registered in promptui.FuncMap and
applied to the default Select and NamedSelect templates (Label,
Active, Inactive) with a prefixLen of 4 to account for the page
arrow, spacing, and icon characters.
Copilot AI lite review requested due to automatic review settings September 5, 2026 12:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@CLAassistant

CLAassistant commented Sep 5, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text overflow spawns a new line instead of linebreaking

4 participants