Repository navigation
Conversation
…rap state When __write_changed_line writes to the last column of the terminal, the cursor enters "pending wrap" state where it physically stays at width-1. However, posxy was recording width, causing subsequent CUB (Cursor Backward) calculations to overshoot by one cell. Cap posxy x-coordinate at width-1 to match the physical cursor position in pending wrap state. This fixes the cursor moving backward during tab completion in xterm and Ghostty. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
This PR is stale because it has been open for 30 days with no activity. |
…-tab-cursor # Conflicts: # Lib/_pyrepl/unix_console.py
Contributor
Author
|
Main is merged in as of 34d2c34. The refresh code was restructured in gh-148105, so the old per-branch edits no longer applied. The same off-by-one is still there though: __apply_line_update sets posxy to start_x + char_width, which can equal the terminal width after writing into the last column. I moved the clamp to the end of __apply_line_update so it covers every update kind, and added test_write_to_last_column_records_pending_wrap_position. It fails on main and passes here; the rest of test_unix_console passes too. |
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 #145448
Summary
When the PyREPL's
__write_changed_linewrites to the last column of the terminal, the cursor enters "pending wrap" state - it physically stays at columnwidth-1butposxywas recordingwidth. This caused subsequent CUB (Cursor Backward) escape sequences to overshoot by one cell, moving the cursor one position too far left.Root cause: In
unix_console.py, three code paths in__write_changed_linesetposxyto the full line width without accounting for pending wrap state. When the cursor is later moved back (e.g., to return to the input line after showing "[ complete but not unique ]"), the CUB count is calculated astarget_x - widthinstead oftarget_x - (width-1), producing one extra backward movement.Fix: Cap
posxy[0]atself.width - 1when writing reaches the terminal edge. This matches the physical cursor position in pending wrap state, so CUB calculations produce the correct count.Why Terminal.app isn't affected: Terminal.app compensates by subtracting 1 from CUB in pending wrap state. xterm and Ghostty do not compensate, matching the spec more strictly.
Test plan
test_pyrepltests passposxyassignment paths in__write_changed_lineThis contribution was developed with AI assistance (Claude Code).