Skip to content

Commit a7541c3

Browse files
authored
gh-154840: Keep the color pair out of curses complexchar.attr (GH-154841)
On a wide build getcchar() also reports the color pair in the A_COLOR bits of the attributes, where it saturates at 255, so complexchar.attr carried it. Mask those bits out in curses_getcchar(), as the narrow build already does when packing a cell.
1 parent 198a835 commit a7541c3

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

Lib/test/test_curses.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,11 @@ 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.
541+
self.assertEqual(curses.complexchar('A', 0, 1).attr, 0)
542+
self.assertEqual(curses.complexchar('A', curses.A_BOLD, 1).attr,
543+
curses.A_BOLD)
544+
self.assertEqual(curses.complexchar('A', 0, 1).pair, 1)
540545
# Immutable rendition.
541546
self.assertRaises(AttributeError, setattr, cc, 'attr', 1)
542547
self.assertRaises(AttributeError, setattr, cc, 'pair', 1)
@@ -592,7 +597,7 @@ def test_in_wch_color(self):
592597
stdscr.addch(0, 0, curses.complexchar('A', curses.A_BOLD, 1))
593598
cc = stdscr.in_wch(0, 0)
594599
self.assertEqual(str(cc), 'A')
595-
self.assertTrue(cc.attr & curses.A_BOLD)
600+
self.assertEqual(cc.attr, curses.A_BOLD)
596601
self.assertEqual(cc.pair, 1)
597602
self.assertEqual(curses.complexchar('A', 0, 1).pair, 1)
598603

Modules/_cursesmodule.c

Lines changed: 4 additions & 1 deletion
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

@@ -3674,7 +3677,7 @@ _curses_window_inch_impl(PyCursesWindowObject *self, int group_right_1,
36743677
byte = 0;
36753678
}
36763679
}
3677-
rtn = (chtype)byte | (attrs & ~(attr_t)A_COLOR) | COLOR_PAIR(pair);
3680+
rtn = (chtype)byte | attrs | COLOR_PAIR(pair);
36783681
#else
36793682
if (!group_right_1) {
36803683
rtn = winch(self->win);

0 commit comments

Comments
 (0)