Skip to content

Commit 6e4596a

Browse files
Workaround a ncurses 6.1 bug.
1 parent c0ccb2f commit 6e4596a

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

Lib/test/test_curses.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def wrapped(self, *args, **kwargs):
4747
return wrapped
4848

4949
term = os.environ.get('TERM')
50+
SHORT_MAX = 0x7fff
5051

5152
# If newterm was supported we could use it instead of initscr and not exit
5253
@unittest.skipIf(not term or term == 'unknown',
@@ -382,16 +383,10 @@ def test_pair_content(self):
382383
(curses.COLOR_WHITE, curses.COLOR_BLACK))
383384
curses.pair_content(0)
384385
maxpair = curses.COLOR_PAIRS - 1
385-
err = None
386-
while maxpair > 0:
387-
try:
388-
curses.pair_content(maxpair)
389-
break
390-
except curses.error as e:
391-
err = e
392-
maxpair -= 1
393-
if err is not None:
394-
raise err
386+
if (not curses.has_extended_color_support()
387+
or (6,) <= getattr(curses, 'ncurses_version', ()) < (6, 2)):
388+
maxpair = min(maxpair, SHORT_MAX - 1)
389+
curses.pair_content(maxpair)
395390

396391
for pair in self.bad_pairs():
397392
self.assertRaises(ValueError, curses.pair_content, pair)
@@ -410,6 +405,9 @@ def test_init_pair(self):
410405
curses.init_pair(1, 0, maxcolor)
411406
self.assertEqual(curses.pair_content(1), (0, maxcolor))
412407
maxpair = curses.COLOR_PAIRS - 1
408+
if (not curses.has_extended_color_support()
409+
or (6,) <= getattr(curses, 'ncurses_version', ()) < (6, 2)):
410+
maxpair = min(maxpair, SHORT_MAX - 1)
413411
if maxpair > 1:
414412
curses.init_pair(maxpair, 0, 0)
415413
self.assertEqual(curses.pair_content(maxpair), (0, 0))

Modules/_cursesmodule.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ typedef chtype attr_t; /* No attr_t type is available */
135135
#define STRICT_SYSV_CURSES
136136
#endif
137137

138-
#if defined(NCURSES_EXT_COLORS) && defined(NCURSES_EXT_FUNCS)
138+
#if NCURSES_EXT_COLORS+0 && NCURSES_EXT_FUNCS+0
139139
#define _NCURSES_EXTENDED_COLOR_FUNCS 1
140140
#else
141141
#define _NCURSES_EXTENDED_COLOR_FUNCS 0
@@ -3866,14 +3866,12 @@ _curses_pair_content_impl(PyObject *module, int pair_number)
38663866
if (_CURSES_PAIR_CONTENT_FUNC(pair_number, &f, &b) == ERR) {
38673867
if (pair_number >= COLOR_PAIRS) {
38683868
PyErr_Format(PyExc_ValueError,
3869-
"Color pair %d is greater than COLOR_PAIRS-1 (%d).",
3870-
pair_number,
3869+
"Color pair is greater than COLOR_PAIRS-1 (%d).",
38713870
COLOR_PAIRS - 1);
38723871
}
38733872
else {
3874-
PyErr_Format(PyCursesError, "%s() returned ERR for color pair %d",
3875-
Py_STRINGIFY(_CURSES_PAIR_CONTENT_FUNC),
3876-
pair_number);
3873+
PyErr_Format(PyCursesError, "%s() returned ERR",
3874+
Py_STRINGIFY(_CURSES_PAIR_CONTENT_FUNC));
38773875
}
38783876
return NULL;
38793877
}

0 commit comments

Comments
 (0)