Skip to content

gh-148228: Enable error overlays in the REPL#148229

Open
johnslavik wants to merge 10 commits into
python:mainfrom
johnslavik:enable-error-overlays
Open

gh-148228: Enable error overlays in the REPL#148229
johnslavik wants to merge 10 commits into
python:mainfrom
johnslavik:enable-error-overlays

Conversation

@johnslavik

Copy link
Copy Markdown
Member

Small proof of concept for gh-148228. We can build on this further on.

@johnslavik johnslavik changed the title gh-148228: Enable error overlays gh-148228: Enable error overlays in the REPL Apr 8, 2026
@johnslavik johnslavik added the topic-repl Related to the interactive shell label Apr 9, 2026
Comment thread Lib/_pyrepl/commands.py
Comment thread Lib/_pyrepl/reader.py
t = THEME()
error_prefix = f"{t.error}{error_prefix}{t.reset}"
self.console.beep()
self.msg = error_prefix + msg

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.

Maybe I am misreading this flow but if I am not wrong, the error() now embeds the escape sequences into self.msg. The message renderer at _render_message_lines slices by string length, not visible width. Then, len(message_line) counts the ANSI bytes (\x1b[1;31m ... \x1b[0m), so on narrow terminals (or long error messages) the slice boundary can land mid-escape, producing a truncated \x1b[ on one line and stray m on the next leaving the whole line un-colored or visually corrupted.

@johnslavik johnslavik Jul 20, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I wired it to use the same wrapping method as layout_content_lines. Should be fine now!

Screenshot 2026-07-20 at 23 48 15

(Taking this to extremes, we don't handle splitting prompt string if terminal is too narrow. Technically anyone can set their own prompt string, so maybe we should?)

Comment thread Lib/_pyrepl/commands.py Outdated
@johnslavik johnslavik self-assigned this Jun 2, 2026
@read-the-docs-community

read-the-docs-community Bot commented Jul 19, 2026

Copy link
Copy Markdown

@johnslavik
johnslavik force-pushed the enable-error-overlays branch from 1d02b0f to 8cb9bc0 Compare July 20, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review sprint topic-repl Related to the interactive shell

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants