@@ -1843,77 +1843,51 @@ curses_clinic_parse_optional_xy_n(PyObject *args,
18431843 }
18441844}
18451845
1846- [
1847- y : int
1848- Y - coordinate .
1849- x : int
1850- X - coordinate .
1851- ]
1852- n : int = 1023
1853- Maximal number of characters .
1854- /
1855-
1856- Read a string from the user , with primitive line editing capacity .
1857- [- clinic start generated code ]* /
1846+ PyDoc_STRVAR (_curses_window_getstr__doc__ ,
1847+ "getstr([[y, x,] n=1023])\n"
1848+ "Read a string from the user, with primitive line editing capacity.\n"
1849+ "\n"
1850+ " y\n"
1851+ " Y-coordinate.\n"
1852+ " x\n"
1853+ " X-coordinate.\n"
1854+ " n\n"
1855+ " Maximal number of characters." );
18581856
18591857static PyObject *
1860- PyCursesWindow_GetStr (PyObject * op , PyObject * args )
1858+ PyCursesWindow_getstr (PyObject * op , PyObject * args )
18611859{
18621860 PyCursesWindowObject * self = _PyCursesWindowObject_CAST (op );
1863-
1864- int x , y , n ;
1861+ int use_xy = 0 , y = 0 , x = 0 ;
1862+ unsigned int n = 1023 ;
18651863 char rtn [1024 ]; /* This should be big enough.. I hope */
18661864 int rtn2 ;
18671865
1868- switch (PyTuple_Size (args )) {
1869- case 0 :
1870- Py_BEGIN_ALLOW_THREADS
1871- rtn2 = wgetnstr (self -> win ,rtn , 1023 );
1872- Py_END_ALLOW_THREADS
1873- break ;
1874- case 1 :
1875- if (!PyArg_ParseTuple (args ,"i;n" , & n ))
1876- return NULL ;
1877- if (n < 0 ) {
1878- PyErr_SetString (PyExc_ValueError , "'n' must be nonnegative" );
1879- return NULL ;
1880- }
1881- Py_BEGIN_ALLOW_THREADS
1882- rtn2 = wgetnstr (self -> win , rtn , Py_MIN (n , 1023 ));
1883- Py_END_ALLOW_THREADS
1884- break ;
1885- case 2 :
1886- if (!PyArg_ParseTuple (args ,"ii;y,x" ,& y ,& x ))
1887- return NULL ;
1866+ if (!curses_clinic_parse_optional_xy_n (args , & y , & x , & n , & use_xy ,
1867+ "_curses.window.getstr" ))
1868+ {
1869+ return NULL ;
1870+ }
1871+
1872+ n = Py_MIN (n , 1023 );
1873+ if (use_xy ) {
18881874 Py_BEGIN_ALLOW_THREADS
18891875#ifdef STRICT_SYSV_CURSES
1890- rtn2 = wmove (self -> win ,y ,x )== ERR ? ERR : wgetnstr (self -> win , rtn , 1023 );
1876+ if (wmove (self -> win , y , x ) == ERR ) {
1877+ rtn2 = ERR ;
1878+ }
1879+ else {
1880+ rtn2 = wgetnstr (self -> win , rtn , n );
1881+ }
18911882#else
1892- rtn2 = mvwgetnstr (self -> win ,y , x , rtn , 1023 );
1883+ rtn2 = mvwgetnstr (self -> win , y , x , rtn , n );
18931884#endif
18941885 Py_END_ALLOW_THREADS
1895- break ;
1896- case 3 :
1897- if (!PyArg_ParseTuple (args ,"iii;y,x,n" , & y , & x , & n ))
1898- return NULL ;
1899- if (n < 0 ) {
1900- PyErr_SetString (PyExc_ValueError , "'n' must be nonnegative" );
1901- return NULL ;
1902- }
1903- #ifdef STRICT_SYSV_CURSES
1904- Py_BEGIN_ALLOW_THREADS
1905- rtn2 = wmove (self -> win ,y ,x )== ERR ? ERR :
1906- wgetnstr (self -> win , rtn , Py_MIN (n , 1023 ));
1907- Py_END_ALLOW_THREADS
1908- #else
1886+ }
1887+ else {
19091888 Py_BEGIN_ALLOW_THREADS
1910- rtn2 = mvwgetnstr (self -> win , y , x , rtn , Py_MIN ( n , 1023 ) );
1889+ rtn2 = wgetnstr (self -> win , rtn , n );
19111890 Py_END_ALLOW_THREADS
1912- #endif
1913- break ;
1914- default :
1915- PyErr_SetString (PyExc_TypeError , "getstr requires 0 to 3 arguments" );
1916- return NULL ;
19171891 }
19181892 if (rtn2 == ERR )
19191893 rtn [0 ] = 0 ;
@@ -2877,7 +2851,10 @@ static PyMethodDef PyCursesWindow_methods[] = {
28772851 _CURSES_WINDOW_GET_WCH_METHODDEF
28782852 {"getmaxyx ", PyCursesWindow_getmaxyx , METH_NOARGS },
28792853 {"getparyx ", PyCursesWindow_getparyx , METH_NOARGS },
2880- {"getstr ", PyCursesWindow_GetStr , METH_VARARGS },
2854+ {
2855+ "getstr ", PyCursesWindow_getstr , METH_VARARGS ,
2856+ _curses_window_getstr__doc__
2857+ },
28812858 {"getyx ", PyCursesWindow_getyx , METH_NOARGS },
28822859 _CURSES_WINDOW_HLINE_METHODDEF
28832860 {"idcok ", PyCursesWindow_idcok, METH_VARARGS},
0 commit comments