]> granicus.if.org Git - python/commitdiff
Patch #1506645: add Python wrappers for the curses functions
authorWalter Dörwald <walter@livinglogic.de>
Mon, 19 Jun 2006 08:07:50 +0000 (08:07 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Mon, 19 Jun 2006 08:07:50 +0000 (08:07 +0000)
is_term_resized, resize_term and resizeterm. This uses three
separate configure checks (one for each function).

Lib/test/test_curses.py
Misc/NEWS
Modules/_cursesmodule.c
configure
configure.in
pyconfig.h.in

index dc2f20bd518f5672e4f6895c263021ba347328a0..4022149310f9a3048768022c1ad196134dfbca69 100644 (file)
@@ -212,6 +212,13 @@ def module_funcs(stdscr):
             m = curses.getmouse()
             curses.ungetmouse(*m)
 
+    if hasattr(curses, 'is_term_resized'):
+        curses.is_term_resized(*stdscr.getmaxyx())
+    if hasattr(curses, 'resizeterm'):
+        curses.resizeterm(*stdscr.getmaxyx())
+    if hasattr(curses, 'resize_term'):
+        curses.resize_term(*stdscr.getmaxyx())
+
 def unit_tests():
     from curses import ascii
     for ch, expected in [('a', 'a'), ('A', 'A'),
index d690117bde3468c9897d97e65149e7e280bb2e91..3b8e22cb603a156fce09e943b276e40d8db174ab 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -163,6 +163,8 @@ Extension Modules
 
 - Patch #1446489: add support for the ZIP64 extensions to zipfile. 
 
+- Patch #1506645: add Python wrappers for the curses functions
+  is_term_resized, resize_term and resizeterm.
 
 Library
 -------
index 71d7a696c3ca656cb3f396674a7fa2614b10e365..f74cfd59ff505974b73ccddf438b62056b847a69 100644 (file)
@@ -44,7 +44,7 @@ unsupported functions:
        mcprint mvaddchnstr mvaddchstr mvchgat mvcur mvinchnstr
        mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr mvwchgat
        mvwgetnstr mvwinchnstr mvwinchstr mvwinnstr newterm
-       resizeterm restartterm ripoffline scr_dump
+       restartterm ripoffline scr_dump
        scr_init scr_restore scr_set scrl set_curterm set_term setterm
        tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
        vidattr vidputs waddchnstr waddchstr wchgat
@@ -1950,6 +1950,29 @@ PyCurses_IntrFlush(PyObject *self, PyObject *args)
   return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
 }
 
+#ifdef HAVE_CURSES_IS_TERM_RESIZED
+static PyObject *
+PyCurses_Is_Term_Resized(PyObject *self, PyObject *args)
+{
+  int lines;
+  int columns;
+  int result;
+
+  PyCursesInitialised
+
+  if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns))
+    return NULL;
+  result = is_term_resized(lines, columns);
+  if (result == TRUE) {
+    Py_INCREF(Py_True);
+    return Py_True;
+  } else {
+    Py_INCREF(Py_False);
+    return Py_False;
+  }
+}
+#endif /* HAVE_CURSES_IS_TERM_RESIZED */
+
 #if !defined(__NetBSD__)
 static PyObject *
 PyCurses_KeyName(PyObject *self, PyObject *args)
@@ -2170,6 +2193,39 @@ PyCurses_QiFlush(PyObject *self, PyObject *args)
   }
 }
 
+#ifdef HAVE_CURSES_RESIZETERM
+static PyObject *
+PyCurses_ResizeTerm(PyObject *self, PyObject *args)
+{
+  int lines;
+  int columns;
+
+  PyCursesInitialised
+
+  if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns))
+    return NULL;
+
+  return PyCursesCheckERR(resizeterm(lines, columns), "resizeterm");
+}
+
+#endif
+
+#ifdef HAVE_CURSES_RESIZE_TERM
+static PyObject *
+PyCurses_Resize_Term(PyObject *self, PyObject *args)
+{
+  int lines;
+  int columns;
+
+  PyCursesInitialised
+
+  if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns))
+    return NULL;
+
+  return PyCursesCheckERR(resize_term(lines, columns), "resize_term");
+}
+#endif /* HAVE_CURSES_RESIZE_TERM */
+
 static PyObject *
 PyCurses_setsyx(PyObject *self, PyObject *args)
 {
@@ -2414,6 +2470,9 @@ static PyMethodDef PyCurses_methods[] = {
   {"initscr",             (PyCFunction)PyCurses_InitScr, METH_NOARGS},
   {"intrflush",           (PyCFunction)PyCurses_IntrFlush, METH_VARARGS},
   {"isendwin",            (PyCFunction)PyCurses_isendwin, METH_NOARGS},
+#ifdef HAVE_CURSES_IS_TERM_RESIZED
+  {"is_term_resized",     (PyCFunction)PyCurses_Is_Term_Resized, METH_VARARGS},
+#endif
 #if !defined(__NetBSD__)
   {"keyname",             (PyCFunction)PyCurses_KeyName, METH_VARARGS},
 #endif
@@ -2441,6 +2500,12 @@ static PyMethodDef PyCurses_methods[] = {
   {"reset_prog_mode",     (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS},
   {"reset_shell_mode",    (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS},
   {"resetty",             (PyCFunction)PyCurses_resetty, METH_NOARGS},
+#ifdef HAVE_CURSES_RESIZETERM
+  {"resizeterm",          (PyCFunction)PyCurses_ResizeTerm, METH_VARARGS},
+#endif
+#ifdef HAVE_CURSES_RESIZE_TERM
+  {"resize_term",         (PyCFunction)PyCurses_Resize_Term, METH_VARARGS},
+#endif
   {"savetty",             (PyCFunction)PyCurses_savetty, METH_NOARGS},
   {"setsyx",              (PyCFunction)PyCurses_setsyx, METH_VARARGS},
   {"setupterm",           (PyCFunction)PyCurses_setupterm,
index ca50d4b00268e59761004422d83bedac7b034b47..7098f5f5ec43b4e6b2d121c1c66fc229461b2c2c 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 46879 .
+# From configure.in Revision: .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.59 for python 2.5.
 #
@@ -722,13 +722,13 @@ echo X"$0" |
          /^X\(\/\).*/{ s//\1/; q; }
          s/.*/./; q'`
   srcdir=$ac_confdir
-  if test ! -r $srcdir/$ac_unique_file; then
+  if test ! -r "$srcdir/$ac_unique_file"; then
     srcdir=..
   fi
 else
   ac_srcdir_defaulted=no
 fi
-if test ! -r $srcdir/$ac_unique_file; then
+if test ! -r "$srcdir/$ac_unique_file"; then
   if test "$ac_srcdir_defaulted" = yes; then
     { echo "$as_me: error: cannot find sources ($ac_unique_file) in $ac_confdir or .." >&2
    { (exit 1); exit 1; }; }
@@ -737,7 +737,7 @@ if test ! -r $srcdir/$ac_unique_file; then
    { (exit 1); exit 1; }; }
   fi
 fi
-(cd $srcdir && test -r ./$ac_unique_file) 2>/dev/null ||
+(cd $srcdir && test -r "./$ac_unique_file") 2>/dev/null ||
   { echo "$as_me: error: sources are in $srcdir, but \`cd $srcdir' does not work" >&2
    { (exit 1); exit 1; }; }
 srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'`
@@ -21854,6 +21854,174 @@ _ACEOF
 
 fi
 
+echo "$as_me:$LINENO: checking for is_term_resized" >&5
+echo $ECHO_N "checking for is_term_resized... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <curses.h>
+int
+main ()
+{
+void *x=is_term_resized
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+        { ac_try='test -z "$ac_c_werror_flag"
+                        || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+        { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_CURSES_IS_TERM_RESIZED 1
+_ACEOF
+
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+echo "$as_me:$LINENO: checking for resize_term" >&5
+echo $ECHO_N "checking for resize_term... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <curses.h>
+int
+main ()
+{
+void *x=resize_term
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+        { ac_try='test -z "$ac_c_werror_flag"
+                        || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+        { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_CURSES_RESIZE_TERM 1
+_ACEOF
+
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+echo "$as_me:$LINENO: checking for resizeterm" >&5
+echo $ECHO_N "checking for resizeterm... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <curses.h>
+int
+main ()
+{
+void *x=resizeterm
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+        { ac_try='test -z "$ac_c_werror_flag"
+                        || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+        { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_CURSES_RESIZETERM 1
+_ACEOF
+
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
 echo "$as_me:$LINENO: checking for /dev/ptmx" >&5
 echo $ECHO_N "checking for /dev/ptmx... $ECHO_C" >&6
 
index 1b7b57e0a8bba495bca6e4b5d49327c9790fde48..2e9ea1010eb6196cca7f4f7efb5684bdbd104f50 100644 (file)
@@ -3295,6 +3295,27 @@ then
   [Define if WINDOW in curses.h offers a field _flags.])
 fi
 
+AC_MSG_CHECKING(for is_term_resized)
+AC_TRY_COMPILE([#include <curses.h>], void *x=is_term_resized,
+  AC_DEFINE(HAVE_CURSES_IS_TERM_RESIZED, 1, Define if you have the 'is_term_resized' function.)
+  AC_MSG_RESULT(yes),
+  AC_MSG_RESULT(no)
+)
+
+AC_MSG_CHECKING(for resizeterm)
+AC_TRY_COMPILE([#include <curses.h>], void *x=resizeterm,
+  AC_DEFINE(HAVE_CURSES_RESIZETERM, 1, Define if you have the 'resizeterm' function.)
+  AC_MSG_RESULT(yes),
+  AC_MSG_RESULT(no)
+)
+
+AC_MSG_CHECKING(for resize_term)
+AC_TRY_COMPILE([#include <curses.h>], void *x=resize_term,
+  AC_DEFINE(HAVE_CURSES_RESIZE_TERM, 1, Define if you have the 'resize_term' function.)
+  AC_MSG_RESULT(yes),
+  AC_MSG_RESULT(no)
+)
+
 AC_MSG_CHECKING(for /dev/ptmx)
 
 if test -e /dev/ptmx
index 84486ca522d7c96d33edf56b5ba60ae04132bdcb..7598504704242193c2169f3526e656a298046fb4 100644 (file)
 /* Define to 1 if you have the `realpath' function. */
 #undef HAVE_REALPATH
 
+/* Define to 1 if you have the `is_term_resized' function. */
+#undef HAVE_CURSES_IS_TERM_RESIZED
+
+/* Define to 1 if you have the `resize_term' function. */
+#undef HAVE_CURSES_RESIZE_TERM
+
+/* Define to 1 if you have the `resizeterm' function. */
+#undef HAVE_CURSES_RESIZETERM
+
 /* Define if you have readline 2.1 */
 #undef HAVE_RL_CALLBACK