mirror of
https://github.com/python/cpython.git
synced 2025-07-29 22:24:49 +00:00
Patch for bug #1633621: if curses.resizeterm() or
curses.resize_term() is called, update _curses.LINES, _curses.COLS, curses.LINES and curses.COLS.
This commit is contained in:
parent
40c626159d
commit
d391f0855c
2 changed files with 71 additions and 2 deletions
|
@ -241,12 +241,21 @@ def test_userptr_without_set(stdscr):
|
||||||
except curses.panel.error:
|
except curses.panel.error:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_resize_term(stdscr):
|
||||||
|
if hasattr(curses, 'resizeterm'):
|
||||||
|
lines, cols = curses.LINES, curses.COLS
|
||||||
|
curses.resizeterm(lines - 1, cols + 1)
|
||||||
|
|
||||||
|
if curses.LINES != lines - 1 or curses.COLS != cols + 1:
|
||||||
|
raise RuntimeError, "Expected resizeterm to update LINES and COLS"
|
||||||
|
|
||||||
def main(stdscr):
|
def main(stdscr):
|
||||||
curses.savetty()
|
curses.savetty()
|
||||||
try:
|
try:
|
||||||
module_funcs(stdscr)
|
module_funcs(stdscr)
|
||||||
window_funcs(stdscr)
|
window_funcs(stdscr)
|
||||||
test_userptr_without_set(stdscr)
|
test_userptr_without_set(stdscr)
|
||||||
|
test_resize_term(stdscr)
|
||||||
finally:
|
finally:
|
||||||
curses.resetty()
|
curses.resetty()
|
||||||
|
|
||||||
|
|
|
@ -2196,19 +2196,72 @@ PyCurses_QiFlush(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES
|
||||||
|
* and _curses.COLS */
|
||||||
|
static int
|
||||||
|
update_lines_cols(void)
|
||||||
|
{
|
||||||
|
PyObject *o;
|
||||||
|
PyObject *m = PyImport_ImportModule("curses");
|
||||||
|
|
||||||
|
if (!m)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
o = PyInt_FromLong(LINES);
|
||||||
|
if (!o) {
|
||||||
|
Py_DECREF(m);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (PyObject_SetAttrString(m, "LINES", o)) {
|
||||||
|
Py_DECREF(m);
|
||||||
|
Py_DECREF(o);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (PyDict_SetItemString(ModDict, "LINES", o)) {
|
||||||
|
Py_DECREF(m);
|
||||||
|
Py_DECREF(o);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Py_DECREF(o);
|
||||||
|
o = PyInt_FromLong(COLS);
|
||||||
|
if (!o) {
|
||||||
|
Py_DECREF(m);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (PyObject_SetAttrString(m, "COLS", o)) {
|
||||||
|
Py_DECREF(m);
|
||||||
|
Py_DECREF(o);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (PyDict_SetItemString(ModDict, "COLS", o)) {
|
||||||
|
Py_DECREF(m);
|
||||||
|
Py_DECREF(o);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Py_DECREF(o);
|
||||||
|
Py_DECREF(m);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_CURSES_RESIZETERM
|
#ifdef HAVE_CURSES_RESIZETERM
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PyCurses_ResizeTerm(PyObject *self, PyObject *args)
|
PyCurses_ResizeTerm(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int lines;
|
int lines;
|
||||||
int columns;
|
int columns;
|
||||||
|
PyObject *result;
|
||||||
|
|
||||||
PyCursesInitialised
|
PyCursesInitialised
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns))
|
if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return PyCursesCheckERR(resizeterm(lines, columns), "resizeterm");
|
result = PyCursesCheckERR(resizeterm(lines, columns), "resizeterm");
|
||||||
|
if (!result)
|
||||||
|
return NULL;
|
||||||
|
if (!update_lines_cols())
|
||||||
|
return NULL;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2220,12 +2273,19 @@ PyCurses_Resize_Term(PyObject *self, PyObject *args)
|
||||||
int lines;
|
int lines;
|
||||||
int columns;
|
int columns;
|
||||||
|
|
||||||
|
PyObject *result;
|
||||||
|
|
||||||
PyCursesInitialised
|
PyCursesInitialised
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns))
|
if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return PyCursesCheckERR(resize_term(lines, columns), "resize_term");
|
result = PyCursesCheckERR(resize_term(lines, columns), "resize_term");
|
||||||
|
if (!result)
|
||||||
|
return NULL;
|
||||||
|
if (!update_lines_cols())
|
||||||
|
return NULL;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
#endif /* HAVE_CURSES_RESIZE_TERM */
|
#endif /* HAVE_CURSES_RESIZE_TERM */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue