Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-134208: remove dead AC directives for_curses.window.{chgat,getstr,instr}#134325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
picnixz wants to merge4 commits intopython:main
base:main
Choose a base branch
Loading
frompicnixz:fix/curses/better-clinic-134208
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
274 changes: 134 additions & 140 deletionsModules/_cursesmodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1429,32 +1429,27 @@ int py_mvwdelch(WINDOW *w, int y, int x)

/* chgat, added by Fabian Kreutz <fabian.kreutz at gmx.net> */
#ifdef HAVE_CURSES_WCHGAT
/*[-clinic input]
_curses.window.chgat

[
y: int
Y-coordinate.
x: int
X-coordinate.
]

n: int = -1
Number of characters.
PyDoc_STRVAR(_curses_window_chgat__doc__,
"chgat([y, x,] [n=-1,] attr)\n"
"Set the attributes of characters.\n"
"\n"
" y\n"
" Y-coordinate.\n"
" x\n"
" X-coordinate.\n"
" n\n"
" Number of characters.\n"
" attr\n"
" Attributes for characters.\n"
"\n"
"Set the attributes of num characters at the current cursor position, or at\n"
"position (y, x) if supplied. If no value of num is given or num = -1, the\n"
"attribute will be set on all the characters to the end of the line. This\n"
"function does not move the cursor. The changed line will be touched using\n"
"the touchline() method so that the contents will be redisplayed by the next\n"
"window refresh.");

attr: long
Attributes for characters.
/

Set the attributes of characters.

Set the attributes of num characters at the current cursor position, or at
position (y, x) if supplied. If no value of num is given or num = -1, the
attribute will be set on all the characters to the end of the line. This
function does not move the cursor. The changed line will be touched using
the touchline() method so that the contents will be redisplayed by the next
window refresh.
[-clinic start generated code]*/
static PyObject *
PyCursesWindow_ChgAt(PyObject *op, PyObject *args)
{
Expand All@@ -1481,19 +1476,20 @@ PyCursesWindow_ChgAt(PyObject *op, PyObject *args)
attr = lattr;
break;
case 3:
if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr))
if (!PyArg_ParseTuple(args,"iil;y,x,attr", &y, &x, &lattr))
return NULL;
attr = lattr;
use_xy = TRUE;
break;
case 4:
if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr))
if (!PyArg_ParseTuple(args,"iiil;y,x,n,attr", &y, &x, &num, &lattr))
return NULL;
attr = lattr;
use_xy = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments");
PyErr_SetString(PyExc_TypeError,
"_curses.window.chgat requires 1 to 4 arguments");
return NULL;
}

Expand DownExpand Up@@ -1807,80 +1803,91 @@ _curses_window_get_wch_impl(PyCursesWindowObject *self, int group_right_1,
}
#endif

/*[-clinic input]
_curses.window.getstr

[
y: int
Y-coordinate.
x: int
X-coordinate.
]
n: int = 1023
Maximal number of characters.
/
/*
* Helper function for parsing parameters from getstr() and instr().
* This function is necessary because Argument Clinic does not know
* how to handle nested optional groups with default values inside.
*
* Return 1 on success and 0 on failure, similar to PyArg_ParseTuple().
*/
static int
curses_clinic_parse_optional_xy_n(PyObject *args,
int *y, int *x, unsigned int *n, int *use_xy,
const char *qualname)
{
switch (PyTuple_GET_SIZE(args)) {
case 0: {
*use_xy = 0;
return 1;
}
case 1: {
*use_xy = 0;
return PyArg_ParseTuple(args, "O&;n",
_PyLong_UnsignedInt_Converter, n);
}
case 2: {
*use_xy = 1;
return PyArg_ParseTuple(args, "ii;y,x", y, x);
}
case 3: {
*use_xy = 1;
return PyArg_ParseTuple(args, "iiO&;y,x,n", y, x,
_PyLong_UnsignedInt_Converter, n);
}
default: {
*use_xy = 0;
PyErr_Format(PyExc_TypeError, "%s requires 0 to 3 arguments",
qualname);
return 0;
}
}
}

Read a string from the user, with primitive line editing capacity.
[-clinic start generated code]*/
PyDoc_STRVAR(_curses_window_getstr__doc__,
"getstr([[y, x,] n=1023])\n"
"Read a string from the user, with primitive line editing capacity.\n"
"\n"
" y\n"
" Y-coordinate.\n"
" x\n"
" X-coordinate.\n"
" n\n"
" Maximal number of characters.");

static PyObject *
PyCursesWindow_GetStr(PyObject *op, PyObject *args)
PyCursesWindow_getstr(PyObject *op, PyObject *args)
{
PyCursesWindowObject *self = _PyCursesWindowObject_CAST(op);

intx, y, n;
int use_xy = 0, y = 0, x = 0;
unsignedintn = 1023;
char rtn[1024]; /* This should be big enough.. I hope */
int rtn2;

switch (PyTuple_Size(args)) {
case 0:
Py_BEGIN_ALLOW_THREADS
rtn2 = wgetnstr(self->win,rtn, 1023);
Py_END_ALLOW_THREADS
break;
case 1:
if (!PyArg_ParseTuple(args,"i;n", &n))
return NULL;
if (n < 0) {
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
return NULL;
}
Py_BEGIN_ALLOW_THREADS
rtn2 = wgetnstr(self->win, rtn, Py_MIN(n, 1023));
Py_END_ALLOW_THREADS
break;
case 2:
if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
return NULL;
if (!curses_clinic_parse_optional_xy_n(args, &y, &x, &n, &use_xy,
"_curses.window.getstr"))
{
return NULL;
}

n = Py_MIN(n, 1023);
if (use_xy) {
Py_BEGIN_ALLOW_THREADS
#ifdef STRICT_SYSV_CURSES
rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023);
if (wmove(self->win, y, x) == ERR) {
rtn2 = ERR;
}
else {
rtn2 = wgetnstr(self->win, rtn, n);
}
#else
rtn2 = mvwgetnstr(self->win,y,x,rtn,1023);
rtn2 = mvwgetnstr(self->win, y, x,rtn,n);
#endif
Py_END_ALLOW_THREADS
break;
case 3:
if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
return NULL;
if (n < 0) {
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
return NULL;
}
#ifdef STRICT_SYSV_CURSES
Py_BEGIN_ALLOW_THREADS
rtn2 = wmove(self->win,y,x)==ERR ? ERR :
wgetnstr(self->win, rtn, Py_MIN(n, 1023));
Py_END_ALLOW_THREADS
#else
}
else {
Py_BEGIN_ALLOW_THREADS
rtn2 =mvwgetnstr(self->win,y, x,rtn,Py_MIN(n, 1023));
rtn2 =wgetnstr(self->win, rtn,n);
Py_END_ALLOW_THREADS
#endif
break;
default:
PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments");
return NULL;
}
if (rtn2 == ERR)
rtn[0] = 0;
Expand DownExpand Up@@ -2014,66 +2021,44 @@ _curses_window_inch_impl(PyCursesWindowObject *self, int group_right_1,
return rtn;
}

/*[-clinic input]
_curses.window.instr

[
y: int
Y-coordinate.
x: int
X-coordinate.
]
n: int = 1023
Maximal number of characters.
/

Return a string of characters, extracted from the window.
PyDoc_STRVAR(_curses_window_instr__doc__,
"instr([y, x,] n=1023)\n"
"Return a string of characters, extracted from the window.\n"
"\n"
" y\n"
" Y-coordinate.\n"
" x\n"
" X-coordinate.\n"
" n\n"
" Maximal number of characters.\n"
"\n"
"Return a string of characters, extracted from the window starting at the\n"
"current cursor position, or at y, x if specified. Attributes are stripped\n"
"from the characters. If n is specified, instr() returns a string at most\n"
"n characters long (exclusive of the trailing NUL).");

Return a string of characters, extracted from the window starting at the
current cursor position, or at y, x if specified. Attributes are stripped
from the characters. If n is specified, instr() returns a string at most
n characters long (exclusive of the trailing NUL).
[-clinic start generated code]*/
static PyObject *
PyCursesWindow_InStr(PyObject *op, PyObject *args)
PyCursesWindow_instr(PyObject *op, PyObject *args)
{
PyCursesWindowObject *self = _PyCursesWindowObject_CAST(op);

intx, y, n;
int use_xy = 0, y = 0, x = 0;
unsignedintn = 1023;
char rtn[1024]; /* This should be big enough.. I hope */
int rtn2;

switch (PyTuple_Size(args)) {
case 0:
rtn2 = winnstr(self->win,rtn, 1023);
break;
case 1:
if (!PyArg_ParseTuple(args,"i;n", &n))
return NULL;
if (n < 0) {
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
return NULL;
}
rtn2 = winnstr(self->win, rtn, Py_MIN(n, 1023));
break;
case 2:
if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
return NULL;
rtn2 = mvwinnstr(self->win,y,x,rtn,1023);
break;
case 3:
if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
return NULL;
if (n < 0) {
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
return NULL;
}
rtn2 = mvwinnstr(self->win, y, x, rtn, Py_MIN(n,1023));
break;
default:
PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
if (!curses_clinic_parse_optional_xy_n(args, &y, &x, &n, &use_xy,
"_curses.window.instr"))
{
return NULL;
}

n = Py_MIN(n, 1023);
if (use_xy) {
rtn2 = mvwinnstr(self->win, y, x, rtn, n);
}
else {
rtn2 = winnstr(self->win, rtn, n);
}
if (rtn2 == ERR)
rtn[0] = 0;
return PyBytes_FromString(rtn);
Expand DownExpand Up@@ -2818,7 +2803,10 @@ static PyMethodDef PyCursesWindow_methods[] = {
_CURSES_WINDOW_ATTRSET_METHODDEF
_CURSES_WINDOW_BKGD_METHODDEF
#ifdef HAVE_CURSES_WCHGAT
{"chgat", PyCursesWindow_ChgAt, METH_VARARGS},
{
"chgat", PyCursesWindow_ChgAt, METH_VARARGS,
_curses_window_chgat__doc__
},
#endif
_CURSES_WINDOW_BKGDSET_METHODDEF
_CURSES_WINDOW_BORDER_METHODDEF
Expand All@@ -2841,7 +2829,10 @@ static PyMethodDef PyCursesWindow_methods[] = {
_CURSES_WINDOW_GET_WCH_METHODDEF
{"getmaxyx", PyCursesWindow_getmaxyx, METH_NOARGS},
{"getparyx", PyCursesWindow_getparyx, METH_NOARGS},
{"getstr", PyCursesWindow_GetStr, METH_VARARGS},
{
"getstr", PyCursesWindow_getstr, METH_VARARGS,
_curses_window_getstr__doc__
},
{"getyx", PyCursesWindow_getyx, METH_NOARGS},
_CURSES_WINDOW_HLINE_METHODDEF
{"idcok", PyCursesWindow_idcok, METH_VARARGS},
Expand All@@ -2855,7 +2846,10 @@ static PyMethodDef PyCursesWindow_methods[] = {
{"insertln", PyCursesWindow_winsertln, METH_NOARGS},
_CURSES_WINDOW_INSNSTR_METHODDEF
_CURSES_WINDOW_INSSTR_METHODDEF
{"instr", PyCursesWindow_InStr, METH_VARARGS},
{
"instr", PyCursesWindow_instr, METH_VARARGS,
_curses_window_instr__doc__
},
_CURSES_WINDOW_IS_LINETOUCHED_METHODDEF
{"is_wintouched", PyCursesWindow_is_wintouched, METH_NOARGS},
{"keypad", PyCursesWindow_keypad, METH_VARARGS},
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp