Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/_pyrepl/unix_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,14 @@ def __apply_line_update(
self.__write(text)
self.posxy = update.start_x + update.char_width, update.y

# When a write reaches the last column, the terminal enters the
# "pending wrap" state and the cursor physically stays at width - 1.
# Record that position so later relative moves (CUB) don't overshoot
# by one cell (gh-145448).
x, y = self.posxy
if x >= self.width:
self.posxy = self.width - 1, y

if update.reset_to_margin:
# Non-SGR terminal controls can affect the cursor position.
self.move_cursor(0, update.y)
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_pyrepl/test_unix_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@ def test_cursor_back_write(self, _os_write):
_os_write.assert_any_call(ANY, b"2")
con.restore()

def test_write_to_last_column_records_pending_wrap_position(self, _os_write):
# gh-145448: after writing into the last column the terminal is in
# "pending wrap" state and the cursor stays at width - 1.
from _pyrepl.render import LineUpdate, RenderCell
con = unix_console(iter([]), width=5)
cells = tuple(RenderCell(ch, 1) for ch in "abcde")
update = LineUpdate(
kind="replace_span", y=0, start_cell=0, start_x=0,
cells=cells, char_width=5,
)
con._UnixConsole__apply_line_update(update)
self.assertEqual(con.posxy, (4, 0))
con.restore()

def test_multiline_function_move_up_short_terminal(self, _os_write):
# fmt: off
code = (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed REPL tab completion cursor moving backward by one cell in terminals
that correctly handle CUB (Cursor Backward) in pending wrap state, such as
xterm and Ghostty.
Loading