Skip to content

gh-150462: REPL Fix cursor position when using \b - #150488

Open
edvilme wants to merge 8 commits into
python:mainfrom
edvilme:pyrepl-backspace
Open

edvilme wants to merge 8 commits into
python:mainfrom
edvilme:pyrepl-backspace

Conversation

@edvilme

@edvilme edvilme commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes length miscalculation when dealing with \b character that caused the cursor to be placed in an incorrect position

Refactors Lib/_pyrepl/utils.py wlen to properly handle \b characters.

CC @pablogsal

Fixes length miscalculation when dealing with \b character that caused the cursor to be placed in an incorrect position
@edvilme edvilme changed the title gh-150462: Fix cursor position when using \\b gh-150462: Fix cursor position when using \b May 26, 2026

@florentx florentx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LG, thank you.

Comment thread Lib/_pyrepl/utils.py Resolved
Comment thread Lib/_pyrepl/utils.py Resolved
@edvilme
edvilme force-pushed the pyrepl-backspace branch from d421286 to 6de4d52 Compare May 26, 2026 20:28
Comment thread Lib/_pyrepl/utils.py Resolved
@edvilme
edvilme requested a review from tanloong May 31, 2026 02:08
@brettcannon
brettcannon requested review from brettcannon and removed request for tanloong July 1, 2026 02:42
Comment thread Lib/_pyrepl/utils.py Resolved
Comment thread Lib/_pyrepl/utils.py Resolved
@edvilme
edvilme requested a review from pablogsal August 19, 2026 02:39
@edvilme edvilme changed the title gh-150462: Fix cursor position when using \b gh-150462: REPL Fix cursor position when using \b Aug 25, 2026
Comment thread Lib/_pyrepl/utils.py
for c in plain:
if c == "\b":
# Backspace decreases cursor position, and cannot move before column 0.
length = max(length - 1, 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This adjusts the prompt width, but the render cells still count the backspace. With input('Question? _\b'), the terminal moves two columns too far left. Can we use the same cursor calculation in both places?

@bedevere-app

bedevere-app Bot commented Nov 26, 2026

Copy link
Copy Markdown

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be put in the comfy chair!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants