Skip to content

wrap(): drop trailing space hidden before SGR sequence - #334

Open
tony1233200 wants to merge 2 commits into
jquast:masterfrom
tony1233200:fix-wrap-trailing-space-332
Open

tony1233200 wants to merge 2 commits into
jquast:masterfrom
tony1233200:fix-wrap-trailing-space-332

Conversation

@tony1233200

Copy link
Copy Markdown

Fixes #332

wrap() with drop_whitespace=True kept a visible trailing space when a long word's leading SGR sequence was assigned to the preceding full line: the line ended with the escape sequence, so the plain str.rstrip() at the emit site never saw the space before it.

Use the existing sequence-aware _rstrip_visible() helper at the emit site instead, falling back to rstrip() so sequence-only lines are retained as before.

Regression tests added to tests/test_textwrap.py cover both line_break modes, propagate_sgr on/off, the drop_whitespace=False control, plain-text behaviour, and sequence-only input.

Test report:

  • WCWIDTH_PYTHON=1 python -m pytest tests/test_textwrap.py: 387 passed
  • WCWIDTH_PYTHON=1 python -m pytest tests wcwidth: 1960 passed, 56 skipped (plus test_package_version, which only fails when the package metadata is not installed; it passes once installed)

This branch has not been deployed

No deployments
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.

wrap() retains trailing spaces before SGR sequences with drop_whitespace=True

2 participants