Skip to content

Commit 7e68790

Browse files
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.
1 parent d1e3403 commit 7e68790

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

Lib/test/test_curses.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ def test_issue6243(self):
359359
self.stdscr.getkey()
360360

361361
@requires_curses_func('unget_wch')
362+
# XXX Remove the decorator when ncurses on OpenBSD be updated
363+
@unittest.skipIf(sys.platform.startswith("openbsd"),
364+
"OpenBSD's curses (v.5.7) has bugs")
362365
def test_unget_wch(self):
363366
stdscr = self.stdscr
364367
encoding = stdscr.encoding
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added a workaround for getkey() in curses for ncurses 5.7 and earlier.

Modules/_cursesmodule.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,8 +1163,16 @@ PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
11631163
if (!PyErr_Occurred())
11641164
PyErr_SetString(PyCursesError, "no input");
11651165
return NULL;
1166-
} else if (rtn<=255) {
1167-
return Py_BuildValue("C", rtn);
1166+
} else if (rtn <= 255) {
1167+
#ifdef NCURSES_VERSION_MAJOR
1168+
#if NCURSES_VERSION_MAJOR*100+NCURSES_VERSION_MINOR <= 507
1169+
/* Work around a bug in ncurses 5.7 and earlier */
1170+
if (rtn < 0) {
1171+
rtn += 256;
1172+
}
1173+
#endif
1174+
#endif
1175+
return PyUnicode_FromOrdinal(rtn);
11681176
} else {
11691177
const char *knp = keyname(rtn);
11701178
return PyUnicode_FromString((knp == NULL) ? "" : knp);

0 commit comments

Comments
 (0)