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
|
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. |
pablogsal
left a comment
There was a problem hiding this comment.
Please rebase against main to resolve the conflicts.
| # by one cell (gh-145448). | ||
| x, y = self.posxy | ||
| if x >= self.width: | ||
| self.posxy = self.width - 1, y |
There was a problem hiding this comment.
This fixes the backward move. In a five-column terminal, an update from abcde to abcdf can write the f on the next row. Can we track pending wrap for that write too?
There was a problem hiding this comment.
Yes, fixed in 26471c2: UnixConsole now tracks pending wrap after a write fills the last column, and the next short move emits \r first so abcde to abcdf rewrites the f on the same row. I added test_write_after_pending_wrap_stays_on_row for that case, and sh -c "./python.exe -m test test_pyrepl" exited 0 on that commit.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
Conflicts are resolved in 7774f23, which brings in current main; the only conflict was in Lib/test/test_pyrepl/test_unix_console.py, and I kept both test_write_to_last_column_records_pending_wrap_position and the new test_insert_char_only_for_midline_insert. After |
|
Thanks for making the requested changes! @pablogsal: please review the changes made to this pull request. |
After a write fills the last column the terminal is in pending wrap state. If the next update targets that same cell, the relative move emits nothing and the write lands on the next row. Track the pending wrap and emit a carriage return before the next relative move.
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).