Skip to content

gh-152233: Add curses complexchar type and wide-character cell reads#152250

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

gh-152233: Add curses complexchar type and wide-character cell reads#152250
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:curses-cchar

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

Add the immutable curses.complexchar type: a styled wide-character cell — a spacing character optionally followed by combining characters, plus attributes and a color pair. The color pair is stored separately rather than packed into a chtype via COLOR_PAIR(), so it is not limited to the values that fit alongside the attribute bits. str(cc) returns the text; the read-only attr and pair attributes return its rendition.

Add the window methods in_wch() and getbkgrnd() — the wide-character counterparts of inch() and getbkgd() — which return a complexchar. (inch()/getbkgd() can only return a packed chtype, so these fill a real gap; this resolves the long-standing gh-83395 request for in_wch.)

The existing character-cell methods (addch, insch, echochar, bkgd, bkgdset, border, box, hline, vline) now also accept a complexchar. A complexchar already carries its own rendition, so passing one together with an explicit attr argument raises TypeError.

Only the reads get a dedicated wide method: a read returns a complexchar instead of a packed chtype, which is a genuine behavioural difference (mirroring getch()/get_wch()). Writes do not differ, so rather than adding parallel add_wch/ins_wch/… methods, the existing writers simply accept a complexchar.

This is the first of two changes for the cchar_t API (gh-152233); a follow-up adds the complexstr cell-array type and the array read/write methods.

@read-the-docs-community

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

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33320243 | 📁 Comparing 7e7c8a9 against main (285d96d)

  🔍 Preview build  

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

…reads

Add the immutable curses.complexchar type: a styled wide-character cell (a
spacing character optionally followed by combining characters, plus attributes
and a color pair stored separately from the packed chtype).

Add the window methods in_wch() and getbkgrnd(), the wide-character
counterparts of inch() and getbkgd(), which return a complexchar.

The character-cell methods (addch, insch, echochar, bkgd, bkgdset, border,
box, hline, vline) now also accept a complexchar; combining one with an
explicit attr argument raises TypeError.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The complexchar constructor accepts attr and pair as argument keywords, whose
interned string identifiers were missing from the generated global-object
tables.  Regenerate them so the module builds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@serhiy-storchaka serhiy-storchaka merged commit 8a01d28 into python:main Jun 26, 2026
54 checks passed
@serhiy-storchaka serhiy-storchaka deleted the curses-cchar branch June 26, 2026 10:49
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