Mercurial > hg
comparison mercurial/crecord.py @ 43460:be0f77fd274d stable
py3: fix handling of ctrl keys in crecord (issue6213)
The "keypressed" value in handlekeypressed() is a key name obtained by
curses's getkey(); this can be a multibyte string for special keys
like CTRL keys. Calling curses.unctrl() with such a value fails on
Python 3 with a TypeError as described in issue6213. (On Python 2, this
does not crash, but I'm not sure the result is correct, though it does
no matter here.)
So instead of calling unctrl(), we compare "keypressed" with the
expected "^L" obtained by curses.ascii.ctrl("L").
author | Denis Laxalde <denis.laxalde@logilab.fr> |
---|---|
date | Wed, 06 Nov 2019 16:54:34 +0100 |
parents | 7cc913396f8c |
children | 9f70512ae2cf |
comparison
equal
deleted
inserted
replaced
43459:7cc913396f8c | 43460:be0f77fd274d |
---|---|
57 """ | 57 """ |
58 ) | 58 ) |
59 | 59 |
60 try: | 60 try: |
61 import curses | 61 import curses |
62 import curses.ascii | |
62 | 63 |
63 curses.error | 64 curses.error |
64 except ImportError: | 65 except ImportError: |
65 # I have no idea if wcurses works with crecord... | 66 # I have no idea if wcurses works with crecord... |
66 try: | 67 try: |
1936 self.handlelastlineevent() | 1937 self.handlelastlineevent() |
1937 elif keypressed in ["?"]: | 1938 elif keypressed in ["?"]: |
1938 self.helpwindow() | 1939 self.helpwindow() |
1939 self.stdscr.clear() | 1940 self.stdscr.clear() |
1940 self.stdscr.refresh() | 1941 self.stdscr.refresh() |
1941 elif curses.unctrl(keypressed) in ["^L"]: | 1942 elif keypressed in [curses.ascii.ctrl("L")]: |
1942 # scroll the current line to the top of the screen, and redraw | 1943 # scroll the current line to the top of the screen, and redraw |
1943 # everything | 1944 # everything |
1944 self.scrolllines(self.selecteditemstartline) | 1945 self.scrolllines(self.selecteditemstartline) |
1945 self.stdscr.clear() | 1946 self.stdscr.clear() |
1946 self.stdscr.refresh() | 1947 self.stdscr.refresh() |