Skip to content

Commit bd874ac

Browse files
authored
gh-158955: Avoid insert-character for PyREPL line appends (GH-158995)
1 parent 697853c commit bd874ac

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎Lib/_pyrepl/unix_console.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ def __plan_changed_line(
835835
planned_cells = diff.new_cells
836836
changed_cell = visible_new_cells[0]
837837
return LineUpdate(
838-
kind="insert_char",
838+
kind=("replace_char" if start_x == oldline.width else "insert_char"),
839839
y=y,
840840
start_cell=start_cell,
841841
start_x=start_x,

‎Lib/test/test_pyrepl/test_unix_console.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,27 @@ def test_cursor_back_write(self, _os_write):
259259
_os_write.assert_any_call(ANY, b"2")
260260
con.restore()
261261

262+
def test_insert_char_only_for_midline_insert(self, _os_write):
263+
insert_char = b"<insert-char>"
264+
events = itertools.chain(
265+
code_to_events("1"),
266+
[Event(evt="key", data="left", raw=bytearray(b"\x1bOD"))],
267+
code_to_events("2"),
268+
)
269+
_, con = handle_all_events(
270+
events,
271+
prepare_console=partial(unix_console, ich1=insert_char),
272+
)
273+
relevant_writes = []
274+
for write in _os_write.call_args_list:
275+
output = write.args[1]
276+
if insert_char in output:
277+
relevant_writes.append(insert_char)
278+
elif output in {b"1", b"2"}:
279+
relevant_writes.append(output)
280+
self.assertEqual(relevant_writes, [b"1", insert_char, b"2"])
281+
con.restore()
282+
262283
def test_multiline_function_move_up_short_terminal(self, _os_write):
263284
# fmt: off
264285
code = (
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed PyREPL rendering on WSL by avoiding the unnecessary INS terminal sequence when appending a character at the end of a line. INS remains used for true mid-line insertions, with regression coverage added.

0 commit comments

Comments
 (0)