mirror of
https://github.com/python/cpython.git
synced 2025-10-22 09:23:54 +00:00
gh-135621: Remove dependency on curses from PyREPL (GH-136758)
This commit is contained in:
parent
d1d526afe7
commit
09dfb50f1b
11 changed files with 1229 additions and 160 deletions
|
@ -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 @@
|
|||
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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue