Skip to content

Fix double-spaced TTY output caused by ANSI-unaware trim_end#875

Merged
dalance merged 2 commits intodalance:masterfrom
veeceey:fix/issue-848-double-spacing
Feb 25, 2026
Merged

Fix double-spaced TTY output caused by ANSI-unaware trim_end#875
dalance merged 2 commits intodalance:masterfrom
veeceey:fix/issue-848-double-spacing

Conversation

@veeceey
Copy link
Contributor

@veeceey veeceey commented Feb 23, 2026

Fixes #848

The double spacing happens because str::trim_end() can't trim trailing whitespace that's wrapped inside ANSI color codes. Each column pads its content to full width, and the color styling wraps the padded string with escape sequences like \x1b[32m...padded content...\x1b[0m. Since trim_end() sees \x1b[0m at the end (not whitespace), it doesn't trim anything.

This leaves rows at their full padded width, so they fill the entire terminal line. When the terminal auto-wraps at the right margin and then write_line appends \n, you get an extra blank line between every row.

The fix adds ansi_trim_end() which strips ANSI codes to measure the actual trimmed text width, then truncates the original styled string to that width. This way trailing padding gets removed even when it's wrapped in color codes.

Tested on macOS - output is compact with no extra blank lines between rows.

@dalance
Copy link
Owner

dalance commented Feb 24, 2026

Thank you for your contribution!
This PR looks good, so could you resolve the conflict? I'll merge it after it.

@veeceey veeceey force-pushed the fix/issue-848-double-spacing branch from 0d7d1d9 to ed389e9 Compare February 24, 2026 07:04
When outputting to a terminal, each row's trailing whitespace was not
properly trimmed because str::trim_end() cannot see past ANSI escape
sequences (e.g. color reset codes) at the end of the string. This left
rows padded to their full column width, causing them to fill the entire
terminal line. When the terminal auto-wraps at the right margin and
write_line then appends a newline, an extra blank line appears between
every row.

Replace trim_end() with ansi_trim_end() which strips ANSI codes to
measure the actual trimmed width, then truncates the original styled
string to that width.

Fixes dalance#848
@dalance dalance force-pushed the fix/issue-848-double-spacing branch from b5215b4 to 11b8276 Compare February 24, 2026 23:46
@dalance dalance merged commit 23c6e79 into dalance:master Feb 25, 2026
9 checks passed
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.

procs prints an extra blank line between each process row (TTY output double-spaced)

2 participants