Patchwork [3,of,3,STABLE] py3: fix handling of ctrl keys in crecord (issue6213)

login
register
mail settings
Submitter Denis Laxalde
Date Nov. 6, 2019, 4:23 p.m.
Message ID <f4415c4f24f879845f5d.1573057409@steppe.local>
Download mbox | patch
Permalink /patch/42804/
State New
Headers show

Comments

Denis Laxalde - Nov. 6, 2019, 4:23 p.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1573055674 -3600
#      Wed Nov 06 16:54:34 2019 +0100
# Branch stable
# Node ID f4415c4f24f879845f5dc631d592440e88d2afee
# Parent  5802765e3828e3b3f1396b92ed7ef18a1eca6456
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").
Yuya Nishihara - Nov. 7, 2019, 11:28 p.m.
On Wed, 06 Nov 2019 17:23:29 +0100, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde@logilab.fr>
> # Date 1573055674 -3600
> #      Wed Nov 06 16:54:34 2019 +0100
> # Branch stable
> # Node ID f4415c4f24f879845f5dc631d592440e88d2afee
> # Parent  5802765e3828e3b3f1396b92ed7ef18a1eca6456
> 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").
> 
> diff --git a/mercurial/crecord.py b/mercurial/crecord.py
> --- a/mercurial/crecord.py
> +++ b/mercurial/crecord.py
> @@ -59,6 +59,7 @@ patchhelptext = _(
>  
>  try:
>      import curses
> +    import curses.ascii
>  
>      curses.error
>  except ImportError:

Maybe need to import wcurses.ascii? I don't know if that works, though.
Denis Laxalde - Nov. 8, 2019, 9:11 a.m.
Yuya Nishihara a écrit :
> On Wed, 06 Nov 2019 17:23:29 +0100, Denis Laxalde wrote:
> > # HG changeset patch
> > # User Denis Laxalde <denis.laxalde@logilab.fr>
> > # Date 1573055674 -3600
> > #      Wed Nov 06 16:54:34 2019 +0100
> > # Branch stable
> > # Node ID f4415c4f24f879845f5dc631d592440e88d2afee
> > # Parent  5802765e3828e3b3f1396b92ed7ef18a1eca6456
> > 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").
> > 
> > diff --git a/mercurial/crecord.py b/mercurial/crecord.py
> > --- a/mercurial/crecord.py
> > +++ b/mercurial/crecord.py
> > @@ -59,6 +59,7 @@ patchhelptext = _(
> >  
> >  try:
> >      import curses
> > +    import curses.ascii
> >  
> >      curses.error
> >  except ImportError:
> 
> Maybe need to import wcurses.ascii? I don't know if that works, though.

I don't know either. If wcurses is https://github.com/idobatter/wcurses,
there does not appear to be an "ascii" module.
Does anybody use crecord on windows?

Patch

diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -59,6 +59,7 @@  patchhelptext = _(
 
 try:
     import curses
+    import curses.ascii
 
     curses.error
 except ImportError:
@@ -1938,7 +1939,7 @@  are you sure you want to review/edit and
             self.helpwindow()
             self.stdscr.clear()
             self.stdscr.refresh()
-        elif curses.unctrl(keypressed) in ["^L"]:
+        elif keypressed in [curses.ascii.ctrl("L")]:
             # scroll the current line to the top of the screen, and redraw
             # everything
             self.scrolllines(self.selecteditemstartline)