gh-152260: Add curses.scr_dump(), scr_restore(), scr_init() and scr_set()#152261
Merged
Conversation
… scr_set() These module-level functions write the whole virtual screen to a file and load it back -- the screen-wide counterpart of window.putwin()/getwin(). The filename argument accepts a string or a path-like object. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Documentation build overview
8 files changed ·
|
vstinner
approved these changes
Jun 26, 2026
vstinner
left a comment
Member
There was a problem hiding this comment.
LGTM. The implementation looks complete and correct, and the added test checks the 4 added functions.
I don't need these functions, but I'm fine with exposing them in Python since they exist in the C library.
| self.assertEqual(win.getmaxyx(), (5, 12)) | ||
| self.assertEqual(win.instr(2, 0), b' Lorem ipsum') | ||
|
|
||
| def test_scr_dump(self): |
Member
There was a problem hiding this comment.
The test name seems to say that scr_dump() is tested, but in fact it tests 4 functions. You may add a comment to say it:
# Test scr_dump(), scr_restore(), scr_init() and scr_set()
# Conflicts: # Doc/whatsnew/3.16.rst # Modules/clinic/_cursesmodule.c.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
curses.scr_dump(),scr_restore(),scr_init()andscr_set(), the module-level functions that dump the whole screen to a file and restore it -- the screen-wide counterpart ofwindow.putwin()/getwin().Unlike
putwin()/getwin(), which take a Python file object (mirroring Cputwin(WINDOW *, FILE *)), the Cscr_*functions are filename-based (theyfopeninternally), so these wrappers take a filename: astror a path-like object.The restored screen is internal curses state (the virtual screen), not a readable window, so the test checks the round-trip by comparing dump files: dump, change the screen, restore, dump again, and assert the two dumps are byte-for-byte identical.