Skip to content

gh-90092: Support multiple terminals in the curses module#151748

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

gh-90092: Support multiple terminals in the curses module#151748
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:curses-newterm

Conversation

@serhiy-storchaka

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

Copy link
Copy Markdown
Member

Add the X/Open Curses SCREEN API for driving more than one terminal: curses.newterm() and curses.set_term(), plus the ncurses extension curses.new_prescr().

A new screen object wraps the C SCREEN and exposes the terminal's standard window as screen.stdscr. Each window keeps a reference to its screen (like a subwindow does to its parent window), so a screen is freed automatically once it and all of its windows are unreferenced. delscreen() is deferred to the screen object's deallocation rather than its tp_clear, so it runs only after the screen's windows — and any panels built on them — are gone.

The ncurses use_screen()/use_window() locking helpers are exposed as the screen.use() and window.use() methods, forwarding *args and **kwargs to the callable.

ScreenTests now run in-process over pseudo-terminals instead of subprocesses, and TestCurses drives a newterm() screen, so the new API is exercised without needing a second real terminal.

🤖 Generated with Claude Code

Add the X/Open Curses SCREEN API for driving more than one terminal:
newterm() and set_term(), plus the ncurses extension new_prescr().

A new screen object wraps the C SCREEN.  It exposes the terminal's
standard window as screen.stdscr.  Each window keeps a reference to its
screen (like a subwindow does to its parent window), so the screen is
deleted automatically once it and all of its windows are unreferenced.

The ncurses use_screen()/use_window() locking helpers are exposed as
the screen.use() and window.use() methods.

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 #33222029 | 📁 Comparing 0028058 against main (2e5843e)

  🔍 Preview build  

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

Comment thread Doc/library/curses.rst
that can be used to call functions that affect global state
before :func:`initscr` or :func:`newterm` is called.

Availability: if the underlying curses library provides ``new_prescr()``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not be using the directive?

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.

2 participants