-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Description
Documentation bug: ambiguous wording in curses.color_pair description
The documentation for curses.color_pair currently states:
“This attribute value can be combined with
A_STANDOUT,A_REVERSE, and the otherA_*attributes.”
This wording is ambiguous because constants like A_COLOR, A_ATTRIBUTES, and A_CHARTEXT also follow the A_* naming pattern. However, those three are bit masks for extraction, not style attributes, and therefore cannot be combined with curses.color_pair().
Suggested clarification
- Explicitly state that
curses.color_pair(n)returns an attribute mask that can be combined (via bitwise OR|) with styling attributes such asA_BOLD,A_UNDERLINE,A_REVERSE, etc. - Clarify that
A_COLOR,A_ATTRIBUTES, andA_CHARTEXTare extraction masks used with bitwise AND&when interpreting values returned from methods likewin.inch(). They are not style attributes and should not be combined withcurses.color_pair().
Example improved wording
“The value returned by
curses.color_pair(n)is an attribute mask. It can be combined with other style attributes (such asA_BOLD,A_REVERSE,A_UNDERLINE) using bitwise OR (|).
Note:A_COLOR,A_ATTRIBUTES, andA_CHARTEXTare extraction masks used with bitwise AND (&) on values returned from functions likewin.inch(). They are not style attributes and cannot be combined withcurses.color_pair().”
Example code
# Valid: combining color pair with style attributes
attr = curses.color_pair(3) | curses.A_BOLD | curses.A_REVERSE
win.addstr("Hello", attr)
# Valid: extracting information from inch()
ch_and_attrs = win.inch()
ch = ch_and_attrs & curses.A_CHARTEXT
color = ch_and_attrs & curses.A_COLOR
# Invalid: attempting to combine with extraction masks (has no effect)
attr = curses.color_pair(3) | curses.A_COLOR # misleading / incorrect
<!-- gh-linked-prs -->
### Linked PRs
* gh-138079
<!-- /gh-linked-prs -->Metadata
Metadata
Assignees
Labels
Projects
Status
Status