Skip to content

gh-151774: Add curses dynamic color-pair functions#151775

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

gh-151774: Add curses dynamic color-pair functions#151775
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:curses-extended-color

Conversation

@serhiy-storchaka

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

Copy link
Copy Markdown
Member

Wrap the ncurses extended-color dynamic color-pair management, which the standard :mod:curses functions cannot express:

  • curses.alloc_pair(fg, bg) allocates a color pair for the given foreground and background colors and returns its number, reusing an existing pair for the same combination. Unlike init_pair(), the caller does not choose the pair number.
  • curses.find_pair(fg, bg) returns the number of an already-allocated pair for the given colors, or -1 if none has been allocated (the inverse of pair_content()).
  • curses.free_pair(pair) releases a pair previously allocated by alloc_pair().
  • curses.reset_color_pairs() discards all color-pair definitions at once.

All four are available only when Python is built against a wide-character ncurses with extended-color support (the same condition as curses.has_extended_color_support()).

The already-wrapped init_color/init_pair/color_content/pair_content already route to the *_extended_* variants internally, so those extended functions are not exposed under separate names; only the dynamic pair-management functions above add new capability.

🤖 Generated with Claude Code

Add alloc_pair(), find_pair(), free_pair() and reset_color_pairs(),
wrapping the ncurses extended-color dynamic pair management.  They are
available only when built against a wide-character ncurses with
extended-color support.

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 #33226974 | 📁 Comparing 9081e16 against main (aa5b164)

  🔍 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