Skip to content

gh-152219: Add curses window attribute get/set methods and WA_* constants#152221

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:curses-attr-get-set
Jun 26, 2026
Merged

gh-152219: Add curses window attribute get/set methods and WA_* constants#152221
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:curses-attr-get-set

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jun 25, 2026

Copy link
Copy Markdown
Member

Add the curses window methods attr_get(), attr_set(), attr_on(), attr_off() and color_set(), wrapping wattr_get(), wattr_set(), wattr_on(), wattr_off() and wcolor_set().

Unlike the legacy attron()/attroff()/attrset() methods, which take a chtype with the color pair packed in via COLOR_PAIR(), these pass the color pair as a separate argument. This is the form used internally by the cchar_t-based wide-character output, and it can address color pairs beyond 255 without colliding with the attribute bits.

Also add the corresponding WA_* attribute constants (WA_NORMAL, WA_BOLD, WA_UNDERLINE, WA_REVERSE, WA_BLINK, WA_DIM, WA_STANDOUT, WA_ALTCHARSET, WA_INVIS, WA_PROTECT, WA_ITALIC and the placement constants), each guarded by #ifdef. On ncurses they are bit-identical to the matching A_* values.

This PR adds an attr_converter that range-checks the attr_t argument and raises OverflowError instead of silently truncating; it is applied to attr_set(), attr_on(), attr_off() and chgat(). A converter for the chtype-style methods (addch, bkgd, hline, etc.) is left for a separate issue.

… constants

Add the window methods attr_get(), attr_set(), attr_on(), attr_off() and
color_set(), wrapping wattr_get(), wattr_set(), wattr_on(), wattr_off() and
wcolor_set().  Unlike the legacy attron()/attroff()/attrset() methods, these
pass the color pair as a separate argument instead of packing it into the
attribute value.  Also add the corresponding WA_* attribute constants.

Add an attr_converter that range-checks the attr_t attribute argument and
raises OverflowError instead of silently truncating it; apply it to attr_set(),
attr_on(), attr_off() and chgat().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@read-the-docs-community

read-the-docs-community Bot commented Jun 25, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33318101 | 📁 Comparing 7fcac00 against main (7676427)

  🔍 Preview build  

4 files changed
± library/curses.html
± library/stdtypes.html
± whatsnew/3.16.html
± whatsnew/changelog.html

@serhiy-storchaka serhiy-storchaka merged commit 285d96d into python:main Jun 26, 2026
54 checks passed
@serhiy-storchaka serhiy-storchaka deleted the curses-attr-get-set branch June 26, 2026 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant