mirror of
https://github.com/python/cpython.git
synced 2025-12-17 22:31:28 +00:00
bpo-15037: Add a workaround for getkey() in curses for ncurses 5.7 and earlier. (#3826)
Skip a test for unget_wch()/get_wch() on OpenBSD since they are broken in ncurses 5.7.
This commit is contained in:
parent
d1e34031f6
commit
7e68790f3d
3 changed files with 14 additions and 2 deletions
|
|
@ -359,6 +359,9 @@ class TestCurses(unittest.TestCase):
|
||||||
self.stdscr.getkey()
|
self.stdscr.getkey()
|
||||||
|
|
||||||
@requires_curses_func('unget_wch')
|
@requires_curses_func('unget_wch')
|
||||||
|
# XXX Remove the decorator when ncurses on OpenBSD be updated
|
||||||
|
@unittest.skipIf(sys.platform.startswith("openbsd"),
|
||||||
|
"OpenBSD's curses (v.5.7) has bugs")
|
||||||
def test_unget_wch(self):
|
def test_unget_wch(self):
|
||||||
stdscr = self.stdscr
|
stdscr = self.stdscr
|
||||||
encoding = stdscr.encoding
|
encoding = stdscr.encoding
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Added a workaround for getkey() in curses for ncurses 5.7 and earlier.
|
||||||
|
|
@ -1163,8 +1163,16 @@ PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
|
||||||
if (!PyErr_Occurred())
|
if (!PyErr_Occurred())
|
||||||
PyErr_SetString(PyCursesError, "no input");
|
PyErr_SetString(PyCursesError, "no input");
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (rtn<=255) {
|
} else if (rtn <= 255) {
|
||||||
return Py_BuildValue("C", rtn);
|
#ifdef NCURSES_VERSION_MAJOR
|
||||||
|
#if NCURSES_VERSION_MAJOR*100+NCURSES_VERSION_MINOR <= 507
|
||||||
|
/* Work around a bug in ncurses 5.7 and earlier */
|
||||||
|
if (rtn < 0) {
|
||||||
|
rtn += 256;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
return PyUnicode_FromOrdinal(rtn);
|
||||||
} else {
|
} else {
|
||||||
const char *knp = keyname(rtn);
|
const char *knp = keyname(rtn);
|
||||||
return PyUnicode_FromString((knp == NULL) ? "" : knp);
|
return PyUnicode_FromString((knp == NULL) ? "" : knp);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue