]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #4254: Adds _curses.update_lines_cols() Patch by Arnon Yaari
authorSteve Dower <steve.dower@microsoft.com>
Wed, 15 Apr 2015 22:06:05 +0000 (18:06 -0400)
committerSteve Dower <steve.dower@microsoft.com>
Wed, 15 Apr 2015 22:06:05 +0000 (18:06 -0400)
Doc/library/curses.rst
Doc/whatsnew/3.5.rst
Lib/test/test_curses.py
Misc/NEWS
Modules/_cursesmodule.c

index f3e60b4be94d60c4852082001feb005f02c71cd9..e8dfd833e414acf141d3a37d025cfb5fa1c1032a 100644 (file)
@@ -599,6 +599,13 @@ The module :mod:`curses` defines the following functions:
       Only one *ch* can be pushed before :meth:`getch` is called.
 
 
+.. function:: update_lines_cols()
+
+   Update :envvar:`LINES` and :envvar:`COLS`. Useful for detecting manual screen resize.
+
+   .. versionadded:: 3.5
+
+
 .. function:: unget_wch(ch)
 
    Push *ch* so the next :meth:`get_wch` will return it.
index 5d010bfc786af308b44cdbc6eec5c2b765317a69..2960979910c065f8c12aebd51ab2fb862db0bee9 100644 (file)
@@ -289,6 +289,11 @@ contextlib
   don't provide any options to redirect it.
   (Contributed by Berker Peksag in :issue:`22389`.)
 
+curses
+------
+* The new :func:`curses.update_lines_cols` function updates the variables
+  :envvar:`curses.LINES` and :envvar:`curses.COLS`.
+
 difflib
 -------
 
index bd7d4fca8bee8f8fd2528b19f887832d9db985bb..274704152007d01b383422f72916528ea198cabc 100644 (file)
@@ -370,6 +370,13 @@ class TestCurses(unittest.TestCase):
         offset = human_readable_signature.find("[y, x,]")
         assert offset >= 0, ""
 
+    def test_update_lines_cols(self):
+        # this doesn't actually test that LINES and COLS are updated,
+        # because we can't automate changing them. See Issue #4254 for
+        # a manual test script. We can only test that the function
+        # can be called.
+        curses.update_lines_cols()
+
 
 if __name__ == '__main__':
     unittest.main()
index 5f5cac6c35090799aa076cb09e7574ba755d2992..cd1d81e45d218637a49383db430f5fbc9a301f6d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -36,6 +36,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #4254: Adds _curses.update_lines_cols() Patch by Arnon Yaari
+
 - Issue 19933: Provide default argument for ndigits in round. Patch by
   Vajrasky Kok.
 
index 54c724ba5f9fc49bcd976a0b4a8f8dd1669473ae..d64bdc74e916a5292749babddf3244ecb2d91c40 100644 (file)
@@ -2866,6 +2866,13 @@ update_lines_cols(void)
     Py_DECREF(m);
     return 1;
 }
+
+static PyObject *
+PyCurses_update_lines_cols(PyObject *self)
+{
+  return PyLong_FromLong((long) update_lines_cols());
+}
+
 #endif
 
 #ifdef HAVE_CURSES_RESIZETERM
@@ -3268,6 +3275,9 @@ static PyMethodDef PyCurses_methods[] = {
     {"typeahead",           (PyCFunction)PyCurses_TypeAhead, METH_VARARGS},
     {"unctrl",              (PyCFunction)PyCurses_UnCtrl, METH_VARARGS},
     {"ungetch",             (PyCFunction)PyCurses_UngetCh, METH_VARARGS},
+#if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM)
+    {"update_lines_cols",   (PyCFunction)PyCurses_update_lines_cols, METH_NOARGS},
+#endif
 #ifdef HAVE_NCURSESW
     {"unget_wch",           (PyCFunction)PyCurses_Unget_Wch, METH_VARARGS},
 #endif