Fix double-spaced TTY output caused by ANSI-unaware trim_end#875
Merged
dalance merged 2 commits intodalance:masterfrom Feb 25, 2026
Merged
Fix double-spaced TTY output caused by ANSI-unaware trim_end#875dalance merged 2 commits intodalance:masterfrom
dalance merged 2 commits intodalance:masterfrom
Conversation
Owner
|
Thank you for your contribution! |
0d7d1d9 to
ed389e9
Compare
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
b5215b4 to
11b8276
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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. Sincetrim_end()sees\x1b[0mat 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_lineappends\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.