Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-152260: Add curses.scr_dump(), scr_restore(), scr_init() and scr_set()#152261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
a0546a5df15c09c05f51c637352dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1116,6 +1116,43 @@ def test_putwin(self): | ||
| self.assertEqual(win.getmaxyx(), (5, 12)) | ||
| self.assertEqual(win.instr(2, 0), b' Lorem ipsum') | ||
| def test_scr_dump(self): | ||
| # Test scr_dump(), scr_restore(), scr_init() and scr_set(). | ||
| # scr_dump() writes the virtual screen to a named file; the other three | ||
serhiy-storchaka marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| # functions load it back. The dumped image is internal curses state, | ||
| # not a window, so the round-trip is checked by comparing dump files | ||
| # rather than reading cells. | ||
| stdscr = self.stdscr | ||
| stdscr.erase() | ||
| stdscr.addstr(0, 0, 'screen dump test') | ||
| stdscr.refresh() | ||
| with tempfile.TemporaryDirectory() as d: | ||
| dump = os.path.join(d, 'dump') | ||
| self.assertIsNone(curses.scr_dump(dump)) | ||
| # Dumping the same screen again is deterministic. | ||
| dump2 = os.path.join(d, 'dump2') | ||
| curses.scr_dump(dump2) | ||
| with open(dump, 'rb') as f1, open(dump2, 'rb') as f2: | ||
| self.assertEqual(f1.read(), f2.read()) | ||
| # scr_restore() reloads that virtual screen, so dumping it again | ||
| # reproduces the original file even after the screen has changed. | ||
| stdscr.erase() | ||
| stdscr.addstr(0, 0, 'something else') | ||
| stdscr.refresh() | ||
| self.assertIsNone(curses.scr_restore(dump)) | ||
| restored = os.path.join(d, 'restored') | ||
| curses.scr_dump(restored) | ||
| with open(dump, 'rb') as f1, open(restored, 'rb') as f2: | ||
| self.assertEqual(f1.read(), f2.read()) | ||
| # scr_init() and scr_set() accept a dump file and return None. | ||
| self.assertIsNone(curses.scr_init(dump)) | ||
| self.assertIsNone(curses.scr_set(dump)) | ||
| # A bytes (path-like) filename is accepted too. | ||
| curses.scr_dump(os.fsencode(dump)) | ||
| # Restoring from a missing file is an error. | ||
| self.assertRaises(curses.error, | ||
| curses.scr_restore, os.path.join(d, 'nope')) | ||
| def test_borders_and_lines(self): | ||
| win = curses.newwin(5, 10, 5, 2) | ||
| win.border('|', '!', '-', '_', | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Add the :mod:`curses` functions :func:`~curses.scr_dump`, | ||
| :func:`~curses.scr_restore`, :func:`~curses.scr_init` and | ||
| :func:`~curses.scr_set`, which dump the whole screen to a file and restore it. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()