Skip to content

Commit 309d618

Browse files
committed
Mask the color pair in curses_getcchar() and move the new tests
getcchar() is the one place that reads the pair out of a cell, so the mask belongs there. inch() no longer needs its own. The complexchar checks move to test_complexchar.
1 parent 1f7d17f commit 309d618

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

Lib/test/test_curses.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,14 @@ def test_complexchar(self):
537537
self.assertEqual(str(cc), 'z')
538538
self.assertEqual(cc.attr, 0)
539539
self.assertEqual(cc.pair, 0)
540+
# attr never carries the color pair, not even a pair that does not fit
541+
# in a color_pair() value.
542+
self.assertEqual(curses.complexchar('A', 0, 1).attr, 0)
543+
self.assertEqual(curses.complexchar('A', 0, 300).attr, 0)
544+
self.assertEqual(curses.complexchar('A', curses.A_BOLD, 1).attr,
545+
curses.A_BOLD)
546+
self.assertEqual(curses.complexchar('A', 0, 1).pair, 1)
547+
self.assertEqual(curses.complexchar('A', 0, 300).pair, 300)
540548
# Immutable rendition.
541549
self.assertRaises(AttributeError, setattr, cc, 'attr', 1)
542550
self.assertRaises(AttributeError, setattr, cc, 'pair', 1)
@@ -595,12 +603,6 @@ def test_in_wch_color(self):
595603
self.assertEqual(cc.attr, curses.A_BOLD)
596604
self.assertEqual(cc.pair, 1)
597605
self.assertEqual(curses.complexchar('A', 0, 1).pair, 1)
598-
# attr never carries the color pair, not even a pair that does not fit
599-
# in a color_pair() value.
600-
self.assertEqual(curses.complexchar('A', 0, 1).attr, 0)
601-
self.assertEqual(curses.complexchar('A', 0, 300).attr, 0)
602-
self.assertEqual(curses.complexchar('A', curses.A_BOLD, 1).attr,
603-
curses.A_BOLD)
604606

605607
def test_getbkgrnd(self):
606608
# getbkgrnd() returns the background as a complexchar (getbkgd() can

Modules/_cursesmodule.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,9 @@ curses_getcchar(const cchar_t *wcval, wchar_t *wstr, attr_t *attrs, int *pair)
798798
*pair = spair;
799799
}
800800
#endif
801+
if (rtn != ERR) {
802+
*attrs &= ~(attr_t)A_COLOR;
803+
}
801804
return rtn;
802805
}
803806

@@ -884,7 +887,6 @@ curses_cell_attr_pair(cursesmodule_state *state, const curses_cell_t *cell,
884887
PyErr_SetString(state->error, "getcchar() returned ERR");
885888
return -1;
886889
}
887-
*attr &= ~(attr_t)A_COLOR;
888890
return 0;
889891
#else
890892
*attr = *cell & A_ATTRIBUTES & ~(attr_t)A_COLOR;
@@ -3675,7 +3677,7 @@ _curses_window_inch_impl(PyCursesWindowObject *self, int group_right_1,
36753677
byte = 0;
36763678
}
36773679
}
3678-
rtn = (chtype)byte | (attrs & ~(attr_t)A_COLOR) | COLOR_PAIR(pair);
3680+
rtn = (chtype)byte | attrs | COLOR_PAIR(pair);
36793681
#else
36803682
if (!group_right_1) {
36813683
rtn = winch(self->win);

0 commit comments

Comments
 (0)