Skip to content

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

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:curses-attr-get-set
Open

gh-152219: Add curses window attribute get/set methods and WA_* constants#152221
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:curses-attr-get-set

Conversation

@serhiy-storchaka

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

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33311536 | 📁 Comparing 655a33b against main (7676427)

  🔍 Preview build  

3 files changed
± library/curses.html
± whatsnew/3.16.html
± whatsnew/changelog.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant