diff options
Diffstat (limited to 'Modules/_cursesmodule.c')
| -rw-r--r-- | Modules/_cursesmodule.c | 106 |
1 files changed, 27 insertions, 79 deletions
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index 501ec91..896d40d 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -140,6 +140,8 @@ class curses.window "PyCursesWindowObject *" "&PyCursesWindow_Type" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=88c860abdbb50e0c]*/ +#include "clinic/_cursesmodule.c.h" + /* Definition of exception curses.error */ static PyObject *PyCursesError; @@ -228,7 +230,7 @@ PyCurses_ConvertToChtype(PyCursesWindowObject *win, PyObject *obj, chtype *ch) encoding = win->encoding; else encoding = screen_encoding; - bytes = PyUnicode_AsEncodedObject(obj, encoding, NULL); + bytes = PyUnicode_AsEncodedString(obj, encoding, NULL); if (bytes == NULL) return 0; if (PyBytes_GET_SIZE(bytes) == 1) @@ -278,7 +280,7 @@ static int PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj, chtype *ch #ifdef HAVE_NCURSESW - , cchar_t *wch + , wchar_t *wch #endif ) { @@ -296,8 +298,7 @@ PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj, PyUnicode_GET_LENGTH(obj)); return 0; } - memset(wch->chars, 0, sizeof(wch->chars)); - wch->chars[0] = buffer[0]; + *wch = buffer[0]; return 2; #else return PyCurses_ConvertToChtype(win, obj, ch); @@ -350,7 +351,7 @@ PyCurses_ConvertToString(PyCursesWindowObject *win, PyObject *obj, return 2; #else assert (wstr == NULL); - *bytes = PyUnicode_AsEncodedObject(obj, win->encoding, NULL); + *bytes = PyUnicode_AsEncodedString(obj, win->encoding, NULL); if (*bytes == NULL) return 0; return 1; @@ -583,75 +584,10 @@ By default, the character position and attributes are the current settings for the window object. [clinic start generated code]*/ -PyDoc_STRVAR(curses_window_addch__doc__, -"addch([y, x,] ch, [attr])\n" -"Paint character ch at (y, x) with attributes attr.\n" -"\n" -" y\n" -" Y-coordinate.\n" -" x\n" -" X-coordinate.\n" -" ch\n" -" Character to add.\n" -" attr\n" -" Attributes for the character.\n" -"\n" -"Paint character ch at (y, x) with attributes attr,\n" -"overwriting any character previously painted at that location.\n" -"By default, the character position and attributes are the\n" -"current settings for the window object."); - -#define CURSES_WINDOW_ADDCH_METHODDEF \ - {"addch", (PyCFunction)curses_window_addch, METH_VARARGS, curses_window_addch__doc__}, - -static PyObject * -curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y, int x, PyObject *ch, int group_right_1, long attr); - -static PyObject * -curses_window_addch(PyCursesWindowObject *self, PyObject *args) -{ - PyObject *return_value = NULL; - int group_left_1 = 0; - int y = 0; - int x = 0; - PyObject *ch; - int group_right_1 = 0; - long attr = 0; - - switch (PyTuple_GET_SIZE(args)) { - case 1: - if (!PyArg_ParseTuple(args, "O:addch", &ch)) - goto exit; - break; - case 2: - if (!PyArg_ParseTuple(args, "Ol:addch", &ch, &attr)) - goto exit; - group_right_1 = 1; - break; - case 3: - if (!PyArg_ParseTuple(args, "iiO:addch", &y, &x, &ch)) - goto exit; - group_left_1 = 1; - break; - case 4: - if (!PyArg_ParseTuple(args, "iiOl:addch", &y, &x, &ch, &attr)) - goto exit; - group_right_1 = 1; - group_left_1 = 1; - break; - default: - PyErr_SetString(PyExc_TypeError, "curses.window.addch requires 1 to 4 arguments"); - goto exit; - } - return_value = curses_window_addch_impl(self, group_left_1, y, x, ch, group_right_1, attr); - -exit: - return return_value; -} - static PyObject * -curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y, int x, PyObject *ch, int group_right_1, long attr) -/*[clinic end generated code: output=d4b97cc287010c54 input=5a41efb34a2de338]*/ +curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y, + int x, PyObject *ch, int group_right_1, long attr) +/*[clinic end generated code: output=99f7f85078ec06c3 input=5a41efb34a2de338]*/ { PyCursesWindowObject *cwself = (PyCursesWindowObject *)self; int coordinates_group = group_left_1; @@ -660,7 +596,8 @@ curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y, in int type; chtype cch; #ifdef HAVE_NCURSESW - cchar_t wch; + wchar_t wstr[2]; + cchar_t wcval; #endif const char *funcname; @@ -668,14 +605,15 @@ curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y, in attr = A_NORMAL; #ifdef HAVE_NCURSESW - type = PyCurses_ConvertToCchar_t(cwself, ch, &cch, &wch); + type = PyCurses_ConvertToCchar_t(cwself, ch, &cch, wstr); if (type == 2) { funcname = "add_wch"; - wch.attr = attr; + wstr[1] = L'\0'; + setcchar(&wcval, wstr, attr, 0, NULL); if (coordinates_group) - rtn = mvwadd_wch(cwself->win,y,x, &wch); + rtn = mvwadd_wch(cwself->win,y,x, &wcval); else { - rtn = wadd_wch(cwself->win, &wch); + rtn = wadd_wch(cwself->win, &wcval); } } else @@ -2691,7 +2629,7 @@ PyCurses_KeyName(PyObject *self, PyObject *args) } knp = keyname(ch); - return PyBytes_FromString((knp == NULL) ? "" : (char *)knp); + return PyBytes_FromString((knp == NULL) ? "" : knp); } #endif @@ -2945,6 +2883,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 @@ -3347,6 +3292,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 |
