Skip to content

gh-151757: Support wide and combining characters in the curses module#151758

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:curses-widechar
Open

gh-151757: Support wide and combining characters in the curses module#151758
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:curses-widechar

Conversation

@serhiy-storchaka

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

Copy link
Copy Markdown
Member

The character-cell window methods now accept a full character cell -- a spacing character optionally followed by combining characters (up to CCHARW_MAX wide characters) -- in addition to a single int or byte character. This affects addch(), bkgd(), bkgdset(), border(), box(), echochar(), hline(), insch() and vline(), which dispatch to the ncursesw wide-character functions (wadd_wch(), wbkgrnd(), wborder_set(), wecho_wchar(), whline_set(), wins_wch(), wvline_set(), ...) when given a string. border() and box() cannot mix integer or byte characters with wide-string characters in a single call.

A cell is one spacing character optionally followed by combining characters, so an extra spacing or control character (for example "ab", an emoji ZWJ sequence, or an emoji with a skin-tone modifier) is rejected with ValueError rather than being silently truncated by setcchar(). A single control character is still accepted (curses applies its usual control processing, e.g. backspace, tab and carriage return).

Also added are the wide-character read methods window.get_wstr() and window.in_wstr(), the counterparts of window.getstr() and window.instr() that return a str rather than bytes, and the module functions curses.erasewchar(), curses.killwchar() and curses.wunctrl(), the wide-character counterparts of curses.erasechar(), curses.killchar() and curses.unctrl().

All of this is available only when built against the wide-character ncursesw library.

🤖 Generated with Claude Code

…module

The character-cell window methods now accept a full character cell -- a
spacing character optionally followed by combining characters (up to
CCHARW_MAX wide characters) -- in addition to a single int or byte
character.  This affects addch(), bkgd(), bkgdset(), border(), box(),
echochar(), hline(), insch() and vline(); they dispatch to the ncursesw
wide-character functions (wadd_wch(), wbkgrnd(), wborder_set(),
wecho_wchar(), whline_set(), wins_wch(), wvline_set(), ...) when given a
string.  border() and box() cannot mix integer or byte characters with
wide string characters in a single call.  A cell is one spacing character
optionally followed by combining characters, so an extra spacing or
control character (such as "ab") is rejected with ValueError rather than
being silently truncated by setcchar().

Also add the wide-character read methods get_wstr() and in_wstr(), the
counterparts of getstr() and instr() that return a str rather than a
bytes object, and the module functions erasewchar(), killwchar() and
wunctrl(), the wide-character counterparts of erasechar(), killchar()
and unctrl().

All of this is available only when built against the wide-character
ncursesw library.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33224239 | 📁 Comparing 6cb20f7 against main (66cc048)

  🔍 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