Skip to content

Preserve cell styles when clipping overtyped text - #305

Open
civilwarinfrance wants to merge 1 commit into
jquast:masterfrom
civilwarinfrance:fix/overtyping-cell-styles
Open

civilwarinfrance wants to merge 1 commit into
jquast:masterfrom
civilwarinfrance:fix/overtyping-cell-styles

Conversation

@civilwarinfrance

Copy link
Copy Markdown

Clipping a colored line after a backspace or carriage return can apply the wrong style to both overwritten and untouched characters. For example, clip('\x1b[31mabc\x1b[0m\bX', 0, 3) currently renders all of abX in red, although X was written after the reset and should use the default color.

Record the immutable SGR state alongside painted cells and restore it when reconstructing them in column order. Track the reconstructed output's final style for the trailing reset. This also preserves the style of untouched text when an overwrite introduces a new color. The C extension already delegates cursor movement to this Python painter, so it uses the same fix.

Validation:

  • Added 64 regression cases covering backspace, carriage return, cursor-left/absolute positioning, clipped windows, resets, foreground/background colors, bold, truecolor, combining characters, CJK and emoji. Original code: 60 failures and 4 passing controls.
  • Python-only suite: 1,834 passed, 47 skipped. Extension-enabled suite: 1,870 passed, 11 skipped, including the existing path-parity tests.
  • An additional local comparison of 4,000 generated ASCII/style/cursor cases against Pyte found zero mismatches with this change (3,876 mismatches before it). Pyte is only a local verification tool; no dependency was added.
  • Flake8, Pylint, strict Mypy, docformatter, pydocstyle, doc8, codespell and the strict Sphinx build pass. Changed files pass isort; the full isort check reports an existing formatting difference in unchanged wcwidth/__init__.py, also present on the original revision.

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

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.

1 participant