[3.14] gh-135621: Remove dependency on curses from PyREPL (GH-136758) (GH-136915)

(cherry picked from commit 09dfb50f1b)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Miss Islington (bot) 2025-07-21 13:02:41 +02:00 committed by GitHub
parent 4f6f3ee8d3
commit 031645a884
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 1229 additions and 160 deletions

View file

@ -33,7 +33,7 @@
import platform
from fcntl import ioctl
from . import curses
from . import terminfo
from .console import Console, Event
from .fancy_termios import tcgetattr, tcsetattr
from .trace import trace
@ -60,7 +60,7 @@ class InvalidTerminal(RuntimeError):
pass
_error = (termios.error, curses.error, InvalidTerminal)
_error = (termios.error, InvalidTerminal)
SIGWINCH_EVENT = "repaint"
@ -157,7 +157,7 @@ def __init__(
self.pollob = poll()
self.pollob.register(self.input_fd, select.POLLIN)
curses.setupterm(term or None, self.output_fd)
self.terminfo = terminfo.TermInfo(term or None)
self.term = term
@overload
@ -167,7 +167,7 @@ def _my_getstr(cap: str, optional: Literal[False] = False) -> bytes: ...
def _my_getstr(cap: str, optional: bool) -> bytes | None: ...
def _my_getstr(cap: str, optional: bool = False) -> bytes | None:
r = curses.tigetstr(cap)
r = self.terminfo.get(cap)
if not optional and r is None:
raise InvalidTerminal(
f"terminal doesn't have the required {cap} capability"
@ -201,7 +201,7 @@ def _my_getstr(cap: str, optional: bool = False) -> bytes | None:
self.__setup_movement()
self.event_queue = EventQueue(self.input_fd, self.encoding)
self.event_queue = EventQueue(self.input_fd, self.encoding, self.terminfo)
self.cursor_visible = 1
signal.signal(signal.SIGCONT, self._sigcont_handler)
@ -597,14 +597,14 @@ def __setup_movement(self):
if self._dch1:
self.dch1 = self._dch1
elif self._dch:
self.dch1 = curses.tparm(self._dch, 1)
self.dch1 = terminfo.tparm(self._dch, 1)
else:
self.dch1 = None
if self._ich1:
self.ich1 = self._ich1
elif self._ich:
self.ich1 = curses.tparm(self._ich, 1)
self.ich1 = terminfo.tparm(self._ich, 1)
else:
self.ich1 = None
@ -701,7 +701,7 @@ def __write(self, text):
self.__buffer.append((text, 0))
def __write_code(self, fmt, *args):
self.__buffer.append((curses.tparm(fmt, *args), 1))
self.__buffer.append((terminfo.tparm(fmt, *args), 1))
def __maybe_write_code(self, fmt, *args):
if fmt: