Skip to content

Preserve display cells and control policies when clipping cursor movement - #427

Closed
civilwarinfrance wants to merge 1 commit into
jquast:masterfrom
civilwarinfrance:fix/clip-preserves-raw-cursor-movement
Closed

civilwarinfrance wants to merge 1 commit into
jquast:masterfrom
civilwarinfrance:fix/clip-preserves-raw-cursor-movement

Conversation

@civilwarinfrance

Copy link
Copy Markdown

Terminal.clip() and truncate() can delete untouched text when the input moves the cursor left. For example, term.clip('abc\x1b[2DX') returns aX instead of aXc. Preprocessing with Sequence.padd() slices Unicode codepoints rather than display cells, so it also mishandles backspaces into combining characters and wide graphemes. The preprocessing removes cursor controls before control_codes='ignore' or 'strict' can handle them.

Pass the original Sequence to wcwidth.clip(), which already resolves horizontal cursor movement and the requested control-code policy. Update the API descriptions and changelog. This is separate from the per-cell SGR issue in jquast/wcwidth#305: these regressions pass with released wcwidth 0.9.4 and the existing minimum 0.9.2, without a dependency change.

Validation:

  • Added 30 cases across the Terminal/Sequence clipping and truncation APIs, including surviving tails, nonzero clipping windows, combining characters, CJK, ZWJ emoji, ignored movement and strict bounds checks. Original code: 26 failures and 4 passing controls.
  • Full suite with TEST_QUICK=0 TEST_KEYBOARD=1: 1,985 passed, 53 skipped. All 79 sequence tests pass with both wcwidth 0.9.4 and 0.9.2.
  • Flake8, strict Mypy, test Pylint, isort, docformatter, pydocstyle, doc8, README validation, codespell and the strict Sphinx documentation build pass. Runtime Pylint reports the same existing diagnostics as the original revision; none added.

AI assistance was used to investigate, implement and test this change.

@jquast

jquast commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Thanks for both

@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.64%. Comparing base (eb97098) to head (ca325d1).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #427      +/-   ##
==========================================
- Coverage   97.74%   97.64%   -0.10%     
==========================================
  Files          13       13              
  Lines        4118     4118              
  Branches      696      696              
==========================================
- Hits         4025     4021       -4     
- Misses         71       73       +2     
- Partials       22       24       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jquast

jquast commented Nov 14, 2026

Copy link
Copy Markdown
Owner

I'll bring this up to date in another branch/PR thanks

@jquast jquast closed this in #434 Nov 14, 2026
rahul05ranjan pushed a commit to rahul05ranjan/blessed that referenced this pull request Nov 14, 2026
This follows up jquast#427, simplifying it a bit, it's something I missed in wcwidth integration jquast#420.

It's also not necessarily a "bugfix" but rather an "improvement" in performance. The call to `padd()` is removed, which was originally done as a hack to replace tabs or "cursor right" `\x1b[10C` to spaces, `' '*10`, and only so that it would be easily measured or truncated

Closes jquast#427.
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.

2 participants