gh-123856: Fix PyREPL failure when a keyboard interrupt is triggered after using a history search (#124396)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Emily Morehouse 2024-09-25 11:22:03 -07:00 committed by GitHub
parent 28efeefab7
commit c1600c78e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 115 additions and 90 deletions

View file

@ -28,6 +28,7 @@ from __future__ import annotations
import _sitebuiltins
import linecache
import functools
import os
import sys
import code
@ -50,7 +51,9 @@ def check() -> str:
try:
_get_reader()
except _error as e:
return str(e) or repr(e) or "unknown error"
if term := os.environ.get("TERM", ""):
term = f"; TERM={term}"
return str(str(e) or repr(e) or "unknown error") + term
return ""
@ -159,10 +162,8 @@ def run_multiline_interactive_console(
input_n += 1
except KeyboardInterrupt:
r = _get_reader()
if r.last_command and 'isearch' in r.last_command.__name__:
r.isearch_direction = ''
r.console.forgetinput()
r.pop_input_trans()
if r.input_trans is r.isearch_trans:
r.do_cmd(("isearch-end", [""]))
r.pos = len(r.get_unicode())
r.dirty = True
r.refresh()