Skip to content

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

Merged
ambv merged 10 commits into
python:mainfrom
johnslavik:enable-error-overlays
Oct 20, 2026
Merged

ambv merged 10 commits into
python:mainfrom
johnslavik:enable-error-overlays

Conversation

@johnslavik

@johnslavik johnslavik commented Apr 7, 2026 •

Copy link
Copy Markdown
Member

When you press Tab and nothing matches, the REPL now shows ! no matches, so you know why it did nothing:

Screen.Recording.2026-04-07.at.19.04.58.mov

If a history search finds nothing, or Ctrl-Y has no cut text to insert, the REPL explains why. It also reports keys with no command assigned, so you can tell whether it understood your shortcut:

Screen.Recording.2026-04-07.at.19.08.58.mov

The REPL always created these messages, but they were discarded silently. This PR displays them temporarily below the input and asks the terminal to beep. The ! prefix is colored when color is enabled.

I've made some opinionated choices on which messages should go through or not, e.g. moving past the start or end of the input stays silent because messages there would make ordinary editing distracting. As the issue notes, some messages still may need clearer wording, and accidental shortcuts can produce a message and beep. Any opinions on these would be very welcome (especially around how we present unknown shortcuts).

Tests cover messages, beep calls, colors, and line wrapping on narrow terminals, including text with color codes, wide characters, and combining accents.

@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
@johnslavik
johnslavik requested a review from pablogsal July 24, 2026 18:28
@ambv
ambv merged commit f5bd077 into python:main Oct 20, 2026
76 of 78 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Sprint Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sprint topic-repl Related to the interactive shell

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants