Skip to content

gh-140131: Fix REPL cursor position on Windows when module completion suggestion line hits console width#140333

Merged
ambv merged 18 commits intopython:mainfrom
tanloong:fix-repl-cursor-pos-windows-module-completion
Mar 12, 2026
Merged

gh-140131: Fix REPL cursor position on Windows when module completion suggestion line hits console width#140333
ambv merged 18 commits intopython:mainfrom
tanloong:fix-repl-cursor-pos-windows-module-completion

Conversation

@tanloong
Copy link
Contributor

@tanloong tanloong commented Oct 19, 2025

This skips handling the wrapping in self.__write_changed_line() when wlen(newline)==self.width, and simply updates self.posxy (explained in #140131 (comment)).

One thing that happens after the skip is that the cursor moves leftward by one character on Tab key:

WindowsTerminal_eDpHfMhTvA.mp4

As noted in this comment, "when writing to the final character on the line, the cursor location is effectively moved one element backwards." So, we account for this 1-character offset by setting the cursor column to a maximum of self.width-1.

WindowsTerminal_0fSumUhJoh.mp4

@tanloong tanloong marked this pull request as ready for review October 20, 2025 14:32
@tanloong tanloong marked this pull request as draft October 20, 2025 15:35
@tanloong tanloong marked this pull request as ready for review October 25, 2025 16:22
@tanloong
Copy link
Contributor Author

tanloong commented Feb 9, 2026

@chris-eibl I've added tests for this.

@chris-eibl chris-eibl self-requested a review February 10, 2026 18:48
@tanloong
Copy link
Contributor Author

tanloong commented Feb 11, 2026

Thank you for the review! Added the second blurb.

Copy link
Member

@chris-eibl chris-eibl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm. This is now ready for core dev review. Thank you for your contribution.

@ambv ambv merged commit e13f6dc into python:main Mar 12, 2026
60 checks passed
@ambv ambv added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Mar 12, 2026
@miss-islington-app
Copy link

Thanks @tanloong for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @tanloong for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @tanloong for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app
Copy link

Thanks @tanloong for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 12, 2026
…letion suggestion line hits console width (pythonGH-140333)

(cherry picked from commit e13f6dc)

Co-authored-by: Tan Long <tanloong@foxmail.com>
@miss-islington-app
Copy link

Sorry, @tanloong and @ambv, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker e13f6dccd7a2f8df543a18c4a3ad92610dc087cb 3.13

@bedevere-app
Copy link

bedevere-app bot commented Mar 12, 2026

GH-145871 is a backport of this pull request to the 3.14 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 12, 2026
…letion suggestion line hits console width (pythonGH-140333)

(cherry picked from commit e13f6dc)

Co-authored-by: Tan Long <tanloong@foxmail.com>
@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Mar 12, 2026
@miss-islington-app
Copy link

Sorry @tanloong and @ambv, I had trouble completing the backport.
Please retry by removing and re-adding the "needs backport to 3.14" label.
Please backport backport using cherry_picker on the command line.

cherry_picker e13f6dccd7a2f8df543a18c4a3ad92610dc087cb 3.14

@miss-islington-app
Copy link

Sorry, @tanloong and @ambv, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker e13f6dccd7a2f8df543a18c4a3ad92610dc087cb 3.13

ambv pushed a commit to ambv/cpython that referenced this pull request Mar 12, 2026
…le completion suggestion line hits console width (pythonGH-140333)

(cherry picked from commit e13f6dc)

Co-authored-by: Tan Long <tanloong@foxmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 12, 2026

GH-145872 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Mar 12, 2026
ambv pushed a commit that referenced this pull request Mar 12, 2026
…pletion suggestion line hits console width (GH-140333) (GH-145871)

(cherry picked from commit e13f6dc)

Co-authored-by: Tan Long <tanloong@foxmail.com>
ambv added a commit that referenced this pull request Mar 12, 2026
…pletion suggestion line hits console width (GH-140333) (GH-145872)

(cherry picked from commit e13f6dc)

Co-authored-by: Tan Long <tanloong@foxmail.com>
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Ubuntu Shared 3.13 (tier-1) has failed when building commit 3ae8cc8.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1450/builds/1621) and take a look at the build logs.
  4. Check if the failure is related to this commit (3ae8cc8) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1450/builds/1621

Failed tests:

  • test_pyrepl

Failed subtests:

  • test_repl_eio - test.test_pyrepl.test_unix_console.TestUnixConsoleEIOHandling.test_repl_eio

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/srv/buildbot/buildarea/3.13.bolen-ubuntu/build/Lib/subprocess.py", line 1140, in __del__
    _warn("subprocess %s is still running" % self.pid,
ResourceWarning: subprocess 3964108 is still running
Warning -- Unraisable exception
Exception ignored in: <_io.FileIO name=8 mode='rb' closefd=True>
Traceback (most recent call last):
  File "/srv/buildbot/buildarea/3.13.bolen-ubuntu/build/Lib/unittest/case.py", line 650, in run
    with outcome.testPartExecutor(self):
ResourceWarning: unclosed file <_io.TextIOWrapper name=8 encoding='UTF-8'>
Warning -- Unraisable exception
Exception ignored in: <_io.FileIO name=10 mode='rb' closefd=True>
Traceback (most recent call last):
  File "/srv/buildbot/buildarea/3.13.bolen-ubuntu/build/Lib/unittest/case.py", line 650, in run
    with outcome.testPartExecutor(self):
ResourceWarning: unclosed file <_io.TextIOWrapper name=10 encoding='UTF-8'>


Traceback (most recent call last):
  File "/srv/buildbot/buildarea/3.13.bolen-ubuntu/build/Lib/subprocess.py", line 1140, in __del__
    _warn("subprocess %s is still running" % self.pid,
ResourceWarning: subprocess 3929058 is still running
Warning -- Unraisable exception
Exception ignored in: <_io.FileIO name=8 mode='rb' closefd=True>
Traceback (most recent call last):
  File "/srv/buildbot/buildarea/3.13.bolen-ubuntu/build/Lib/unittest/case.py", line 650, in run
    with outcome.testPartExecutor(self):
ResourceWarning: unclosed file <_io.TextIOWrapper name=8 encoding='UTF-8'>
Warning -- Unraisable exception
Exception ignored in: <_io.FileIO name=10 mode='rb' closefd=True>
Traceback (most recent call last):
  File "/srv/buildbot/buildarea/3.13.bolen-ubuntu/build/Lib/unittest/case.py", line 650, in run
    with outcome.testPartExecutor(self):
ResourceWarning: unclosed file <_io.TextIOWrapper name=10 encoding='UTF-8'>


Traceback (most recent call last):
  File "/srv/buildbot/buildarea/3.13.bolen-ubuntu/build/Lib/test/test_pyrepl/test_unix_console.py", line 415, in test_repl_eio
    _, err = proc.communicate(timeout=support.LONG_TIMEOUT)
             ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/buildbot/buildarea/3.13.bolen-ubuntu/build/Lib/subprocess.py", line 1222, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
                     ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/buildbot/buildarea/3.13.bolen-ubuntu/build/Lib/subprocess.py", line 2155, in _communicate
    self._check_timeout(endtime, orig_timeout, stdout, stderr)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/buildbot/buildarea/3.13.bolen-ubuntu/build/Lib/subprocess.py", line 1269, in _check_timeout
    raise TimeoutExpired(
    ...<2 lines>...
            stderr=b''.join(stderr_seq) if stderr_seq else None)
subprocess.TimeoutExpired: Command '['/srv/buildbot/buildarea/3.13.bolen-ubuntu/build/python', '-E', '-S', '/srv/buildbot/buildarea/3.13.bolen-ubuntu/build/Lib/test/test_pyrepl/eio_test_script.py']' timed out after 300.0 seconds

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.

4 participants