Skip to content

Preserve cursor and text when cleaning erase-right sequences - #106

Open
Kulraj69 wants to merge 2 commits into
xolox:masterfrom
Kulraj69:fix-terminal-erase-right
Open

Kulraj69 wants to merge 2 commits into
xolox:masterfrom
Kulraj69:fix-terminal-erase-right

Conversation

@Kulraj69

Copy link
Copy Markdown

Problem

clean_terminal_output() currently treats erase-right as clearing the whole line and moving the cursor to column zero. This can drop the final status from captured progress output:

clean_terminal_output('progress: 100%\rdone\x1b[K\n')
# Current: []
# Expected: ['done']

The default CSI K and explicit-zero CSI 0 K erase from the current cursor to the end of the line. Text before the cursor and the cursor position should stay intact. Reference: https://xfree86.org/current/ctlseqs.html (Erase in Line).

Change

Handle erase-right separately from newlines, truncate only the suffix, and recognize the explicit-zero form. Add seven regression test methods covering both forms, including progress updates, backspaces, later writes, carriage returns and newlines. No new runtime dependency.

Other erase modes, terminal-width wrapping, ANSI color handling and Unicode cell-width emulation are outside this change.

Verification

CPython 3.10.12 on Linux:

  • Original suite: 69 passed.
  • Original implementation with the added tests: 7 failed, 69 passed.
  • Patched full suite: 76 passed, including a fresh checkout fetched from the published fork branch.
  • Full-repository flake8, compileall and git diff --check passed.
  • Branch coverage run: 91% package-wide coverage, not complete platform coverage.
  • Supplemental comparison against pyte 0.8.2: all 5,000 seeded single-line ASCII sequences matched the patched cleanup result. The original implementation disagreed on 3,752. These sequences use ordinary text, carriage return, backspace and the two erase-right forms. Pyte is an external test oracle only, not a project dependency.

Python 2, other Python 3 versions, PyPy, Windows, macOS, the Sphinx build and remote CI were not run locally. No independent human QA results have been received.

AI-assisted implementation and tests. Base: 6758ac61f906cd8528682003070a57febe4ad3cf.

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