1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
--- contrib/tools/python3/Lib/_pyrepl/unix_console.py (index)
+++ contrib/tools/python3/Lib/_pyrepl/unix_console.py (working tree)
@@ -32,7 +32,7 @@ import time
import platform
from fcntl import ioctl
-from . import curses
+from . import terminfo
from .console import Console, Event
from .fancy_termios import tcgetattr, tcsetattr, TermState
from .trace import trace
@@ -55,7 +55,7 @@ class InvalidTerminal(RuntimeError):
super().__init__(errno.EIO, message)
-_error = (termios.error, curses.error, InvalidTerminal)
+_error = (termios.error, InvalidTerminal)
_error_codes_to_ignore = frozenset([errno.EIO, errno.ENXIO, errno.EPERM])
SIGWINCH_EVENT = "repaint"
@@ -156,7 +156,7 @@ class UnixConsole(Console):
self.pollob.register(self.input_fd, select.POLLIN)
self.input_buffer = b""
self.input_buffer_pos = 0
- curses.setupterm(term or None, self.output_fd)
+ self.terminfo = terminfo.TermInfo(term or None)
self.term = term
self.is_apple_terminal = (
platform.system() == "Darwin"
@@ -177,7 +177,7 @@ class UnixConsole(Console):
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"
@@ -211,7 +211,7 @@ class UnixConsole(Console):
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)
@@ -630,14 +630,14 @@ class UnixConsole(Console):
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
@@ -734,7 +734,7 @@ class UnixConsole(Console):
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:
--- contrib/tools/python3/Lib/_pyrepl/unix_eventqueue.py (index)
+++ contrib/tools/python3/Lib/_pyrepl/unix_eventqueue.py (working tree)
@@ -18,7 +18,7 @@
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-from . import curses
+from .terminfo import TermInfo
from .trace import trace
from .base_eventqueue import BaseEventQueue
from termios import tcgetattr, VERASE
@@ -54,22 +54,23 @@ CTRL_ARROW_KEYCODES= {
b'\033Oc': 'ctrl right',
}
-def get_terminal_keycodes() -> dict[bytes, str]:
+def get_terminal_keycodes(ti: TermInfo) -> dict[bytes, str]:
"""
Generates a dictionary mapping terminal keycodes to human-readable names.
"""
keycodes = {}
for key, terminal_code in TERMINAL_KEYNAMES.items():
- keycode = curses.tigetstr(terminal_code)
+ keycode = ti.get(terminal_code)
trace('key {key} tiname {terminal_code} keycode {keycode!r}', **locals())
if keycode:
keycodes[keycode] = key
keycodes.update(CTRL_ARROW_KEYCODES)
return keycodes
+
class EventQueue(BaseEventQueue):
- def __init__(self, fd: int, encoding: str) -> None:
- keycodes = get_terminal_keycodes()
+ def __init__(self, fd: int, encoding: str, ti: TermInfo) -> None:
+ keycodes = get_terminal_keycodes(ti)
if os.isatty(fd):
backspace = tcgetattr(fd)[6][VERASE]
keycodes[backspace] = "backspace"
|