Skip to content

Ambiguous wording in curses.color_pair description #138071

@peturingi

Description

@peturingi

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 other A_* 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 as A_BOLD, A_UNDERLINE, A_REVERSE, etc.
  • Clarify that A_COLOR, A_ATTRIBUTES, and A_CHARTEXT are extraction masks used with bitwise AND & when interpreting values returned from methods like win.inch(). They are not style attributes and should not be combined with curses.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 as A_BOLD, A_REVERSE, A_UNDERLINE) using bitwise OR (|).
Note: A_COLOR, A_ATTRIBUTES, and A_CHARTEXT are extraction masks used with bitwise AND (&) on values returned from functions like win.inch(). They are not style attributes and cannot be combined with curses.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

No one assigned

    Labels

    docsDocumentation in the Doc dirpendingThe issue will be closed if no feedback is provided

    Projects

    Status

    Done

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions