and return the previously current screen.
Returns ``None`` if the previous screen was the one created by
:func:`initscr`.
+ Raises :exc:`error` if *screen* has no terminal,
+ as is the case for a screen returned by :func:`new_prescr`.
.. versionadded:: next
del screen
gc_collect()
+ @requires_curses_func('new_prescr')
+ def test_set_term_prescr_screen(self):
+ # A new_prescr() screen has no terminal, so it cannot become the
+ # current one. It used to be accepted, and the next refresh then
+ # crashed inside curses.
+ s = self.make_pty()
+ screen = curses.newterm('xterm', s, s)
+ self.assertRaises(curses.error, curses.set_term, curses.new_prescr())
+ # The current screen is unchanged, so refreshing it still works.
+ screen.stdscr.refresh()
+
def test_initscr_after_newterm_keeps_screen_alive(self):
# initscr() called while a newterm() screen is current returns that
# screen's own standard window, so the window keeps the screen alive.
if (so == NULL) {
return NULL;
}
+ cursesmodule_state *state = get_cursesmodule_state(module);
+ if (so->stdscr_win == NULL) {
+ /* A screen from new_prescr() has no terminal, so it cannot become the
+ current one: a later refresh would dereference NULL in curses. */
+ PyErr_SetString(state->error, "the screen has no terminal");
+ return NULL;
+ }
set_term(so->screen);
if (!update_lines_cols(module)) {
return NULL;
}
- cursesmodule_state *state = get_cursesmodule_state(module);
PyObject *prev = state->topscreen; /* steal the owned reference */
state->topscreen = Py_NewRef(screen);
return prev != NULL ? prev : Py_NewRef(Py_None);