LCOV - code coverage report
Current view: top level - Modules - _cursesmodule.c (source / functions) Hit Total Coverage
Test: CPython 3.12 LCOV report [commit 5e6661bce9] Lines: 126 1256 10.0 %
Date: 2023-03-20 08:15:36 Functions: 3 172 1.7 %
Branches: 155 1249 12.4 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  *   This is a curses module for Python.
       3                 :            :  *
       4                 :            :  *   Based on prior work by Lance Ellinghaus and Oliver Andrich
       5                 :            :  *   Version 1.2 of this module: Copyright 1994 by Lance Ellinghouse,
       6                 :            :  *    Cathedral City, California Republic, United States of America.
       7                 :            :  *
       8                 :            :  *   Version 1.5b1, heavily extended for ncurses by Oliver Andrich:
       9                 :            :  *   Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany.
      10                 :            :  *
      11                 :            :  *   Tidied for Python 1.6, and currently maintained by <amk@amk.ca>.
      12                 :            :  *
      13                 :            :  *   Permission is hereby granted, free of charge, to any person obtaining
      14                 :            :  *   a copy of this source file to use, copy, modify, merge, or publish it
      15                 :            :  *   subject to the following conditions:
      16                 :            :  *
      17                 :            :  *   The above copyright notice and this permission notice shall be included
      18                 :            :  *   in all copies or in any new file that contains a substantial portion of
      19                 :            :  *   this file.
      20                 :            :  *
      21                 :            :  *   THE  AUTHOR  MAKES  NO  REPRESENTATIONS ABOUT  THE  SUITABILITY  OF
      22                 :            :  *   THE  SOFTWARE FOR  ANY  PURPOSE.  IT IS  PROVIDED  "AS IS"  WITHOUT
      23                 :            :  *   EXPRESS OR  IMPLIED WARRANTY.  THE AUTHOR DISCLAIMS  ALL WARRANTIES
      24                 :            :  *   WITH  REGARD TO  THIS  SOFTWARE, INCLUDING  ALL IMPLIED  WARRANTIES
      25                 :            :  *   OF   MERCHANTABILITY,  FITNESS   FOR  A   PARTICULAR  PURPOSE   AND
      26                 :            :  *   NON-INFRINGEMENT  OF THIRD  PARTY  RIGHTS. IN  NO  EVENT SHALL  THE
      27                 :            :  *   AUTHOR  BE LIABLE  TO  YOU  OR ANY  OTHER  PARTY  FOR ANY  SPECIAL,
      28                 :            :  *   INDIRECT,  OR  CONSEQUENTIAL  DAMAGES  OR  ANY  DAMAGES  WHATSOEVER
      29                 :            :  *   WHETHER IN AN  ACTION OF CONTRACT, NEGLIGENCE,  STRICT LIABILITY OR
      30                 :            :  *   ANY OTHER  ACTION ARISING OUT OF  OR IN CONNECTION WITH  THE USE OR
      31                 :            :  *   PERFORMANCE OF THIS SOFTWARE.
      32                 :            :  */
      33                 :            : 
      34                 :            : /*
      35                 :            : 
      36                 :            :   A number of SysV or ncurses functions don't have wrappers yet; if you
      37                 :            :   need a given function, add it and send a patch.  See
      38                 :            :   https://www.python.org/dev/patches/ for instructions on how to submit
      39                 :            :   patches to Python.
      40                 :            : 
      41                 :            :   Here's a list of currently unsupported functions:
      42                 :            : 
      43                 :            :   addchnstr addchstr color_set define_key
      44                 :            :   del_curterm delscreen dupwin inchnstr inchstr innstr keyok
      45                 :            :   mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr
      46                 :            :   mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr
      47                 :            :   mvwinchnstr mvwinchstr mvwinnstr newterm
      48                 :            :   restartterm ripoffline scr_dump
      49                 :            :   scr_init scr_restore scr_set scrl set_curterm set_term setterm
      50                 :            :   tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
      51                 :            :   vidattr vidputs waddchnstr waddchstr
      52                 :            :   wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
      53                 :            : 
      54                 :            :   Low-priority:
      55                 :            :   slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
      56                 :            :   slk_attron slk_attrset slk_clear slk_color slk_init slk_label
      57                 :            :   slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
      58                 :            : 
      59                 :            :   Menu extension (ncurses and probably SYSV):
      60                 :            :   current_item free_item free_menu item_count item_description
      61                 :            :   item_index item_init item_name item_opts item_opts_off
      62                 :            :   item_opts_on item_term item_userptr item_value item_visible
      63                 :            :   menu_back menu_driver menu_fore menu_format menu_grey
      64                 :            :   menu_init menu_items menu_mark menu_opts menu_opts_off
      65                 :            :   menu_opts_on menu_pad menu_pattern menu_request_by_name
      66                 :            :   menu_request_name menu_spacing menu_sub menu_term menu_userptr
      67                 :            :   menu_win new_item new_menu pos_menu_cursor post_menu
      68                 :            :   scale_menu set_current_item set_item_init set_item_opts
      69                 :            :   set_item_term set_item_userptr set_item_value set_menu_back
      70                 :            :   set_menu_fore set_menu_format set_menu_grey set_menu_init
      71                 :            :   set_menu_items set_menu_mark set_menu_opts set_menu_pad
      72                 :            :   set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
      73                 :            :   set_menu_userptr set_menu_win set_top_row top_row unpost_menu
      74                 :            : 
      75                 :            :   Form extension (ncurses and probably SYSV):
      76                 :            :   current_field data_ahead data_behind dup_field
      77                 :            :   dynamic_fieldinfo field_arg field_back field_buffer
      78                 :            :   field_count field_fore field_index field_info field_init
      79                 :            :   field_just field_opts field_opts_off field_opts_on field_pad
      80                 :            :   field_status field_term field_type field_userptr form_driver
      81                 :            :   form_fields form_init form_opts form_opts_off form_opts_on
      82                 :            :   form_page form_request_by_name form_request_name form_sub
      83                 :            :   form_term form_userptr form_win free_field free_form
      84                 :            :   link_field link_fieldtype move_field new_field new_form
      85                 :            :   new_page pos_form_cursor post_form scale_form
      86                 :            :   set_current_field set_field_back set_field_buffer
      87                 :            :   set_field_fore set_field_init set_field_just set_field_opts
      88                 :            :   set_field_pad set_field_status set_field_term set_field_type
      89                 :            :   set_field_userptr set_fieldtype_arg set_fieldtype_choice
      90                 :            :   set_form_fields set_form_init set_form_opts set_form_page
      91                 :            :   set_form_sub set_form_term set_form_userptr set_form_win
      92                 :            :   set_max_field set_new_page unpost_form
      93                 :            : 
      94                 :            : 
      95                 :            : */
      96                 :            : 
      97                 :            : /* Release Number */
      98                 :            : 
      99                 :            : static const char PyCursesVersion[] = "2.2";
     100                 :            : 
     101                 :            : /* Includes */
     102                 :            : 
     103                 :            : #ifndef Py_BUILD_CORE_BUILTIN
     104                 :            : #  define Py_BUILD_CORE_MODULE 1
     105                 :            : #endif
     106                 :            : 
     107                 :            : #define PY_SSIZE_T_CLEAN
     108                 :            : 
     109                 :            : #include "Python.h"
     110                 :            : #include "pycore_long.h"          // _PyLong_GetZero()
     111                 :            : #include "pycore_structseq.h"     // _PyStructSequence_NewType()
     112                 :            : 
     113                 :            : #ifdef __hpux
     114                 :            : #define STRICT_SYSV_CURSES
     115                 :            : #endif
     116                 :            : 
     117                 :            : #define CURSES_MODULE
     118                 :            : #include "py_curses.h"
     119                 :            : 
     120                 :            : #if defined(HAVE_TERM_H) || defined(__sgi)
     121                 :            : /* For termname, longname, putp, tigetflag, tigetnum, tigetstr, tparm
     122                 :            :    which are not declared in SysV curses and for setupterm. */
     123                 :            : #include <term.h>
     124                 :            : /* Including <term.h> #defines many common symbols. */
     125                 :            : #undef lines
     126                 :            : #undef columns
     127                 :            : #endif
     128                 :            : 
     129                 :            : #ifdef HAVE_LANGINFO_H
     130                 :            : #include <langinfo.h>
     131                 :            : #endif
     132                 :            : 
     133                 :            : #if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5))
     134                 :            : #define STRICT_SYSV_CURSES       /* Don't use ncurses extensions */
     135                 :            : typedef chtype attr_t;           /* No attr_t type is available */
     136                 :            : #endif
     137                 :            : 
     138                 :            : #if defined(_AIX)
     139                 :            : #define STRICT_SYSV_CURSES
     140                 :            : #endif
     141                 :            : 
     142                 :            : #if NCURSES_EXT_FUNCS+0 >= 20170401 && NCURSES_EXT_COLORS+0 >= 20170401
     143                 :            : #define _NCURSES_EXTENDED_COLOR_FUNCS   1
     144                 :            : #else
     145                 :            : #define _NCURSES_EXTENDED_COLOR_FUNCS   0
     146                 :            : #endif
     147                 :            : 
     148                 :            : #if _NCURSES_EXTENDED_COLOR_FUNCS
     149                 :            : #define _CURSES_COLOR_VAL_TYPE          int
     150                 :            : #define _CURSES_COLOR_NUM_TYPE          int
     151                 :            : #define _CURSES_INIT_COLOR_FUNC         init_extended_color
     152                 :            : #define _CURSES_INIT_PAIR_FUNC          init_extended_pair
     153                 :            : #define _COLOR_CONTENT_FUNC             extended_color_content
     154                 :            : #define _CURSES_PAIR_CONTENT_FUNC       extended_pair_content
     155                 :            : #else
     156                 :            : #define _CURSES_COLOR_VAL_TYPE          short
     157                 :            : #define _CURSES_COLOR_NUM_TYPE          short
     158                 :            : #define _CURSES_INIT_COLOR_FUNC         init_color
     159                 :            : #define _CURSES_INIT_PAIR_FUNC          init_pair
     160                 :            : #define _COLOR_CONTENT_FUNC             color_content
     161                 :            : #define _CURSES_PAIR_CONTENT_FUNC       pair_content
     162                 :            : #endif  /* _NCURSES_EXTENDED_COLOR_FUNCS */
     163                 :            : 
     164                 :            : /*[clinic input]
     165                 :            : module _curses
     166                 :            : class _curses.window "PyCursesWindowObject *" "&PyCursesWindow_Type"
     167                 :            : [clinic start generated code]*/
     168                 :            : /*[clinic end generated code: output=da39a3ee5e6b4b0d input=43265c372c2887d6]*/
     169                 :            : 
     170                 :            : /* Definition of exception curses.error */
     171                 :            : 
     172                 :            : static PyObject *PyCursesError;
     173                 :            : 
     174                 :            : /* Tells whether setupterm() has been called to initialise terminfo.  */
     175                 :            : static int initialised_setupterm = FALSE;
     176                 :            : 
     177                 :            : /* Tells whether initscr() has been called to initialise curses.  */
     178                 :            : static int initialised = FALSE;
     179                 :            : 
     180                 :            : /* Tells whether start_color() has been called to initialise color usage. */
     181                 :            : static int initialisedcolors = FALSE;
     182                 :            : 
     183                 :            : static char *screen_encoding = NULL;
     184                 :            : 
     185                 :            : /* Utility Macros */
     186                 :            : #define PyCursesSetupTermCalled                                         \
     187                 :            :     if (initialised_setupterm != TRUE) {                                \
     188                 :            :         PyErr_SetString(PyCursesError,                                  \
     189                 :            :                         "must call (at least) setupterm() first");      \
     190                 :            :         return 0; }
     191                 :            : 
     192                 :            : #define PyCursesInitialised                             \
     193                 :            :     if (initialised != TRUE) {                          \
     194                 :            :         PyErr_SetString(PyCursesError,                  \
     195                 :            :                         "must call initscr() first");   \
     196                 :            :         return 0; }
     197                 :            : 
     198                 :            : #define PyCursesInitialisedColor                                \
     199                 :            :     if (initialisedcolors != TRUE) {                            \
     200                 :            :         PyErr_SetString(PyCursesError,                          \
     201                 :            :                         "must call start_color() first");       \
     202                 :            :         return 0; }
     203                 :            : 
     204                 :            : /* Utility Functions */
     205                 :            : 
     206                 :            : /*
     207                 :            :  * Check the return code from a curses function and return None
     208                 :            :  * or raise an exception as appropriate.  These are exported using the
     209                 :            :  * capsule API.
     210                 :            :  */
     211                 :            : 
     212                 :            : static PyObject *
     213                 :          0 : PyCursesCheckERR(int code, const char *fname)
     214                 :            : {
     215         [ #  # ]:          0 :     if (code != ERR) {
     216                 :          0 :         Py_RETURN_NONE;
     217                 :            :     } else {
     218         [ #  # ]:          0 :         if (fname == NULL) {
     219                 :          0 :             PyErr_SetString(PyCursesError, catchall_ERR);
     220                 :            :         } else {
     221                 :          0 :             PyErr_Format(PyCursesError, "%s() returned ERR", fname);
     222                 :            :         }
     223                 :          0 :         return NULL;
     224                 :            :     }
     225                 :            : }
     226                 :            : 
     227                 :            : /* Convert an object to a byte (an integer of type chtype):
     228                 :            : 
     229                 :            :    - int
     230                 :            :    - bytes of length 1
     231                 :            :    - str of length 1
     232                 :            : 
     233                 :            :    Return 1 on success, 0 on error (invalid type or integer overflow). */
     234                 :            : static int
     235                 :          0 : PyCurses_ConvertToChtype(PyCursesWindowObject *win, PyObject *obj, chtype *ch)
     236                 :            : {
     237                 :            :     long value;
     238   [ #  #  #  # ]:          0 :     if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) {
     239                 :          0 :         value = (unsigned char)PyBytes_AsString(obj)[0];
     240                 :            :     }
     241         [ #  # ]:          0 :     else if (PyUnicode_Check(obj)) {
     242         [ #  # ]:          0 :         if (PyUnicode_GetLength(obj) != 1) {
     243                 :          0 :             PyErr_Format(PyExc_TypeError,
     244                 :            :                          "expect bytes or str of length 1, or int, "
     245                 :            :                          "got a str of length %zi",
     246                 :            :                          PyUnicode_GET_LENGTH(obj));
     247                 :          0 :             return 0;
     248                 :            :         }
     249                 :          0 :         value = PyUnicode_READ_CHAR(obj, 0);
     250         [ #  # ]:          0 :         if (128 < value) {
     251                 :            :             PyObject *bytes;
     252                 :            :             const char *encoding;
     253         [ #  # ]:          0 :             if (win)
     254                 :          0 :                 encoding = win->encoding;
     255                 :            :             else
     256                 :          0 :                 encoding = screen_encoding;
     257                 :          0 :             bytes = PyUnicode_AsEncodedString(obj, encoding, NULL);
     258         [ #  # ]:          0 :             if (bytes == NULL)
     259                 :          0 :                 return 0;
     260         [ #  # ]:          0 :             if (PyBytes_GET_SIZE(bytes) == 1)
     261                 :          0 :                 value = (unsigned char)PyBytes_AS_STRING(bytes)[0];
     262                 :            :             else
     263                 :          0 :                 value = -1;
     264                 :          0 :             Py_DECREF(bytes);
     265         [ #  # ]:          0 :             if (value < 0)
     266                 :          0 :                 goto overflow;
     267                 :            :         }
     268                 :            :     }
     269         [ #  # ]:          0 :     else if (PyLong_CheckExact(obj)) {
     270                 :            :         int long_overflow;
     271                 :          0 :         value = PyLong_AsLongAndOverflow(obj, &long_overflow);
     272         [ #  # ]:          0 :         if (long_overflow)
     273                 :          0 :             goto overflow;
     274                 :            :     }
     275                 :            :     else {
     276                 :          0 :         PyErr_Format(PyExc_TypeError,
     277                 :            :                      "expect bytes or str of length 1, or int, got %s",
     278                 :          0 :                      Py_TYPE(obj)->tp_name);
     279                 :          0 :         return 0;
     280                 :            :     }
     281                 :          0 :     *ch = (chtype)value;
     282         [ #  # ]:          0 :     if ((long)*ch != value)
     283                 :          0 :         goto overflow;
     284                 :          0 :     return 1;
     285                 :            : 
     286                 :          0 : overflow:
     287                 :          0 :     PyErr_SetString(PyExc_OverflowError,
     288                 :            :                     "byte doesn't fit in chtype");
     289                 :          0 :     return 0;
     290                 :            : }
     291                 :            : 
     292                 :            : /* Convert an object to a byte (chtype) or a character (cchar_t):
     293                 :            : 
     294                 :            :     - int
     295                 :            :     - bytes of length 1
     296                 :            :     - str of length 1
     297                 :            : 
     298                 :            :    Return:
     299                 :            : 
     300                 :            :     - 2 if obj is a character (written into *wch)
     301                 :            :     - 1 if obj is a byte (written into *ch)
     302                 :            :     - 0 on error: raise an exception */
     303                 :            : static int
     304                 :          0 : PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj,
     305                 :            :                           chtype *ch
     306                 :            : #ifdef HAVE_NCURSESW
     307                 :            :                           , wchar_t *wch
     308                 :            : #endif
     309                 :            :                           )
     310                 :            : {
     311                 :            :     long value;
     312                 :            : #ifdef HAVE_NCURSESW
     313                 :            :     wchar_t buffer[2];
     314                 :            : #endif
     315                 :            : 
     316         [ #  # ]:          0 :     if (PyUnicode_Check(obj)) {
     317                 :            : #ifdef HAVE_NCURSESW
     318         [ #  # ]:          0 :         if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) {
     319                 :          0 :             PyErr_Format(PyExc_TypeError,
     320                 :            :                          "expect bytes or str of length 1, or int, "
     321                 :            :                          "got a str of length %zi",
     322                 :            :                          PyUnicode_GET_LENGTH(obj));
     323                 :          0 :             return 0;
     324                 :            :         }
     325                 :          0 :         *wch = buffer[0];
     326                 :          0 :         return 2;
     327                 :            : #else
     328                 :            :         return PyCurses_ConvertToChtype(win, obj, ch);
     329                 :            : #endif
     330                 :            :     }
     331   [ #  #  #  # ]:          0 :     else if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) {
     332                 :          0 :         value = (unsigned char)PyBytes_AsString(obj)[0];
     333                 :            :     }
     334         [ #  # ]:          0 :     else if (PyLong_CheckExact(obj)) {
     335                 :            :         int overflow;
     336                 :          0 :         value = PyLong_AsLongAndOverflow(obj, &overflow);
     337         [ #  # ]:          0 :         if (overflow) {
     338                 :          0 :             PyErr_SetString(PyExc_OverflowError,
     339                 :            :                             "int doesn't fit in long");
     340                 :          0 :             return 0;
     341                 :            :         }
     342                 :            :     }
     343                 :            :     else {
     344                 :          0 :         PyErr_Format(PyExc_TypeError,
     345                 :            :                      "expect bytes or str of length 1, or int, got %s",
     346                 :          0 :                      Py_TYPE(obj)->tp_name);
     347                 :          0 :         return 0;
     348                 :            :     }
     349                 :            : 
     350                 :          0 :     *ch = (chtype)value;
     351         [ #  # ]:          0 :     if ((long)*ch != value) {
     352                 :          0 :         PyErr_Format(PyExc_OverflowError,
     353                 :            :                      "byte doesn't fit in chtype");
     354                 :          0 :         return 0;
     355                 :            :     }
     356                 :          0 :     return 1;
     357                 :            : }
     358                 :            : 
     359                 :            : /* Convert an object to a byte string (char*) or a wide character string
     360                 :            :    (wchar_t*). Return:
     361                 :            : 
     362                 :            :     - 2 if obj is a character string (written into *wch)
     363                 :            :     - 1 if obj is a byte string (written into *bytes)
     364                 :            :     - 0 on error: raise an exception */
     365                 :            : static int
     366                 :          0 : PyCurses_ConvertToString(PyCursesWindowObject *win, PyObject *obj,
     367                 :            :                          PyObject **bytes, wchar_t **wstr)
     368                 :            : {
     369                 :            :     char *str;
     370         [ #  # ]:          0 :     if (PyUnicode_Check(obj)) {
     371                 :            : #ifdef HAVE_NCURSESW
     372                 :            :         assert (wstr != NULL);
     373                 :            : 
     374                 :          0 :         *wstr = PyUnicode_AsWideCharString(obj, NULL);
     375         [ #  # ]:          0 :         if (*wstr == NULL)
     376                 :          0 :             return 0;
     377                 :          0 :         return 2;
     378                 :            : #else
     379                 :            :         assert (wstr == NULL);
     380                 :            :         *bytes = PyUnicode_AsEncodedString(obj, win->encoding, NULL);
     381                 :            :         if (*bytes == NULL)
     382                 :            :             return 0;
     383                 :            :         /* check for embedded null bytes */
     384                 :            :         if (PyBytes_AsStringAndSize(*bytes, &str, NULL) < 0) {
     385                 :            :             Py_CLEAR(*bytes);
     386                 :            :             return 0;
     387                 :            :         }
     388                 :            :         return 1;
     389                 :            : #endif
     390                 :            :     }
     391         [ #  # ]:          0 :     else if (PyBytes_Check(obj)) {
     392                 :          0 :         *bytes = Py_NewRef(obj);
     393                 :            :         /* check for embedded null bytes */
     394         [ #  # ]:          0 :         if (PyBytes_AsStringAndSize(*bytes, &str, NULL) < 0) {
     395                 :          0 :             Py_DECREF(obj);
     396                 :          0 :             return 0;
     397                 :            :         }
     398                 :          0 :         return 1;
     399                 :            :     }
     400                 :            : 
     401                 :          0 :     PyErr_Format(PyExc_TypeError, "expect bytes or str, got %s",
     402                 :          0 :                  Py_TYPE(obj)->tp_name);
     403                 :          0 :     return 0;
     404                 :            : }
     405                 :            : 
     406                 :            : static int
     407                 :          0 : color_allow_default_converter(PyObject *arg, void *ptr)
     408                 :            : {
     409                 :            :     long color_number;
     410                 :            :     int overflow;
     411                 :            : 
     412                 :          0 :     color_number = PyLong_AsLongAndOverflow(arg, &overflow);
     413   [ #  #  #  # ]:          0 :     if (color_number == -1 && PyErr_Occurred())
     414                 :          0 :         return 0;
     415                 :            : 
     416   [ #  #  #  # ]:          0 :     if (overflow > 0 || color_number >= COLORS) {
     417                 :          0 :         PyErr_Format(PyExc_ValueError,
     418                 :            :                      "Color number is greater than COLORS-1 (%d).",
     419                 :            :                      COLORS - 1);
     420                 :          0 :         return 0;
     421                 :            :     }
     422   [ #  #  #  # ]:          0 :     else if (overflow < 0 || color_number < 0) {
     423                 :          0 :         color_number = -1;
     424                 :            :     }
     425                 :            : 
     426                 :          0 :     *(int *)ptr = (int)color_number;
     427                 :          0 :     return 1;
     428                 :            : }
     429                 :            : 
     430                 :            : static int
     431                 :          0 : color_converter(PyObject *arg, void *ptr)
     432                 :            : {
     433         [ #  # ]:          0 :     if (!color_allow_default_converter(arg, ptr)) {
     434                 :          0 :         return 0;
     435                 :            :     }
     436         [ #  # ]:          0 :     if (*(int *)ptr < 0) {
     437                 :          0 :         PyErr_SetString(PyExc_ValueError,
     438                 :            :                         "Color number is less than 0.");
     439                 :          0 :         return 0;
     440                 :            :     }
     441                 :          0 :     return 1;
     442                 :            : }
     443                 :            : 
     444                 :            : /*[python input]
     445                 :            : class color_converter(CConverter):
     446                 :            :     type = 'int'
     447                 :            :     converter = 'color_converter'
     448                 :            : [python start generated code]*/
     449                 :            : /*[python end generated code: output=da39a3ee5e6b4b0d input=4260d2b6e66b3709]*/
     450                 :            : 
     451                 :            : /*[python input]
     452                 :            : class color_allow_default_converter(CConverter):
     453                 :            :     type = 'int'
     454                 :            :     converter = 'color_allow_default_converter'
     455                 :            : [python start generated code]*/
     456                 :            : /*[python end generated code: output=da39a3ee5e6b4b0d input=975602bc058a872d]*/
     457                 :            : 
     458                 :            : static int
     459                 :          0 : pair_converter(PyObject *arg, void *ptr)
     460                 :            : {
     461                 :            :     long pair_number;
     462                 :            :     int overflow;
     463                 :            : 
     464                 :          0 :     pair_number = PyLong_AsLongAndOverflow(arg, &overflow);
     465   [ #  #  #  # ]:          0 :     if (pair_number == -1 && PyErr_Occurred())
     466                 :          0 :         return 0;
     467                 :            : 
     468                 :            : #if _NCURSES_EXTENDED_COLOR_FUNCS
     469   [ #  #  #  # ]:          0 :     if (overflow > 0 || pair_number > INT_MAX) {
     470                 :          0 :         PyErr_Format(PyExc_ValueError,
     471                 :            :                      "Color pair is greater than maximum (%d).",
     472                 :            :                      INT_MAX);
     473                 :          0 :         return 0;
     474                 :            :     }
     475                 :            : #else
     476                 :            :     if (overflow > 0 || pair_number >= COLOR_PAIRS) {
     477                 :            :         PyErr_Format(PyExc_ValueError,
     478                 :            :                      "Color pair is greater than COLOR_PAIRS-1 (%d).",
     479                 :            :                      COLOR_PAIRS - 1);
     480                 :            :         return 0;
     481                 :            :     }
     482                 :            : #endif
     483   [ #  #  #  # ]:          0 :     else if (overflow < 0 || pair_number < 0) {
     484                 :          0 :         PyErr_SetString(PyExc_ValueError,
     485                 :            :                         "Color pair is less than 0.");
     486                 :          0 :         return 0;
     487                 :            :     }
     488                 :            : 
     489                 :          0 :     *(int *)ptr = (int)pair_number;
     490                 :          0 :     return 1;
     491                 :            : }
     492                 :            : 
     493                 :            : /*[python input]
     494                 :            : class pair_converter(CConverter):
     495                 :            :     type = 'int'
     496                 :            :     converter = 'pair_converter'
     497                 :            : [python start generated code]*/
     498                 :            : /*[python end generated code: output=da39a3ee5e6b4b0d input=1a918ae6a1b32af7]*/
     499                 :            : 
     500                 :            : static int
     501                 :          0 : component_converter(PyObject *arg, void *ptr)
     502                 :            : {
     503                 :            :     long component;
     504                 :            :     int overflow;
     505                 :            : 
     506                 :          0 :     component = PyLong_AsLongAndOverflow(arg, &overflow);
     507   [ #  #  #  # ]:          0 :     if (component == -1 && PyErr_Occurred())
     508                 :          0 :         return 0;
     509                 :            : 
     510   [ #  #  #  # ]:          0 :     if (overflow > 0 || component > 1000) {
     511                 :          0 :         PyErr_SetString(PyExc_ValueError,
     512                 :            :                         "Color component is greater than 1000");
     513                 :          0 :         return 0;
     514                 :            :     }
     515   [ #  #  #  # ]:          0 :     else if (overflow < 0 || component < 0) {
     516                 :          0 :         PyErr_SetString(PyExc_ValueError,
     517                 :            :                         "Color component is less than 0");
     518                 :          0 :         return 0;
     519                 :            :     }
     520                 :            : 
     521                 :          0 :     *(short *)ptr = (short)component;
     522                 :          0 :     return 1;
     523                 :            : }
     524                 :            : 
     525                 :            : /*[python input]
     526                 :            : class component_converter(CConverter):
     527                 :            :     type = 'short'
     528                 :            :     converter = 'component_converter'
     529                 :            : [python start generated code]*/
     530                 :            : /*[python end generated code: output=da39a3ee5e6b4b0d input=38e9be01d33927fb]*/
     531                 :            : 
     532                 :            : /* Function versions of the 3 functions for testing whether curses has been
     533                 :            :    initialised or not. */
     534                 :            : 
     535                 :          0 : static int func_PyCursesSetupTermCalled(void)
     536                 :            : {
     537         [ #  # ]:          0 :     PyCursesSetupTermCalled;
     538                 :          0 :     return 1;
     539                 :            : }
     540                 :            : 
     541                 :          0 : static int func_PyCursesInitialised(void)
     542                 :            : {
     543         [ #  # ]:          0 :     PyCursesInitialised;
     544                 :          0 :     return 1;
     545                 :            : }
     546                 :            : 
     547                 :          0 : static int func_PyCursesInitialisedColor(void)
     548                 :            : {
     549         [ #  # ]:          0 :     PyCursesInitialisedColor;
     550                 :          0 :     return 1;
     551                 :            : }
     552                 :            : 
     553                 :            : /*****************************************************************************
     554                 :            :  The Window Object
     555                 :            : ******************************************************************************/
     556                 :            : 
     557                 :            : /* Definition of the window type */
     558                 :            : 
     559                 :            : PyTypeObject PyCursesWindow_Type;
     560                 :            : 
     561                 :            : /* Function prototype macros for Window object
     562                 :            : 
     563                 :            :    X - function name
     564                 :            :    TYPE - parameter Type
     565                 :            :    ERGSTR - format string for construction of the return value
     566                 :            :    PARSESTR - format string for argument parsing
     567                 :            : */
     568                 :            : 
     569                 :            : #define Window_NoArgNoReturnFunction(X)                         \
     570                 :            :     static PyObject *PyCursesWindow_ ## X                       \
     571                 :            :     (PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored))  \
     572                 :            :     { return PyCursesCheckERR(X(self->win), # X); }
     573                 :            : 
     574                 :            : #define Window_NoArgTrueFalseFunction(X)                                \
     575                 :            :     static PyObject * PyCursesWindow_ ## X                              \
     576                 :            :     (PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored))          \
     577                 :            :     {                                                                   \
     578                 :            :         return PyBool_FromLong(X(self->win)); }
     579                 :            : 
     580                 :            : #define Window_NoArgNoReturnVoidFunction(X)                     \
     581                 :            :     static PyObject * PyCursesWindow_ ## X                      \
     582                 :            :     (PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored))  \
     583                 :            :     {                                                           \
     584                 :            :         X(self->win); Py_RETURN_NONE; }
     585                 :            : 
     586                 :            : #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR)               \
     587                 :            :     static PyObject * PyCursesWindow_ ## X                              \
     588                 :            :     (PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored))          \
     589                 :            :     {                                                                   \
     590                 :            :         TYPE arg1, arg2;                                                \
     591                 :            :         X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
     592                 :            : 
     593                 :            : #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR)            \
     594                 :            :     static PyObject * PyCursesWindow_ ## X                              \
     595                 :            :     (PyCursesWindowObject *self, PyObject *args)                        \
     596                 :            :     {                                                                   \
     597                 :            :         TYPE arg1;                                                      \
     598                 :            :         if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL;      \
     599                 :            :         X(self->win,arg1); Py_RETURN_NONE; }
     600                 :            : 
     601                 :            : #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR)                \
     602                 :            :     static PyObject * PyCursesWindow_ ## X                              \
     603                 :            :     (PyCursesWindowObject *self, PyObject *args)                        \
     604                 :            :     {                                                                   \
     605                 :            :         TYPE arg1;                                                      \
     606                 :            :         if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL;       \
     607                 :            :         return PyCursesCheckERR(X(self->win, arg1), # X); }
     608                 :            : 
     609                 :            : #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR)                \
     610                 :            :     static PyObject * PyCursesWindow_ ## X                              \
     611                 :            :     (PyCursesWindowObject *self, PyObject *args)                        \
     612                 :            :     {                                                                   \
     613                 :            :         TYPE arg1, arg2;                                                \
     614                 :            :         if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
     615                 :            :         return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
     616                 :            : 
     617                 :            : /* ------------- WINDOW routines --------------- */
     618                 :            : 
     619         [ #  # ]:          0 : Window_NoArgNoReturnFunction(untouchwin)
     620         [ #  # ]:          0 : Window_NoArgNoReturnFunction(touchwin)
     621         [ #  # ]:          0 : Window_NoArgNoReturnFunction(redrawwin)
     622                 :          0 : Window_NoArgNoReturnFunction(winsertln)
     623                 :          0 : Window_NoArgNoReturnFunction(werase)
     624                 :          0 : Window_NoArgNoReturnFunction(wdeleteln)
     625                 :            : 
     626                 :          0 : Window_NoArgTrueFalseFunction(is_wintouched)
     627                 :            : 
     628                 :          0 : Window_NoArgNoReturnVoidFunction(wsyncup)
     629                 :          0 : Window_NoArgNoReturnVoidFunction(wsyncdown)
     630                 :          0 : Window_NoArgNoReturnVoidFunction(wstandend)
     631                 :          0 : Window_NoArgNoReturnVoidFunction(wstandout)
     632                 :          0 : Window_NoArgNoReturnVoidFunction(wcursyncup)
     633                 :          0 : Window_NoArgNoReturnVoidFunction(wclrtoeol)
     634                 :          0 : Window_NoArgNoReturnVoidFunction(wclrtobot)
     635                 :          0 : Window_NoArgNoReturnVoidFunction(wclear)
     636                 :            : 
     637         [ #  # ]:          0 : Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)")
     638                 :            : #ifdef HAVE_CURSES_IMMEDOK
     639         [ #  # ]:          0 : Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)")
     640                 :            : #endif
     641         [ #  # ]:          0 : Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay")
     642                 :            : 
     643   [ #  #  #  # ]:          0 : Window_NoArg2TupleReturnFunction(getyx, int, "ii")
     644   [ #  #  #  # ]:          0 : Window_NoArg2TupleReturnFunction(getbegyx, int, "ii")
     645   [ #  #  #  # ]:          0 : Window_NoArg2TupleReturnFunction(getmaxyx, int, "ii")
     646   [ #  #  #  # ]:          0 : Window_NoArg2TupleReturnFunction(getparyx, int, "ii")
     647                 :            : 
     648         [ #  # ]:          0 : Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)")
     649         [ #  # ]:          0 : Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)")
     650         [ #  # ]:          0 : Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)")
     651         [ #  # ]:          0 : Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)")
     652         [ #  # ]:          0 : Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)")
     653         [ #  # ]:          0 : Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)")
     654         [ #  # ]:          0 : Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)")
     655         [ #  # ]:          0 : Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines")
     656                 :            : #ifdef HAVE_CURSES_SYNCOK
     657         [ #  # ]:          0 : Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)")
     658                 :            : #endif
     659                 :            : 
     660         [ #  # ]:          0 : Window_TwoArgNoReturnFunction(mvwin, int, "ii;y,x")
     661         [ #  # ]:          0 : Window_TwoArgNoReturnFunction(mvderwin, int, "ii;y,x")
     662         [ #  # ]:          0 : Window_TwoArgNoReturnFunction(wmove, int, "ii;y,x")
     663                 :            : #ifndef STRICT_SYSV_CURSES
     664         [ #  # ]:          0 : Window_TwoArgNoReturnFunction(wresize, int, "ii;lines,columns")
     665                 :            : #endif
     666                 :            : 
     667                 :            : /* Allocation and deallocation of Window Objects */
     668                 :            : 
     669                 :            : static PyObject *
     670                 :          0 : PyCursesWindow_New(WINDOW *win, const char *encoding)
     671                 :            : {
     672                 :            :     PyCursesWindowObject *wo;
     673                 :            : 
     674         [ #  # ]:          0 :     if (encoding == NULL) {
     675                 :            : #if defined(MS_WINDOWS)
     676                 :            :         char *buffer[100];
     677                 :            :         UINT cp;
     678                 :            :         cp = GetConsoleOutputCP();
     679                 :            :         if (cp != 0) {
     680                 :            :             PyOS_snprintf(buffer, sizeof(buffer), "cp%u", cp);
     681                 :            :             encoding = buffer;
     682                 :            :         }
     683                 :            : #elif defined(CODESET)
     684                 :          0 :         const char *codeset = nl_langinfo(CODESET);
     685   [ #  #  #  # ]:          0 :         if (codeset != NULL && codeset[0] != 0)
     686                 :          0 :             encoding = codeset;
     687                 :            : #endif
     688         [ #  # ]:          0 :         if (encoding == NULL)
     689                 :          0 :             encoding = "utf-8";
     690                 :            :     }
     691                 :            : 
     692                 :          0 :     wo = PyObject_New(PyCursesWindowObject, &PyCursesWindow_Type);
     693         [ #  # ]:          0 :     if (wo == NULL) return NULL;
     694                 :          0 :     wo->win = win;
     695                 :          0 :     wo->encoding = _PyMem_Strdup(encoding);
     696         [ #  # ]:          0 :     if (wo->encoding == NULL) {
     697                 :          0 :         Py_DECREF(wo);
     698                 :          0 :         PyErr_NoMemory();
     699                 :          0 :         return NULL;
     700                 :            :     }
     701                 :          0 :     return (PyObject *)wo;
     702                 :            : }
     703                 :            : 
     704                 :            : static void
     705                 :          0 : PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
     706                 :            : {
     707         [ #  # ]:          0 :     if (wo->win != stdscr) delwin(wo->win);
     708         [ #  # ]:          0 :     if (wo->encoding != NULL)
     709                 :          0 :         PyMem_Free(wo->encoding);
     710                 :          0 :     PyObject_Free(wo);
     711                 :          0 : }
     712                 :            : 
     713                 :            : /* Addch, Addstr, Addnstr */
     714                 :            : 
     715                 :            : /*[clinic input]
     716                 :            : _curses.window.addch
     717                 :            : 
     718                 :            :     [
     719                 :            :     y: int
     720                 :            :         Y-coordinate.
     721                 :            :     x: int
     722                 :            :         X-coordinate.
     723                 :            :     ]
     724                 :            : 
     725                 :            :     ch: object
     726                 :            :         Character to add.
     727                 :            : 
     728                 :            :     [
     729                 :            :     attr: long(c_default="A_NORMAL") = _curses.A_NORMAL
     730                 :            :         Attributes for the character.
     731                 :            :     ]
     732                 :            :     /
     733                 :            : 
     734                 :            : Paint the character.
     735                 :            : 
     736                 :            : Paint character ch at (y, x) with attributes attr,
     737                 :            : overwriting any character previously painted at that location.
     738                 :            : By default, the character position and attributes are the
     739                 :            : current settings for the window object.
     740                 :            : [clinic start generated code]*/
     741                 :            : 
     742                 :            : static PyObject *
     743                 :          0 : _curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1,
     744                 :            :                           int y, int x, PyObject *ch, int group_right_1,
     745                 :            :                           long attr)
     746                 :            : /*[clinic end generated code: output=00f4c37af3378f45 input=95ce131578458196]*/
     747                 :            : {
     748                 :          0 :     int coordinates_group = group_left_1;
     749                 :            :     int rtn;
     750                 :            :     int type;
     751                 :          0 :     chtype cch = 0;
     752                 :            : #ifdef HAVE_NCURSESW
     753                 :            :     wchar_t wstr[2];
     754                 :            :     cchar_t wcval;
     755                 :            : #endif
     756                 :            :     const char *funcname;
     757                 :            : 
     758                 :            : #ifdef HAVE_NCURSESW
     759                 :          0 :     type = PyCurses_ConvertToCchar_t(self, ch, &cch, wstr);
     760         [ #  # ]:          0 :     if (type == 2) {
     761                 :          0 :         funcname = "add_wch";
     762                 :          0 :         wstr[1] = L'\0';
     763                 :          0 :         setcchar(&wcval, wstr, attr, PAIR_NUMBER(attr), NULL);
     764         [ #  # ]:          0 :         if (coordinates_group)
     765         [ #  # ]:          0 :             rtn = mvwadd_wch(self->win,y,x, &wcval);
     766                 :            :         else {
     767                 :          0 :             rtn = wadd_wch(self->win, &wcval);
     768                 :            :         }
     769                 :            :     }
     770                 :            :     else
     771                 :            : #else
     772                 :            :     type = PyCurses_ConvertToCchar_t(self, ch, &cch);
     773                 :            : #endif
     774         [ #  # ]:          0 :     if (type == 1) {
     775                 :          0 :         funcname = "addch";
     776         [ #  # ]:          0 :         if (coordinates_group)
     777         [ #  # ]:          0 :             rtn = mvwaddch(self->win,y,x, cch | (attr_t) attr);
     778                 :            :         else {
     779                 :          0 :             rtn = waddch(self->win, cch | (attr_t) attr);
     780                 :            :         }
     781                 :            :     }
     782                 :            :     else {
     783                 :          0 :         return NULL;
     784                 :            :     }
     785                 :          0 :     return PyCursesCheckERR(rtn, funcname);
     786                 :            : }
     787                 :            : 
     788                 :            : /*[clinic input]
     789                 :            : _curses.window.addstr
     790                 :            : 
     791                 :            :     [
     792                 :            :     y: int
     793                 :            :         Y-coordinate.
     794                 :            :     x: int
     795                 :            :         X-coordinate.
     796                 :            :     ]
     797                 :            : 
     798                 :            :     str: object
     799                 :            :         String to add.
     800                 :            : 
     801                 :            :     [
     802                 :            :     attr: long
     803                 :            :         Attributes for characters.
     804                 :            :     ]
     805                 :            :     /
     806                 :            : 
     807                 :            : Paint the string.
     808                 :            : 
     809                 :            : Paint the string str at (y, x) with attributes attr,
     810                 :            : overwriting anything previously on the display.
     811                 :            : By default, the character position and attributes are the
     812                 :            : current settings for the window object.
     813                 :            : [clinic start generated code]*/
     814                 :            : 
     815                 :            : static PyObject *
     816                 :          0 : _curses_window_addstr_impl(PyCursesWindowObject *self, int group_left_1,
     817                 :            :                            int y, int x, PyObject *str, int group_right_1,
     818                 :            :                            long attr)
     819                 :            : /*[clinic end generated code: output=65a928ea85ff3115 input=ff6cbb91448a22a3]*/
     820                 :            : {
     821                 :            :     int rtn;
     822                 :            :     int strtype;
     823                 :          0 :     PyObject *bytesobj = NULL;
     824                 :            : #ifdef HAVE_NCURSESW
     825                 :          0 :     wchar_t *wstr = NULL;
     826                 :            : #endif
     827                 :          0 :     attr_t attr_old = A_NORMAL;
     828                 :          0 :     int use_xy = group_left_1, use_attr = group_right_1;
     829                 :            :     const char *funcname;
     830                 :            : 
     831                 :            : #ifdef HAVE_NCURSESW
     832                 :          0 :     strtype = PyCurses_ConvertToString(self, str, &bytesobj, &wstr);
     833                 :            : #else
     834                 :            :     strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL);
     835                 :            : #endif
     836         [ #  # ]:          0 :     if (strtype == 0) {
     837                 :          0 :         return NULL;
     838                 :            :     }
     839         [ #  # ]:          0 :     if (use_attr) {
     840         [ #  # ]:          0 :         attr_old = getattrs(self->win);
     841                 :          0 :         (void)wattrset(self->win,attr);
     842                 :            :     }
     843                 :            : #ifdef HAVE_NCURSESW
     844         [ #  # ]:          0 :     if (strtype == 2) {
     845                 :          0 :         funcname = "addwstr";
     846         [ #  # ]:          0 :         if (use_xy)
     847         [ #  # ]:          0 :             rtn = mvwaddwstr(self->win,y,x,wstr);
     848                 :            :         else
     849                 :          0 :             rtn = waddwstr(self->win,wstr);
     850                 :          0 :         PyMem_Free(wstr);
     851                 :            :     }
     852                 :            :     else
     853                 :            : #endif
     854                 :            :     {
     855                 :          0 :         const char *str = PyBytes_AS_STRING(bytesobj);
     856                 :          0 :         funcname = "addstr";
     857         [ #  # ]:          0 :         if (use_xy)
     858         [ #  # ]:          0 :             rtn = mvwaddstr(self->win,y,x,str);
     859                 :            :         else
     860                 :          0 :             rtn = waddstr(self->win,str);
     861                 :          0 :         Py_DECREF(bytesobj);
     862                 :            :     }
     863         [ #  # ]:          0 :     if (use_attr)
     864                 :          0 :         (void)wattrset(self->win,attr_old);
     865                 :          0 :     return PyCursesCheckERR(rtn, funcname);
     866                 :            : }
     867                 :            : 
     868                 :            : /*[clinic input]
     869                 :            : _curses.window.addnstr
     870                 :            : 
     871                 :            :     [
     872                 :            :     y: int
     873                 :            :         Y-coordinate.
     874                 :            :     x: int
     875                 :            :         X-coordinate.
     876                 :            :     ]
     877                 :            : 
     878                 :            :     str: object
     879                 :            :         String to add.
     880                 :            : 
     881                 :            :     n: int
     882                 :            :         Maximal number of characters.
     883                 :            : 
     884                 :            :     [
     885                 :            :     attr: long
     886                 :            :         Attributes for characters.
     887                 :            :     ]
     888                 :            :     /
     889                 :            : 
     890                 :            : Paint at most n characters of the string.
     891                 :            : 
     892                 :            : Paint at most n characters of the string str at (y, x) with
     893                 :            : attributes attr, overwriting anything previously on the display.
     894                 :            : By default, the character position and attributes are the
     895                 :            : current settings for the window object.
     896                 :            : [clinic start generated code]*/
     897                 :            : 
     898                 :            : static PyObject *
     899                 :          0 : _curses_window_addnstr_impl(PyCursesWindowObject *self, int group_left_1,
     900                 :            :                             int y, int x, PyObject *str, int n,
     901                 :            :                             int group_right_1, long attr)
     902                 :            : /*[clinic end generated code: output=6d21cee2ce6876d9 input=72718415c2744a2a]*/
     903                 :            : {
     904                 :            :     int rtn;
     905                 :            :     int strtype;
     906                 :          0 :     PyObject *bytesobj = NULL;
     907                 :            : #ifdef HAVE_NCURSESW
     908                 :          0 :     wchar_t *wstr = NULL;
     909                 :            : #endif
     910                 :          0 :     attr_t attr_old = A_NORMAL;
     911                 :          0 :     int use_xy = group_left_1, use_attr = group_right_1;
     912                 :            :     const char *funcname;
     913                 :            : 
     914                 :            : #ifdef HAVE_NCURSESW
     915                 :          0 :     strtype = PyCurses_ConvertToString(self, str, &bytesobj, &wstr);
     916                 :            : #else
     917                 :            :     strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL);
     918                 :            : #endif
     919         [ #  # ]:          0 :     if (strtype == 0)
     920                 :          0 :         return NULL;
     921                 :            : 
     922         [ #  # ]:          0 :     if (use_attr) {
     923         [ #  # ]:          0 :         attr_old = getattrs(self->win);
     924                 :          0 :         (void)wattrset(self->win,attr);
     925                 :            :     }
     926                 :            : #ifdef HAVE_NCURSESW
     927         [ #  # ]:          0 :     if (strtype == 2) {
     928                 :          0 :         funcname = "addnwstr";
     929         [ #  # ]:          0 :         if (use_xy)
     930         [ #  # ]:          0 :             rtn = mvwaddnwstr(self->win,y,x,wstr,n);
     931                 :            :         else
     932                 :          0 :             rtn = waddnwstr(self->win,wstr,n);
     933                 :          0 :         PyMem_Free(wstr);
     934                 :            :     }
     935                 :            :     else
     936                 :            : #endif
     937                 :            :     {
     938                 :          0 :         const char *str = PyBytes_AS_STRING(bytesobj);
     939                 :          0 :         funcname = "addnstr";
     940         [ #  # ]:          0 :         if (use_xy)
     941         [ #  # ]:          0 :             rtn = mvwaddnstr(self->win,y,x,str,n);
     942                 :            :         else
     943                 :          0 :             rtn = waddnstr(self->win,str,n);
     944                 :          0 :         Py_DECREF(bytesobj);
     945                 :            :     }
     946         [ #  # ]:          0 :     if (use_attr)
     947                 :          0 :         (void)wattrset(self->win,attr_old);
     948                 :          0 :     return PyCursesCheckERR(rtn, funcname);
     949                 :            : }
     950                 :            : 
     951                 :            : /*[clinic input]
     952                 :            : _curses.window.bkgd
     953                 :            : 
     954                 :            :     ch: object
     955                 :            :         Background character.
     956                 :            :     attr: long(c_default="A_NORMAL") = _curses.A_NORMAL
     957                 :            :         Background attributes.
     958                 :            :     /
     959                 :            : 
     960                 :            : Set the background property of the window.
     961                 :            : [clinic start generated code]*/
     962                 :            : 
     963                 :            : static PyObject *
     964                 :          0 : _curses_window_bkgd_impl(PyCursesWindowObject *self, PyObject *ch, long attr)
     965                 :            : /*[clinic end generated code: output=058290afb2cf4034 input=634015bcb339283d]*/
     966                 :            : {
     967                 :            :     chtype bkgd;
     968                 :            : 
     969         [ #  # ]:          0 :     if (!PyCurses_ConvertToChtype(self, ch, &bkgd))
     970                 :          0 :         return NULL;
     971                 :            : 
     972                 :          0 :     return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd");
     973                 :            : }
     974                 :            : 
     975                 :            : /*[clinic input]
     976                 :            : _curses.window.attroff
     977                 :            : 
     978                 :            :     attr: long
     979                 :            :     /
     980                 :            : 
     981                 :            : Remove attribute attr from the "background" set.
     982                 :            : [clinic start generated code]*/
     983                 :            : 
     984                 :            : static PyObject *
     985                 :          0 : _curses_window_attroff_impl(PyCursesWindowObject *self, long attr)
     986                 :            : /*[clinic end generated code: output=8a2fcd4df682fc64 input=786beedf06a7befe]*/
     987                 :            : {
     988                 :          0 :     return PyCursesCheckERR(wattroff(self->win, (attr_t)attr), "attroff");
     989                 :            : }
     990                 :            : 
     991                 :            : /*[clinic input]
     992                 :            : _curses.window.attron
     993                 :            : 
     994                 :            :     attr: long
     995                 :            :     /
     996                 :            : 
     997                 :            : Add attribute attr from the "background" set.
     998                 :            : [clinic start generated code]*/
     999                 :            : 
    1000                 :            : static PyObject *
    1001                 :          0 : _curses_window_attron_impl(PyCursesWindowObject *self, long attr)
    1002                 :            : /*[clinic end generated code: output=7afea43b237fa870 input=5a88fba7b1524f32]*/
    1003                 :            : {
    1004                 :          0 :     return PyCursesCheckERR(wattron(self->win, (attr_t)attr), "attron");
    1005                 :            : }
    1006                 :            : 
    1007                 :            : /*[clinic input]
    1008                 :            : _curses.window.attrset
    1009                 :            : 
    1010                 :            :     attr: long
    1011                 :            :     /
    1012                 :            : 
    1013                 :            : Set the "background" set of attributes.
    1014                 :            : [clinic start generated code]*/
    1015                 :            : 
    1016                 :            : static PyObject *
    1017                 :          0 : _curses_window_attrset_impl(PyCursesWindowObject *self, long attr)
    1018                 :            : /*[clinic end generated code: output=84e379bff20c0433 input=42e400c0d0154ab5]*/
    1019                 :            : {
    1020                 :          0 :     return PyCursesCheckERR(wattrset(self->win, (attr_t)attr), "attrset");
    1021                 :            : }
    1022                 :            : 
    1023                 :            : /*[clinic input]
    1024                 :            : _curses.window.bkgdset
    1025                 :            : 
    1026                 :            :     ch: object
    1027                 :            :         Background character.
    1028                 :            :     attr: long(c_default="A_NORMAL") = _curses.A_NORMAL
    1029                 :            :         Background attributes.
    1030                 :            :     /
    1031                 :            : 
    1032                 :            : Set the window's background.
    1033                 :            : [clinic start generated code]*/
    1034                 :            : 
    1035                 :            : static PyObject *
    1036                 :          0 : _curses_window_bkgdset_impl(PyCursesWindowObject *self, PyObject *ch,
    1037                 :            :                             long attr)
    1038                 :            : /*[clinic end generated code: output=8cb994fc4d7e2496 input=e09c682425c9e45b]*/
    1039                 :            : {
    1040                 :            :     chtype bkgd;
    1041                 :            : 
    1042         [ #  # ]:          0 :     if (!PyCurses_ConvertToChtype(self, ch, &bkgd))
    1043                 :          0 :         return NULL;
    1044                 :            : 
    1045                 :          0 :     wbkgdset(self->win, bkgd | attr);
    1046                 :          0 :     return PyCursesCheckERR(0, "bkgdset");
    1047                 :            : }
    1048                 :            : 
    1049                 :            : /*[clinic input]
    1050                 :            : _curses.window.border
    1051                 :            : 
    1052                 :            :     ls: object(c_default="NULL") = _curses.ACS_VLINE
    1053                 :            :         Left side.
    1054                 :            :     rs: object(c_default="NULL") = _curses.ACS_VLINE
    1055                 :            :         Right side.
    1056                 :            :     ts: object(c_default="NULL") = _curses.ACS_HLINE
    1057                 :            :         Top side.
    1058                 :            :     bs: object(c_default="NULL") = _curses.ACS_HLINE
    1059                 :            :         Bottom side.
    1060                 :            :     tl: object(c_default="NULL") = _curses.ACS_ULCORNER
    1061                 :            :         Upper-left corner.
    1062                 :            :     tr: object(c_default="NULL") = _curses.ACS_URCORNER
    1063                 :            :         Upper-right corner.
    1064                 :            :     bl: object(c_default="NULL") = _curses.ACS_LLCORNER
    1065                 :            :         Bottom-left corner.
    1066                 :            :     br: object(c_default="NULL") = _curses.ACS_LRCORNER
    1067                 :            :         Bottom-right corner.
    1068                 :            :     /
    1069                 :            : 
    1070                 :            : Draw a border around the edges of the window.
    1071                 :            : 
    1072                 :            : Each parameter specifies the character to use for a specific part of the
    1073                 :            : border.  The characters can be specified as integers or as one-character
    1074                 :            : strings.  A 0 value for any parameter will cause the default character to be
    1075                 :            : used for that parameter.
    1076                 :            : [clinic start generated code]*/
    1077                 :            : 
    1078                 :            : static PyObject *
    1079                 :          0 : _curses_window_border_impl(PyCursesWindowObject *self, PyObject *ls,
    1080                 :            :                            PyObject *rs, PyObject *ts, PyObject *bs,
    1081                 :            :                            PyObject *tl, PyObject *tr, PyObject *bl,
    1082                 :            :                            PyObject *br)
    1083                 :            : /*[clinic end generated code: output=670ef38d3d7c2aa3 input=e015f735d67a240b]*/
    1084                 :            : {
    1085                 :            :     chtype ch[8];
    1086                 :            :     int i;
    1087                 :            : 
    1088                 :            :     /* Clear the array of parameters */
    1089         [ #  # ]:          0 :     for(i=0; i<8; i++)
    1090                 :          0 :         ch[i] = 0;
    1091                 :            : 
    1092                 :            : #define CONVERTTOCHTYPE(obj, i) \
    1093                 :            :     if ((obj) != NULL && !PyCurses_ConvertToChtype(self, (obj), &ch[(i)])) \
    1094                 :            :         return NULL;
    1095                 :            : 
    1096   [ #  #  #  # ]:          0 :     CONVERTTOCHTYPE(ls, 0);
    1097   [ #  #  #  # ]:          0 :     CONVERTTOCHTYPE(rs, 1);
    1098   [ #  #  #  # ]:          0 :     CONVERTTOCHTYPE(ts, 2);
    1099   [ #  #  #  # ]:          0 :     CONVERTTOCHTYPE(bs, 3);
    1100   [ #  #  #  # ]:          0 :     CONVERTTOCHTYPE(tl, 4);
    1101   [ #  #  #  # ]:          0 :     CONVERTTOCHTYPE(tr, 5);
    1102   [ #  #  #  # ]:          0 :     CONVERTTOCHTYPE(bl, 6);
    1103   [ #  #  #  # ]:          0 :     CONVERTTOCHTYPE(br, 7);
    1104                 :            : 
    1105                 :            : #undef CONVERTTOCHTYPE
    1106                 :            : 
    1107                 :          0 :     wborder(self->win,
    1108                 :            :             ch[0], ch[1], ch[2], ch[3],
    1109                 :            :             ch[4], ch[5], ch[6], ch[7]);
    1110                 :          0 :     Py_RETURN_NONE;
    1111                 :            : }
    1112                 :            : 
    1113                 :            : /*[clinic input]
    1114                 :            : _curses.window.box
    1115                 :            : 
    1116                 :            :     [
    1117                 :            :     verch: object(c_default="_PyLong_GetZero()") = 0
    1118                 :            :         Left and right side.
    1119                 :            :     horch: object(c_default="_PyLong_GetZero()") = 0
    1120                 :            :         Top and bottom side.
    1121                 :            :     ]
    1122                 :            :     /
    1123                 :            : 
    1124                 :            : Draw a border around the edges of the window.
    1125                 :            : 
    1126                 :            : Similar to border(), but both ls and rs are verch and both ts and bs are
    1127                 :            : horch.  The default corner characters are always used by this function.
    1128                 :            : [clinic start generated code]*/
    1129                 :            : 
    1130                 :            : static PyObject *
    1131                 :          0 : _curses_window_box_impl(PyCursesWindowObject *self, int group_right_1,
    1132                 :            :                         PyObject *verch, PyObject *horch)
    1133                 :            : /*[clinic end generated code: output=f3fcb038bb287192 input=f00435f9c8c98f60]*/
    1134                 :            : {
    1135                 :          0 :     chtype ch1 = 0, ch2 = 0;
    1136         [ #  # ]:          0 :     if (group_right_1) {
    1137         [ #  # ]:          0 :         if (!PyCurses_ConvertToChtype(self, verch, &ch1)) {
    1138                 :          0 :             return NULL;
    1139                 :            :         }
    1140         [ #  # ]:          0 :         if (!PyCurses_ConvertToChtype(self, horch, &ch2)) {
    1141                 :          0 :             return NULL;
    1142                 :            :         }
    1143                 :            :     }
    1144                 :          0 :     box(self->win,ch1,ch2);
    1145                 :          0 :     Py_RETURN_NONE;
    1146                 :            : }
    1147                 :            : 
    1148                 :            : #if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)
    1149                 :            : #define py_mvwdelch mvwdelch
    1150                 :            : #else
    1151                 :            : int py_mvwdelch(WINDOW *w, int y, int x)
    1152                 :            : {
    1153                 :            :     mvwdelch(w,y,x);
    1154                 :            :     /* On HP/UX, mvwdelch already returns. On other systems,
    1155                 :            :        we may well run into this return statement. */
    1156                 :            :     return 0;
    1157                 :            : }
    1158                 :            : #endif
    1159                 :            : 
    1160                 :            : #if defined(HAVE_CURSES_IS_PAD)
    1161                 :            : #define py_is_pad(win)      is_pad(win)
    1162                 :            : #elif defined(WINDOW_HAS_FLAGS)
    1163                 :            : #define py_is_pad(win)      ((win) ? ((win)->_flags & _ISPAD) != 0 : FALSE)
    1164                 :            : #endif
    1165                 :            : 
    1166                 :            : /* chgat, added by Fabian Kreutz <fabian.kreutz at gmx.net> */
    1167                 :            : #ifdef HAVE_CURSES_WCHGAT
    1168                 :            : /*[-clinic input]
    1169                 :            : _curses.window.chgat
    1170                 :            : 
    1171                 :            :     [
    1172                 :            :     y: int
    1173                 :            :         Y-coordinate.
    1174                 :            :     x: int
    1175                 :            :         X-coordinate.
    1176                 :            :     ]
    1177                 :            : 
    1178                 :            :     n: int = -1
    1179                 :            :         Number of characters.
    1180                 :            : 
    1181                 :            :     attr: long
    1182                 :            :         Attributes for characters.
    1183                 :            :     /
    1184                 :            : 
    1185                 :            : Set the attributes of characters.
    1186                 :            : 
    1187                 :            : Set the attributes of num characters at the current cursor position, or at
    1188                 :            : position (y, x) if supplied.  If no value of num is given or num = -1, the
    1189                 :            : attribute will be set on all the characters to the end of the line.  This
    1190                 :            : function does not move the cursor.  The changed line will be touched using
    1191                 :            : the touchline() method so that the contents will be redisplayed by the next
    1192                 :            : window refresh.
    1193                 :            : [-clinic start generated code]*/
    1194                 :            : static PyObject *
    1195                 :          0 : PyCursesWindow_ChgAt(PyCursesWindowObject *self, PyObject *args)
    1196                 :            : {
    1197                 :            :     int rtn;
    1198                 :            :     int x, y;
    1199                 :          0 :     int num = -1;
    1200                 :            :     short color;
    1201                 :          0 :     attr_t attr = A_NORMAL;
    1202                 :            :     long lattr;
    1203                 :          0 :     int use_xy = FALSE;
    1204                 :            : 
    1205   [ #  #  #  #  :          0 :     switch (PyTuple_Size(args)) {
                      # ]
    1206                 :          0 :     case 1:
    1207         [ #  # ]:          0 :         if (!PyArg_ParseTuple(args,"l;attr", &lattr))
    1208                 :          0 :             return NULL;
    1209                 :          0 :         attr = lattr;
    1210                 :          0 :         break;
    1211                 :          0 :     case 2:
    1212         [ #  # ]:          0 :         if (!PyArg_ParseTuple(args,"il;n,attr", &num, &lattr))
    1213                 :          0 :             return NULL;
    1214                 :          0 :         attr = lattr;
    1215                 :          0 :         break;
    1216                 :          0 :     case 3:
    1217         [ #  # ]:          0 :         if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr))
    1218                 :          0 :             return NULL;
    1219                 :          0 :         attr = lattr;
    1220                 :          0 :         use_xy = TRUE;
    1221                 :          0 :         break;
    1222                 :          0 :     case 4:
    1223         [ #  # ]:          0 :         if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr))
    1224                 :          0 :             return NULL;
    1225                 :          0 :         attr = lattr;
    1226                 :          0 :         use_xy = TRUE;
    1227                 :          0 :         break;
    1228                 :          0 :     default:
    1229                 :          0 :         PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments");
    1230                 :          0 :         return NULL;
    1231                 :            :     }
    1232                 :            : 
    1233                 :          0 :     color = (short) PAIR_NUMBER(attr);
    1234                 :          0 :     attr = attr & A_ATTRIBUTES;
    1235                 :            : 
    1236         [ #  # ]:          0 :     if (use_xy) {
    1237         [ #  # ]:          0 :         rtn = mvwchgat(self->win,y,x,num,attr,color,NULL);
    1238                 :          0 :         touchline(self->win,y,1);
    1239                 :            :     } else {
    1240   [ #  #  #  # ]:          0 :         getyx(self->win,y,x);
    1241                 :          0 :         rtn = wchgat(self->win,num,attr,color,NULL);
    1242                 :          0 :         touchline(self->win,y,1);
    1243                 :            :     }
    1244                 :          0 :     return PyCursesCheckERR(rtn, "chgat");
    1245                 :            : }
    1246                 :            : #endif
    1247                 :            : 
    1248                 :            : /*[clinic input]
    1249                 :            : _curses.window.delch
    1250                 :            : 
    1251                 :            :     [
    1252                 :            :     y: int
    1253                 :            :         Y-coordinate.
    1254                 :            :     x: int
    1255                 :            :         X-coordinate.
    1256                 :            :     ]
    1257                 :            :     /
    1258                 :            : 
    1259                 :            : Delete any character at (y, x).
    1260                 :            : [clinic start generated code]*/
    1261                 :            : 
    1262                 :            : static PyObject *
    1263                 :          0 : _curses_window_delch_impl(PyCursesWindowObject *self, int group_right_1,
    1264                 :            :                           int y, int x)
    1265                 :            : /*[clinic end generated code: output=22e77bb9fa11b461 input=d2f79e630a4fc6d0]*/
    1266                 :            : {
    1267         [ #  # ]:          0 :     if (!group_right_1) {
    1268                 :          0 :         return PyCursesCheckERR(wdelch(self->win), "wdelch");
    1269                 :            :     }
    1270                 :            :     else {
    1271         [ #  # ]:          0 :         return PyCursesCheckERR(py_mvwdelch(self->win, y, x), "mvwdelch");
    1272                 :            :     }
    1273                 :            : }
    1274                 :            : 
    1275                 :            : /*[clinic input]
    1276                 :            : _curses.window.derwin
    1277                 :            : 
    1278                 :            :     [
    1279                 :            :     nlines: int = 0
    1280                 :            :         Height.
    1281                 :            :     ncols: int = 0
    1282                 :            :         Width.
    1283                 :            :     ]
    1284                 :            :     begin_y: int
    1285                 :            :         Top side y-coordinate.
    1286                 :            :     begin_x: int
    1287                 :            :         Left side x-coordinate.
    1288                 :            :     /
    1289                 :            : 
    1290                 :            : Create a sub-window (window-relative coordinates).
    1291                 :            : 
    1292                 :            : derwin() is the same as calling subwin(), except that begin_y and begin_x
    1293                 :            : are relative to the origin of the window, rather than relative to the entire
    1294                 :            : screen.
    1295                 :            : [clinic start generated code]*/
    1296                 :            : 
    1297                 :            : static PyObject *
    1298                 :          0 : _curses_window_derwin_impl(PyCursesWindowObject *self, int group_left_1,
    1299                 :            :                            int nlines, int ncols, int begin_y, int begin_x)
    1300                 :            : /*[clinic end generated code: output=7924b112d9f70d6e input=966d9481f7f5022e]*/
    1301                 :            : {
    1302                 :            :     WINDOW *win;
    1303                 :            : 
    1304                 :          0 :     win = derwin(self->win,nlines,ncols,begin_y,begin_x);
    1305                 :            : 
    1306         [ #  # ]:          0 :     if (win == NULL) {
    1307                 :          0 :         PyErr_SetString(PyCursesError, catchall_NULL);
    1308                 :          0 :         return NULL;
    1309                 :            :     }
    1310                 :            : 
    1311                 :          0 :     return (PyObject *)PyCursesWindow_New(win, NULL);
    1312                 :            : }
    1313                 :            : 
    1314                 :            : /*[clinic input]
    1315                 :            : _curses.window.echochar
    1316                 :            : 
    1317                 :            :     ch: object
    1318                 :            :         Character to add.
    1319                 :            : 
    1320                 :            :     attr: long(c_default="A_NORMAL") = _curses.A_NORMAL
    1321                 :            :         Attributes for the character.
    1322                 :            :     /
    1323                 :            : 
    1324                 :            : Add character ch with attribute attr, and refresh.
    1325                 :            : [clinic start generated code]*/
    1326                 :            : 
    1327                 :            : static PyObject *
    1328                 :          0 : _curses_window_echochar_impl(PyCursesWindowObject *self, PyObject *ch,
    1329                 :            :                              long attr)
    1330                 :            : /*[clinic end generated code: output=13e7dd875d4b9642 input=e7f34b964e92b156]*/
    1331                 :            : {
    1332                 :            :     chtype ch_;
    1333                 :            : 
    1334         [ #  # ]:          0 :     if (!PyCurses_ConvertToChtype(self, ch, &ch_))
    1335                 :          0 :         return NULL;
    1336                 :            : 
    1337                 :            : #ifdef py_is_pad
    1338   [ #  #  #  # ]:          0 :     if (py_is_pad(self->win)) {
    1339                 :          0 :         return PyCursesCheckERR(pechochar(self->win, ch_ | (attr_t)attr),
    1340                 :            :                                 "echochar");
    1341                 :            :     }
    1342                 :            :     else
    1343                 :            : #endif
    1344                 :          0 :         return PyCursesCheckERR(wechochar(self->win, ch_ | (attr_t)attr),
    1345                 :            :                                 "echochar");
    1346                 :            : }
    1347                 :            : 
    1348                 :            : #ifdef NCURSES_MOUSE_VERSION
    1349                 :            : /*[clinic input]
    1350                 :            : _curses.window.enclose
    1351                 :            : 
    1352                 :            :     y: int
    1353                 :            :         Y-coordinate.
    1354                 :            :     x: int
    1355                 :            :         X-coordinate.
    1356                 :            :     /
    1357                 :            : 
    1358                 :            : Return True if the screen-relative coordinates are enclosed by the window.
    1359                 :            : [clinic start generated code]*/
    1360                 :            : 
    1361                 :            : static PyObject *
    1362                 :          0 : _curses_window_enclose_impl(PyCursesWindowObject *self, int y, int x)
    1363                 :            : /*[clinic end generated code: output=8679beef50502648 input=4fd3355d723f7bc9]*/
    1364                 :            : {
    1365                 :          0 :     return PyBool_FromLong(wenclose(self->win, y, x));
    1366                 :            : }
    1367                 :            : #endif
    1368                 :            : 
    1369                 :            : /*[clinic input]
    1370                 :            : _curses.window.getbkgd -> long
    1371                 :            : 
    1372                 :            : Return the window's current background character/attribute pair.
    1373                 :            : [clinic start generated code]*/
    1374                 :            : 
    1375                 :            : static long
    1376                 :          0 : _curses_window_getbkgd_impl(PyCursesWindowObject *self)
    1377                 :            : /*[clinic end generated code: output=c52b25dc16b215c3 input=a69db882fa35426c]*/
    1378                 :            : {
    1379         [ #  # ]:          0 :     return (long) getbkgd(self->win);
    1380                 :            : }
    1381                 :            : 
    1382                 :            : /*[clinic input]
    1383                 :            : _curses.window.getch -> int
    1384                 :            : 
    1385                 :            :     [
    1386                 :            :     y: int
    1387                 :            :         Y-coordinate.
    1388                 :            :     x: int
    1389                 :            :         X-coordinate.
    1390                 :            :     ]
    1391                 :            :     /
    1392                 :            : 
    1393                 :            : Get a character code from terminal keyboard.
    1394                 :            : 
    1395                 :            : The integer returned does not have to be in ASCII range: function keys,
    1396                 :            : keypad keys and so on return numbers higher than 256.  In no-delay mode, -1
    1397                 :            : is returned if there is no input, else getch() waits until a key is pressed.
    1398                 :            : [clinic start generated code]*/
    1399                 :            : 
    1400                 :            : static int
    1401                 :          0 : _curses_window_getch_impl(PyCursesWindowObject *self, int group_right_1,
    1402                 :            :                           int y, int x)
    1403                 :            : /*[clinic end generated code: output=980aa6af0c0ca387 input=bb24ebfb379f991f]*/
    1404                 :            : {
    1405                 :            :     int rtn;
    1406                 :            : 
    1407                 :          0 :     Py_BEGIN_ALLOW_THREADS
    1408         [ #  # ]:          0 :     if (!group_right_1) {
    1409                 :          0 :         rtn = wgetch(self->win);
    1410                 :            :     }
    1411                 :            :     else {
    1412         [ #  # ]:          0 :         rtn = mvwgetch(self->win, y, x);
    1413                 :            :     }
    1414                 :          0 :     Py_END_ALLOW_THREADS
    1415                 :            : 
    1416                 :          0 :     return rtn;
    1417                 :            : }
    1418                 :            : 
    1419                 :            : /*[clinic input]
    1420                 :            : _curses.window.getkey
    1421                 :            : 
    1422                 :            :     [
    1423                 :            :     y: int
    1424                 :            :         Y-coordinate.
    1425                 :            :     x: int
    1426                 :            :         X-coordinate.
    1427                 :            :     ]
    1428                 :            :     /
    1429                 :            : 
    1430                 :            : Get a character (string) from terminal keyboard.
    1431                 :            : 
    1432                 :            : Returning a string instead of an integer, as getch() does.  Function keys,
    1433                 :            : keypad keys and other special keys return a multibyte string containing the
    1434                 :            : key name.  In no-delay mode, an exception is raised if there is no input.
    1435                 :            : [clinic start generated code]*/
    1436                 :            : 
    1437                 :            : static PyObject *
    1438                 :          0 : _curses_window_getkey_impl(PyCursesWindowObject *self, int group_right_1,
    1439                 :            :                            int y, int x)
    1440                 :            : /*[clinic end generated code: output=8490a182db46b10f input=be2dee34f5cf57f8]*/
    1441                 :            : {
    1442                 :            :     int rtn;
    1443                 :            : 
    1444                 :          0 :     Py_BEGIN_ALLOW_THREADS
    1445         [ #  # ]:          0 :     if (!group_right_1) {
    1446                 :          0 :         rtn = wgetch(self->win);
    1447                 :            :     }
    1448                 :            :     else {
    1449         [ #  # ]:          0 :         rtn = mvwgetch(self->win, y, x);
    1450                 :            :     }
    1451                 :          0 :     Py_END_ALLOW_THREADS
    1452                 :            : 
    1453         [ #  # ]:          0 :     if (rtn == ERR) {
    1454                 :            :         /* getch() returns ERR in nodelay mode */
    1455                 :          0 :         PyErr_CheckSignals();
    1456         [ #  # ]:          0 :         if (!PyErr_Occurred())
    1457                 :          0 :             PyErr_SetString(PyCursesError, "no input");
    1458                 :          0 :         return NULL;
    1459         [ #  # ]:          0 :     } else if (rtn <= 255) {
    1460                 :            : #ifdef NCURSES_VERSION_MAJOR
    1461                 :            : #if NCURSES_VERSION_MAJOR*100+NCURSES_VERSION_MINOR <= 507
    1462                 :            :         /* Work around a bug in ncurses 5.7 and earlier */
    1463                 :            :         if (rtn < 0) {
    1464                 :            :             rtn += 256;
    1465                 :            :         }
    1466                 :            : #endif
    1467                 :            : #endif
    1468                 :          0 :         return PyUnicode_FromOrdinal(rtn);
    1469                 :            :     } else {
    1470                 :          0 :         const char *knp = keyname(rtn);
    1471         [ #  # ]:          0 :         return PyUnicode_FromString((knp == NULL) ? "" : knp);
    1472                 :            :     }
    1473                 :            : }
    1474                 :            : 
    1475                 :            : #ifdef HAVE_NCURSESW
    1476                 :            : /*[clinic input]
    1477                 :            : _curses.window.get_wch
    1478                 :            : 
    1479                 :            :     [
    1480                 :            :     y: int
    1481                 :            :         Y-coordinate.
    1482                 :            :     x: int
    1483                 :            :         X-coordinate.
    1484                 :            :     ]
    1485                 :            :     /
    1486                 :            : 
    1487                 :            : Get a wide character from terminal keyboard.
    1488                 :            : 
    1489                 :            : Return a character for most keys, or an integer for function keys,
    1490                 :            : keypad keys, and other special keys.
    1491                 :            : [clinic start generated code]*/
    1492                 :            : 
    1493                 :            : static PyObject *
    1494                 :          0 : _curses_window_get_wch_impl(PyCursesWindowObject *self, int group_right_1,
    1495                 :            :                             int y, int x)
    1496                 :            : /*[clinic end generated code: output=9f4f86e91fe50ef3 input=dd7e5367fb49dc48]*/
    1497                 :            : {
    1498                 :            :     int ct;
    1499                 :            :     wint_t rtn;
    1500                 :            : 
    1501                 :          0 :     Py_BEGIN_ALLOW_THREADS
    1502         [ #  # ]:          0 :     if (!group_right_1) {
    1503                 :          0 :         ct = wget_wch(self->win ,&rtn);
    1504                 :            :     }
    1505                 :            :     else {
    1506         [ #  # ]:          0 :         ct = mvwget_wch(self->win, y, x, &rtn);
    1507                 :            :     }
    1508                 :          0 :     Py_END_ALLOW_THREADS
    1509                 :            : 
    1510         [ #  # ]:          0 :     if (ct == ERR) {
    1511         [ #  # ]:          0 :         if (PyErr_CheckSignals())
    1512                 :          0 :             return NULL;
    1513                 :            : 
    1514                 :            :         /* get_wch() returns ERR in nodelay mode */
    1515                 :          0 :         PyErr_SetString(PyCursesError, "no input");
    1516                 :          0 :         return NULL;
    1517                 :            :     }
    1518         [ #  # ]:          0 :     if (ct == KEY_CODE_YES)
    1519                 :          0 :         return PyLong_FromLong(rtn);
    1520                 :            :     else
    1521                 :          0 :         return PyUnicode_FromOrdinal(rtn);
    1522                 :            : }
    1523                 :            : #endif
    1524                 :            : 
    1525                 :            : /*[-clinic input]
    1526                 :            : _curses.window.getstr
    1527                 :            : 
    1528                 :            :     [
    1529                 :            :     y: int
    1530                 :            :         Y-coordinate.
    1531                 :            :     x: int
    1532                 :            :         X-coordinate.
    1533                 :            :     ]
    1534                 :            :     n: int = 1023
    1535                 :            :         Maximal number of characters.
    1536                 :            :     /
    1537                 :            : 
    1538                 :            : Read a string from the user, with primitive line editing capacity.
    1539                 :            : [-clinic start generated code]*/
    1540                 :            : 
    1541                 :            : static PyObject *
    1542                 :          0 : PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
    1543                 :            : {
    1544                 :            :     int x, y, n;
    1545                 :            :     char rtn[1024]; /* This should be big enough.. I hope */
    1546                 :            :     int rtn2;
    1547                 :            : 
    1548   [ #  #  #  #  :          0 :     switch (PyTuple_Size(args)) {
                      # ]
    1549                 :          0 :     case 0:
    1550                 :          0 :         Py_BEGIN_ALLOW_THREADS
    1551                 :          0 :         rtn2 = wgetnstr(self->win,rtn, 1023);
    1552                 :          0 :         Py_END_ALLOW_THREADS
    1553                 :          0 :         break;
    1554                 :          0 :     case 1:
    1555         [ #  # ]:          0 :         if (!PyArg_ParseTuple(args,"i;n", &n))
    1556                 :          0 :             return NULL;
    1557         [ #  # ]:          0 :         if (n < 0) {
    1558                 :          0 :             PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
    1559                 :          0 :             return NULL;
    1560                 :            :         }
    1561                 :          0 :         Py_BEGIN_ALLOW_THREADS
    1562                 :          0 :         rtn2 = wgetnstr(self->win, rtn, Py_MIN(n, 1023));
    1563                 :          0 :         Py_END_ALLOW_THREADS
    1564                 :          0 :         break;
    1565                 :          0 :     case 2:
    1566         [ #  # ]:          0 :         if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
    1567                 :          0 :             return NULL;
    1568                 :          0 :         Py_BEGIN_ALLOW_THREADS
    1569                 :            : #ifdef STRICT_SYSV_CURSES
    1570                 :            :         rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023);
    1571                 :            : #else
    1572         [ #  # ]:          0 :         rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023);
    1573                 :            : #endif
    1574                 :          0 :         Py_END_ALLOW_THREADS
    1575                 :          0 :         break;
    1576                 :          0 :     case 3:
    1577         [ #  # ]:          0 :         if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
    1578                 :          0 :             return NULL;
    1579         [ #  # ]:          0 :         if (n < 0) {
    1580                 :          0 :             PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
    1581                 :          0 :             return NULL;
    1582                 :            :         }
    1583                 :            : #ifdef STRICT_SYSV_CURSES
    1584                 :            :         Py_BEGIN_ALLOW_THREADS
    1585                 :            :         rtn2 = wmove(self->win,y,x)==ERR ? ERR :
    1586                 :            :         wgetnstr(self->win, rtn, Py_MIN(n, 1023));
    1587                 :            :         Py_END_ALLOW_THREADS
    1588                 :            : #else
    1589                 :          0 :         Py_BEGIN_ALLOW_THREADS
    1590         [ #  # ]:          0 :         rtn2 = mvwgetnstr(self->win, y, x, rtn, Py_MIN(n, 1023));
    1591                 :          0 :         Py_END_ALLOW_THREADS
    1592                 :            : #endif
    1593                 :          0 :         break;
    1594                 :          0 :     default:
    1595                 :          0 :         PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments");
    1596                 :          0 :         return NULL;
    1597                 :            :     }
    1598         [ #  # ]:          0 :     if (rtn2 == ERR)
    1599                 :          0 :         rtn[0] = 0;
    1600                 :          0 :     return PyBytes_FromString(rtn);
    1601                 :            : }
    1602                 :            : 
    1603                 :            : /*[clinic input]
    1604                 :            : _curses.window.hline
    1605                 :            : 
    1606                 :            :     [
    1607                 :            :     y: int
    1608                 :            :         Starting Y-coordinate.
    1609                 :            :     x: int
    1610                 :            :         Starting X-coordinate.
    1611                 :            :     ]
    1612                 :            : 
    1613                 :            :     ch: object
    1614                 :            :         Character to draw.
    1615                 :            :     n: int
    1616                 :            :         Line length.
    1617                 :            : 
    1618                 :            :     [
    1619                 :            :     attr: long(c_default="A_NORMAL") = _curses.A_NORMAL
    1620                 :            :         Attributes for the characters.
    1621                 :            :     ]
    1622                 :            :     /
    1623                 :            : 
    1624                 :            : Display a horizontal line.
    1625                 :            : [clinic start generated code]*/
    1626                 :            : 
    1627                 :            : static PyObject *
    1628                 :          0 : _curses_window_hline_impl(PyCursesWindowObject *self, int group_left_1,
    1629                 :            :                           int y, int x, PyObject *ch, int n,
    1630                 :            :                           int group_right_1, long attr)
    1631                 :            : /*[clinic end generated code: output=c00d489d61fc9eef input=81a4dea47268163e]*/
    1632                 :            : {
    1633                 :            :     chtype ch_;
    1634                 :            : 
    1635         [ #  # ]:          0 :     if (!PyCurses_ConvertToChtype(self, ch, &ch_))
    1636                 :          0 :         return NULL;
    1637         [ #  # ]:          0 :     if (group_left_1) {
    1638         [ #  # ]:          0 :         if (wmove(self->win, y, x) == ERR) {
    1639                 :          0 :             return PyCursesCheckERR(ERR, "wmove");
    1640                 :            :         }
    1641                 :            :     }
    1642                 :          0 :     return PyCursesCheckERR(whline(self->win, ch_ | (attr_t)attr, n), "hline");
    1643                 :            : }
    1644                 :            : 
    1645                 :            : /*[clinic input]
    1646                 :            : _curses.window.insch
    1647                 :            : 
    1648                 :            :     [
    1649                 :            :     y: int
    1650                 :            :         Y-coordinate.
    1651                 :            :     x: int
    1652                 :            :         X-coordinate.
    1653                 :            :     ]
    1654                 :            : 
    1655                 :            :     ch: object
    1656                 :            :         Character to insert.
    1657                 :            : 
    1658                 :            :     [
    1659                 :            :     attr: long(c_default="A_NORMAL") = _curses.A_NORMAL
    1660                 :            :         Attributes for the character.
    1661                 :            :     ]
    1662                 :            :     /
    1663                 :            : 
    1664                 :            : Insert a character before the current or specified position.
    1665                 :            : 
    1666                 :            : All characters to the right of the cursor are shifted one position right, with
    1667                 :            : the rightmost characters on the line being lost.
    1668                 :            : [clinic start generated code]*/
    1669                 :            : 
    1670                 :            : static PyObject *
    1671                 :          0 : _curses_window_insch_impl(PyCursesWindowObject *self, int group_left_1,
    1672                 :            :                           int y, int x, PyObject *ch, int group_right_1,
    1673                 :            :                           long attr)
    1674                 :            : /*[clinic end generated code: output=ade8cfe3a3bf3e34 input=336342756ee19812]*/
    1675                 :            : {
    1676                 :            :     int rtn;
    1677                 :          0 :     chtype ch_ = 0;
    1678                 :            : 
    1679         [ #  # ]:          0 :     if (!PyCurses_ConvertToChtype(self, ch, &ch_))
    1680                 :          0 :         return NULL;
    1681                 :            : 
    1682         [ #  # ]:          0 :     if (!group_left_1) {
    1683                 :          0 :         rtn = winsch(self->win, ch_ | (attr_t)attr);
    1684                 :            :     }
    1685                 :            :     else {
    1686         [ #  # ]:          0 :         rtn = mvwinsch(self->win, y, x, ch_ | (attr_t)attr);
    1687                 :            :     }
    1688                 :            : 
    1689                 :          0 :     return PyCursesCheckERR(rtn, "insch");
    1690                 :            : }
    1691                 :            : 
    1692                 :            : /*[clinic input]
    1693                 :            : _curses.window.inch -> unsigned_long
    1694                 :            : 
    1695                 :            :     [
    1696                 :            :     y: int
    1697                 :            :         Y-coordinate.
    1698                 :            :     x: int
    1699                 :            :         X-coordinate.
    1700                 :            :     ]
    1701                 :            :     /
    1702                 :            : 
    1703                 :            : Return the character at the given position in the window.
    1704                 :            : 
    1705                 :            : The bottom 8 bits are the character proper, and upper bits are the attributes.
    1706                 :            : [clinic start generated code]*/
    1707                 :            : 
    1708                 :            : static unsigned long
    1709                 :          0 : _curses_window_inch_impl(PyCursesWindowObject *self, int group_right_1,
    1710                 :            :                          int y, int x)
    1711                 :            : /*[clinic end generated code: output=6c4719fe978fe86a input=fac23ee11e3b3a66]*/
    1712                 :            : {
    1713                 :            :     unsigned long rtn;
    1714                 :            : 
    1715         [ #  # ]:          0 :     if (!group_right_1) {
    1716                 :          0 :         rtn = winch(self->win);
    1717                 :            :     }
    1718                 :            :     else {
    1719         [ #  # ]:          0 :         rtn = mvwinch(self->win, y, x);
    1720                 :            :     }
    1721                 :            : 
    1722                 :          0 :     return rtn;
    1723                 :            : }
    1724                 :            : 
    1725                 :            : /*[-clinic input]
    1726                 :            : _curses.window.instr
    1727                 :            : 
    1728                 :            :     [
    1729                 :            :     y: int
    1730                 :            :         Y-coordinate.
    1731                 :            :     x: int
    1732                 :            :         X-coordinate.
    1733                 :            :     ]
    1734                 :            :     n: int = 1023
    1735                 :            :         Maximal number of characters.
    1736                 :            :     /
    1737                 :            : 
    1738                 :            : Return a string of characters, extracted from the window.
    1739                 :            : 
    1740                 :            : Return a string of characters, extracted from the window starting at the
    1741                 :            : current cursor position, or at y, x if specified.  Attributes are stripped
    1742                 :            : from the characters.  If n is specified, instr() returns a string at most
    1743                 :            : n characters long (exclusive of the trailing NUL).
    1744                 :            : [-clinic start generated code]*/
    1745                 :            : static PyObject *
    1746                 :          0 : PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
    1747                 :            : {
    1748                 :            :     int x, y, n;
    1749                 :            :     char rtn[1024]; /* This should be big enough.. I hope */
    1750                 :            :     int rtn2;
    1751                 :            : 
    1752   [ #  #  #  #  :          0 :     switch (PyTuple_Size(args)) {
                      # ]
    1753                 :          0 :     case 0:
    1754                 :          0 :         rtn2 = winnstr(self->win,rtn, 1023);
    1755                 :          0 :         break;
    1756                 :          0 :     case 1:
    1757         [ #  # ]:          0 :         if (!PyArg_ParseTuple(args,"i;n", &n))
    1758                 :          0 :             return NULL;
    1759         [ #  # ]:          0 :         if (n < 0) {
    1760                 :          0 :             PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
    1761                 :          0 :             return NULL;
    1762                 :            :         }
    1763                 :          0 :         rtn2 = winnstr(self->win, rtn, Py_MIN(n, 1023));
    1764                 :          0 :         break;
    1765                 :          0 :     case 2:
    1766         [ #  # ]:          0 :         if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
    1767                 :          0 :             return NULL;
    1768         [ #  # ]:          0 :         rtn2 = mvwinnstr(self->win,y,x,rtn,1023);
    1769                 :          0 :         break;
    1770                 :          0 :     case 3:
    1771         [ #  # ]:          0 :         if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
    1772                 :          0 :             return NULL;
    1773         [ #  # ]:          0 :         if (n < 0) {
    1774                 :          0 :             PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
    1775                 :          0 :             return NULL;
    1776                 :            :         }
    1777         [ #  # ]:          0 :         rtn2 = mvwinnstr(self->win, y, x, rtn, Py_MIN(n,1023));
    1778                 :          0 :         break;
    1779                 :          0 :     default:
    1780                 :          0 :         PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
    1781                 :          0 :         return NULL;
    1782                 :            :     }
    1783         [ #  # ]:          0 :     if (rtn2 == ERR)
    1784                 :          0 :         rtn[0] = 0;
    1785                 :          0 :     return PyBytes_FromString(rtn);
    1786                 :            : }
    1787                 :            : 
    1788                 :            : /*[clinic input]
    1789                 :            : _curses.window.insstr
    1790                 :            : 
    1791                 :            :     [
    1792                 :            :     y: int
    1793                 :            :         Y-coordinate.
    1794                 :            :     x: int
    1795                 :            :         X-coordinate.
    1796                 :            :     ]
    1797                 :            : 
    1798                 :            :     str: object
    1799                 :            :         String to insert.
    1800                 :            : 
    1801                 :            :     [
    1802                 :            :     attr: long
    1803                 :            :         Attributes for characters.
    1804                 :            :     ]
    1805                 :            :     /
    1806                 :            : 
    1807                 :            : Insert the string before the current or specified position.
    1808                 :            : 
    1809                 :            : Insert a character string (as many characters as will fit on the line)
    1810                 :            : before the character under the cursor.  All characters to the right of
    1811                 :            : the cursor are shifted right, with the rightmost characters on the line
    1812                 :            : being lost.  The cursor position does not change (after moving to y, x,
    1813                 :            : if specified).
    1814                 :            : [clinic start generated code]*/
    1815                 :            : 
    1816                 :            : static PyObject *
    1817                 :          0 : _curses_window_insstr_impl(PyCursesWindowObject *self, int group_left_1,
    1818                 :            :                            int y, int x, PyObject *str, int group_right_1,
    1819                 :            :                            long attr)
    1820                 :            : /*[clinic end generated code: output=c259a5265ad0b777 input=6827cddc6340a7f3]*/
    1821                 :            : {
    1822                 :            :     int rtn;
    1823                 :            :     int strtype;
    1824                 :          0 :     PyObject *bytesobj = NULL;
    1825                 :            : #ifdef HAVE_NCURSESW
    1826                 :          0 :     wchar_t *wstr = NULL;
    1827                 :            : #endif
    1828                 :          0 :     attr_t attr_old = A_NORMAL;
    1829                 :          0 :     int use_xy = group_left_1, use_attr = group_right_1;
    1830                 :            :     const char *funcname;
    1831                 :            : 
    1832                 :            : #ifdef HAVE_NCURSESW
    1833                 :          0 :     strtype = PyCurses_ConvertToString(self, str, &bytesobj, &wstr);
    1834                 :            : #else
    1835                 :            :     strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL);
    1836                 :            : #endif
    1837         [ #  # ]:          0 :     if (strtype == 0)
    1838                 :          0 :         return NULL;
    1839                 :            : 
    1840         [ #  # ]:          0 :     if (use_attr) {
    1841         [ #  # ]:          0 :         attr_old = getattrs(self->win);
    1842                 :          0 :         (void)wattrset(self->win, (attr_t)attr);
    1843                 :            :     }
    1844                 :            : #ifdef HAVE_NCURSESW
    1845         [ #  # ]:          0 :     if (strtype == 2) {
    1846                 :          0 :         funcname = "inswstr";
    1847         [ #  # ]:          0 :         if (use_xy)
    1848         [ #  # ]:          0 :             rtn = mvwins_wstr(self->win,y,x,wstr);
    1849                 :            :         else
    1850                 :          0 :             rtn = wins_wstr(self->win,wstr);
    1851                 :          0 :         PyMem_Free(wstr);
    1852                 :            :     }
    1853                 :            :     else
    1854                 :            : #endif
    1855                 :            :     {
    1856                 :          0 :         const char *str = PyBytes_AS_STRING(bytesobj);
    1857                 :          0 :         funcname = "insstr";
    1858         [ #  # ]:          0 :         if (use_xy)
    1859         [ #  # ]:          0 :             rtn = mvwinsstr(self->win,y,x,str);
    1860                 :            :         else
    1861                 :          0 :             rtn = winsstr(self->win,str);
    1862                 :          0 :         Py_DECREF(bytesobj);
    1863                 :            :     }
    1864         [ #  # ]:          0 :     if (use_attr)
    1865                 :          0 :         (void)wattrset(self->win,attr_old);
    1866                 :          0 :     return PyCursesCheckERR(rtn, funcname);
    1867                 :            : }
    1868                 :            : 
    1869                 :            : /*[clinic input]
    1870                 :            : _curses.window.insnstr
    1871                 :            : 
    1872                 :            :     [
    1873                 :            :     y: int
    1874                 :            :         Y-coordinate.
    1875                 :            :     x: int
    1876                 :            :         X-coordinate.
    1877                 :            :     ]
    1878                 :            : 
    1879                 :            :     str: object
    1880                 :            :         String to insert.
    1881                 :            : 
    1882                 :            :     n: int
    1883                 :            :         Maximal number of characters.
    1884                 :            : 
    1885                 :            :     [
    1886                 :            :     attr: long
    1887                 :            :         Attributes for characters.
    1888                 :            :     ]
    1889                 :            :     /
    1890                 :            : 
    1891                 :            : Insert at most n characters of the string.
    1892                 :            : 
    1893                 :            : Insert a character string (as many characters as will fit on the line)
    1894                 :            : before the character under the cursor, up to n characters.  If n is zero
    1895                 :            : or negative, the entire string is inserted.  All characters to the right
    1896                 :            : of the cursor are shifted right, with the rightmost characters on the line
    1897                 :            : being lost.  The cursor position does not change (after moving to y, x, if
    1898                 :            : specified).
    1899                 :            : [clinic start generated code]*/
    1900                 :            : 
    1901                 :            : static PyObject *
    1902                 :          0 : _curses_window_insnstr_impl(PyCursesWindowObject *self, int group_left_1,
    1903                 :            :                             int y, int x, PyObject *str, int n,
    1904                 :            :                             int group_right_1, long attr)
    1905                 :            : /*[clinic end generated code: output=971a32ea6328ec8b input=70fa0cd543901a4c]*/
    1906                 :            : {
    1907                 :            :     int rtn;
    1908                 :            :     int strtype;
    1909                 :          0 :     PyObject *bytesobj = NULL;
    1910                 :            : #ifdef HAVE_NCURSESW
    1911                 :          0 :     wchar_t *wstr = NULL;
    1912                 :            : #endif
    1913                 :          0 :     attr_t attr_old = A_NORMAL;
    1914                 :          0 :     int use_xy = group_left_1, use_attr = group_right_1;
    1915                 :            :     const char *funcname;
    1916                 :            : 
    1917                 :            : #ifdef HAVE_NCURSESW
    1918                 :          0 :     strtype = PyCurses_ConvertToString(self, str, &bytesobj, &wstr);
    1919                 :            : #else
    1920                 :            :     strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL);
    1921                 :            : #endif
    1922         [ #  # ]:          0 :     if (strtype == 0)
    1923                 :          0 :         return NULL;
    1924                 :            : 
    1925         [ #  # ]:          0 :     if (use_attr) {
    1926         [ #  # ]:          0 :         attr_old = getattrs(self->win);
    1927                 :          0 :         (void)wattrset(self->win, (attr_t)attr);
    1928                 :            :     }
    1929                 :            : #ifdef HAVE_NCURSESW
    1930         [ #  # ]:          0 :     if (strtype == 2) {
    1931                 :          0 :         funcname = "insn_wstr";
    1932         [ #  # ]:          0 :         if (use_xy)
    1933         [ #  # ]:          0 :             rtn = mvwins_nwstr(self->win,y,x,wstr,n);
    1934                 :            :         else
    1935                 :          0 :             rtn = wins_nwstr(self->win,wstr,n);
    1936                 :          0 :         PyMem_Free(wstr);
    1937                 :            :     }
    1938                 :            :     else
    1939                 :            : #endif
    1940                 :            :     {
    1941                 :          0 :         const char *str = PyBytes_AS_STRING(bytesobj);
    1942                 :          0 :         funcname = "insnstr";
    1943         [ #  # ]:          0 :         if (use_xy)
    1944         [ #  # ]:          0 :             rtn = mvwinsnstr(self->win,y,x,str,n);
    1945                 :            :         else
    1946                 :          0 :             rtn = winsnstr(self->win,str,n);
    1947                 :          0 :         Py_DECREF(bytesobj);
    1948                 :            :     }
    1949         [ #  # ]:          0 :     if (use_attr)
    1950                 :          0 :         (void)wattrset(self->win,attr_old);
    1951                 :          0 :     return PyCursesCheckERR(rtn, funcname);
    1952                 :            : }
    1953                 :            : 
    1954                 :            : /*[clinic input]
    1955                 :            : _curses.window.is_linetouched
    1956                 :            : 
    1957                 :            :     line: int
    1958                 :            :         Line number.
    1959                 :            :     /
    1960                 :            : 
    1961                 :            : Return True if the specified line was modified, otherwise return False.
    1962                 :            : 
    1963                 :            : Raise a curses.error exception if line is not valid for the given window.
    1964                 :            : [clinic start generated code]*/
    1965                 :            : 
    1966                 :            : static PyObject *
    1967                 :          0 : _curses_window_is_linetouched_impl(PyCursesWindowObject *self, int line)
    1968                 :            : /*[clinic end generated code: output=ad4a4edfee2db08c input=a7be0c189f243914]*/
    1969                 :            : {
    1970                 :            :     int erg;
    1971   [ #  #  #  #  :          0 :     erg = is_linetouched(self->win, line);
             #  #  #  # ]
    1972         [ #  # ]:          0 :     if (erg == ERR) {
    1973                 :          0 :         PyErr_SetString(PyExc_TypeError,
    1974                 :            :                         "is_linetouched: line number outside of boundaries");
    1975                 :          0 :         return NULL;
    1976                 :            :     }
    1977                 :          0 :     return PyBool_FromLong(erg);
    1978                 :            : }
    1979                 :            : 
    1980                 :            : #ifdef py_is_pad
    1981                 :            : /*[clinic input]
    1982                 :            : _curses.window.noutrefresh
    1983                 :            : 
    1984                 :            :     [
    1985                 :            :     pminrow: int
    1986                 :            :     pmincol: int
    1987                 :            :     sminrow: int
    1988                 :            :     smincol: int
    1989                 :            :     smaxrow: int
    1990                 :            :     smaxcol: int
    1991                 :            :     ]
    1992                 :            :     /
    1993                 :            : 
    1994                 :            : Mark for refresh but wait.
    1995                 :            : 
    1996                 :            : This function updates the data structure representing the desired state of the
    1997                 :            : window, but does not force an update of the physical screen.  To accomplish
    1998                 :            : that, call doupdate().
    1999                 :            : [clinic start generated code]*/
    2000                 :            : 
    2001                 :            : static PyObject *
    2002                 :          0 : _curses_window_noutrefresh_impl(PyCursesWindowObject *self,
    2003                 :            :                                 int group_right_1, int pminrow, int pmincol,
    2004                 :            :                                 int sminrow, int smincol, int smaxrow,
    2005                 :            :                                 int smaxcol)
    2006                 :            : /*[clinic end generated code: output=809a1f3c6a03e23e input=3e56898388cd739e]*/
    2007                 :            : #else
    2008                 :            : /*[clinic input]
    2009                 :            : _curses.window.noutrefresh
    2010                 :            : 
    2011                 :            : Mark for refresh but wait.
    2012                 :            : 
    2013                 :            : This function updates the data structure representing the desired state of the
    2014                 :            : window, but does not force an update of the physical screen.  To accomplish
    2015                 :            : that, call doupdate().
    2016                 :            : [clinic start generated code]*/
    2017                 :            : 
    2018                 :            : static PyObject *
    2019                 :            : _curses_window_noutrefresh_impl(PyCursesWindowObject *self)
    2020                 :            : /*[clinic end generated code: output=6ef6dec666643fee input=876902e3fa431dbd]*/
    2021                 :            : #endif
    2022                 :            : {
    2023                 :            :     int rtn;
    2024                 :            : 
    2025                 :            : #ifdef py_is_pad
    2026   [ #  #  #  # ]:          0 :     if (py_is_pad(self->win)) {
    2027         [ #  # ]:          0 :         if (!group_right_1) {
    2028                 :          0 :             PyErr_SetString(PyCursesError,
    2029                 :            :                             "noutrefresh() called for a pad "
    2030                 :            :                             "requires 6 arguments");
    2031                 :          0 :             return NULL;
    2032                 :            :         }
    2033                 :          0 :         Py_BEGIN_ALLOW_THREADS
    2034                 :          0 :         rtn = pnoutrefresh(self->win, pminrow, pmincol,
    2035                 :            :                            sminrow, smincol, smaxrow, smaxcol);
    2036                 :          0 :         Py_END_ALLOW_THREADS
    2037                 :          0 :         return PyCursesCheckERR(rtn, "pnoutrefresh");
    2038                 :            :     }
    2039         [ #  # ]:          0 :     if (group_right_1) {
    2040                 :          0 :         PyErr_SetString(PyExc_TypeError,
    2041                 :            :                         "noutrefresh() takes no arguments (6 given)");
    2042                 :          0 :         return NULL;
    2043                 :            :     }
    2044                 :            : #endif
    2045                 :          0 :     Py_BEGIN_ALLOW_THREADS
    2046                 :          0 :     rtn = wnoutrefresh(self->win);
    2047                 :          0 :     Py_END_ALLOW_THREADS
    2048                 :          0 :     return PyCursesCheckERR(rtn, "wnoutrefresh");
    2049                 :            : }
    2050                 :            : 
    2051                 :            : /*[clinic input]
    2052                 :            : _curses.window.overlay
    2053                 :            : 
    2054                 :            :     destwin: object(type="PyCursesWindowObject *", subclass_of="&PyCursesWindow_Type")
    2055                 :            : 
    2056                 :            :     [
    2057                 :            :     sminrow: int
    2058                 :            :     smincol: int
    2059                 :            :     dminrow: int
    2060                 :            :     dmincol: int
    2061                 :            :     dmaxrow: int
    2062                 :            :     dmaxcol: int
    2063                 :            :     ]
    2064                 :            :     /
    2065                 :            : 
    2066                 :            : Overlay the window on top of destwin.
    2067                 :            : 
    2068                 :            : The windows need not be the same size, only the overlapping region is copied.
    2069                 :            : This copy is non-destructive, which means that the current background
    2070                 :            : character does not overwrite the old contents of destwin.
    2071                 :            : 
    2072                 :            : To get fine-grained control over the copied region, the second form of
    2073                 :            : overlay() can be used.  sminrow and smincol are the upper-left coordinates
    2074                 :            : of the source window, and the other variables mark a rectangle in the
    2075                 :            : destination window.
    2076                 :            : [clinic start generated code]*/
    2077                 :            : 
    2078                 :            : static PyObject *
    2079                 :          0 : _curses_window_overlay_impl(PyCursesWindowObject *self,
    2080                 :            :                             PyCursesWindowObject *destwin, int group_right_1,
    2081                 :            :                             int sminrow, int smincol, int dminrow,
    2082                 :            :                             int dmincol, int dmaxrow, int dmaxcol)
    2083                 :            : /*[clinic end generated code: output=82bb2c4cb443ca58 input=7edd23ad22cc1984]*/
    2084                 :            : {
    2085                 :            :     int rtn;
    2086                 :            : 
    2087         [ #  # ]:          0 :     if (group_right_1) {
    2088                 :          0 :         rtn = copywin(self->win, destwin->win, sminrow, smincol,
    2089                 :            :                       dminrow, dmincol, dmaxrow, dmaxcol, TRUE);
    2090                 :          0 :         return PyCursesCheckERR(rtn, "copywin");
    2091                 :            :     }
    2092                 :            :     else {
    2093                 :          0 :         rtn = overlay(self->win, destwin->win);
    2094                 :          0 :         return PyCursesCheckERR(rtn, "overlay");
    2095                 :            :     }
    2096                 :            : }
    2097                 :            : 
    2098                 :            : /*[clinic input]
    2099                 :            : _curses.window.overwrite
    2100                 :            : 
    2101                 :            :     destwin: object(type="PyCursesWindowObject *", subclass_of="&PyCursesWindow_Type")
    2102                 :            : 
    2103                 :            :     [
    2104                 :            :     sminrow: int
    2105                 :            :     smincol: int
    2106                 :            :     dminrow: int
    2107                 :            :     dmincol: int
    2108                 :            :     dmaxrow: int
    2109                 :            :     dmaxcol: int
    2110                 :            :     ]
    2111                 :            :     /
    2112                 :            : 
    2113                 :            : Overwrite the window on top of destwin.
    2114                 :            : 
    2115                 :            : The windows need not be the same size, in which case only the overlapping
    2116                 :            : region is copied.  This copy is destructive, which means that the current
    2117                 :            : background character overwrites the old contents of destwin.
    2118                 :            : 
    2119                 :            : To get fine-grained control over the copied region, the second form of
    2120                 :            : overwrite() can be used. sminrow and smincol are the upper-left coordinates
    2121                 :            : of the source window, the other variables mark a rectangle in the destination
    2122                 :            : window.
    2123                 :            : [clinic start generated code]*/
    2124                 :            : 
    2125                 :            : static PyObject *
    2126                 :          0 : _curses_window_overwrite_impl(PyCursesWindowObject *self,
    2127                 :            :                               PyCursesWindowObject *destwin,
    2128                 :            :                               int group_right_1, int sminrow, int smincol,
    2129                 :            :                               int dminrow, int dmincol, int dmaxrow,
    2130                 :            :                               int dmaxcol)
    2131                 :            : /*[clinic end generated code: output=12ae007d1681be28 input=ea5de1b35cd948e0]*/
    2132                 :            : {
    2133                 :            :     int rtn;
    2134                 :            : 
    2135         [ #  # ]:          0 :     if (group_right_1) {
    2136                 :          0 :         rtn = copywin(self->win, destwin->win, sminrow, smincol,
    2137                 :            :                       dminrow, dmincol, dmaxrow, dmaxcol, FALSE);
    2138                 :          0 :         return PyCursesCheckERR(rtn, "copywin");
    2139                 :            :     }
    2140                 :            :     else {
    2141                 :          0 :         rtn = overwrite(self->win, destwin->win);
    2142                 :          0 :         return PyCursesCheckERR(rtn, "overwrite");
    2143                 :            :     }
    2144                 :            : }
    2145                 :            : 
    2146                 :            : /*[clinic input]
    2147                 :            : _curses.window.putwin
    2148                 :            : 
    2149                 :            :     file: object
    2150                 :            :     /
    2151                 :            : 
    2152                 :            : Write all data associated with the window into the provided file object.
    2153                 :            : 
    2154                 :            : This information can be later retrieved using the getwin() function.
    2155                 :            : [clinic start generated code]*/
    2156                 :            : 
    2157                 :            : static PyObject *
    2158                 :          0 : _curses_window_putwin(PyCursesWindowObject *self, PyObject *file)
    2159                 :            : /*[clinic end generated code: output=3a25e2a5e7a040ac input=0608648e09c8ea0a]*/
    2160                 :            : {
    2161                 :            :     /* We have to simulate this by writing to a temporary FILE*,
    2162                 :            :        then reading back, then writing to the argument file. */
    2163                 :            :     FILE *fp;
    2164                 :          0 :     PyObject *res = NULL;
    2165                 :            : 
    2166                 :          0 :     fp = tmpfile();
    2167         [ #  # ]:          0 :     if (fp == NULL)
    2168                 :          0 :         return PyErr_SetFromErrno(PyExc_OSError);
    2169         [ #  # ]:          0 :     if (_Py_set_inheritable(fileno(fp), 0, NULL) < 0)
    2170                 :          0 :         goto exit;
    2171                 :          0 :     res = PyCursesCheckERR(putwin(self->win, fp), "putwin");
    2172         [ #  # ]:          0 :     if (res == NULL)
    2173                 :          0 :         goto exit;
    2174                 :          0 :     fseek(fp, 0, 0);
    2175                 :          0 :     while (1) {
    2176                 :            :         char buf[BUFSIZ];
    2177                 :          0 :         Py_ssize_t n = fread(buf, 1, BUFSIZ, fp);
    2178                 :            : 
    2179         [ #  # ]:          0 :         if (n <= 0)
    2180                 :          0 :             break;
    2181                 :          0 :         Py_DECREF(res);
    2182                 :          0 :         res = PyObject_CallMethod(file, "write", "y#", buf, n);
    2183         [ #  # ]:          0 :         if (res == NULL)
    2184                 :          0 :             break;
    2185                 :            :     }
    2186                 :            : 
    2187                 :          0 : exit:
    2188                 :          0 :     fclose(fp);
    2189                 :          0 :     return res;
    2190                 :            : }
    2191                 :            : 
    2192                 :            : /*[clinic input]
    2193                 :            : _curses.window.redrawln
    2194                 :            : 
    2195                 :            :     beg: int
    2196                 :            :         Starting line number.
    2197                 :            :     num: int
    2198                 :            :         The number of lines.
    2199                 :            :     /
    2200                 :            : 
    2201                 :            : Mark the specified lines corrupted.
    2202                 :            : 
    2203                 :            : They should be completely redrawn on the next refresh() call.
    2204                 :            : [clinic start generated code]*/
    2205                 :            : 
    2206                 :            : static PyObject *
    2207                 :          0 : _curses_window_redrawln_impl(PyCursesWindowObject *self, int beg, int num)
    2208                 :            : /*[clinic end generated code: output=ea216e334f9ce1b4 input=152155e258a77a7a]*/
    2209                 :            : {
    2210                 :          0 :     return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
    2211                 :            : }
    2212                 :            : 
    2213                 :            : /*[clinic input]
    2214                 :            : _curses.window.refresh
    2215                 :            : 
    2216                 :            :     [
    2217                 :            :     pminrow: int
    2218                 :            :     pmincol: int
    2219                 :            :     sminrow: int
    2220                 :            :     smincol: int
    2221                 :            :     smaxrow: int
    2222                 :            :     smaxcol: int
    2223                 :            :     ]
    2224                 :            :     /
    2225                 :            : 
    2226                 :            : Update the display immediately.
    2227                 :            : 
    2228                 :            : Synchronize actual screen with previous drawing/deleting methods.
    2229                 :            : The 6 optional arguments can only be specified when the window is a pad
    2230                 :            : created with newpad().  The additional parameters are needed to indicate
    2231                 :            : what part of the pad and screen are involved.  pminrow and pmincol specify
    2232                 :            : the upper left-hand corner of the rectangle to be displayed in the pad.
    2233                 :            : sminrow, smincol, smaxrow, and smaxcol specify the edges of the rectangle to
    2234                 :            : be displayed on the screen.  The lower right-hand corner of the rectangle to
    2235                 :            : be displayed in the pad is calculated from the screen coordinates, since the
    2236                 :            : rectangles must be the same size.  Both rectangles must be entirely contained
    2237                 :            : within their respective structures.  Negative values of pminrow, pmincol,
    2238                 :            : sminrow, or smincol are treated as if they were zero.
    2239                 :            : [clinic start generated code]*/
    2240                 :            : 
    2241                 :            : static PyObject *
    2242                 :          0 : _curses_window_refresh_impl(PyCursesWindowObject *self, int group_right_1,
    2243                 :            :                             int pminrow, int pmincol, int sminrow,
    2244                 :            :                             int smincol, int smaxrow, int smaxcol)
    2245                 :            : /*[clinic end generated code: output=42199543115e6e63 input=95e01cb5ffc635d0]*/
    2246                 :            : {
    2247                 :            :     int rtn;
    2248                 :            : 
    2249                 :            : #ifdef py_is_pad
    2250   [ #  #  #  # ]:          0 :     if (py_is_pad(self->win)) {
    2251         [ #  # ]:          0 :         if (!group_right_1) {
    2252                 :          0 :             PyErr_SetString(PyCursesError,
    2253                 :            :                             "refresh() for a pad requires 6 arguments");
    2254                 :          0 :             return NULL;
    2255                 :            :         }
    2256                 :          0 :         Py_BEGIN_ALLOW_THREADS
    2257                 :          0 :         rtn = prefresh(self->win, pminrow, pmincol,
    2258                 :            :                        sminrow, smincol, smaxrow, smaxcol);
    2259                 :          0 :         Py_END_ALLOW_THREADS
    2260                 :          0 :         return PyCursesCheckERR(rtn, "prefresh");
    2261                 :            :     }
    2262                 :            : #endif
    2263         [ #  # ]:          0 :     if (group_right_1) {
    2264                 :          0 :         PyErr_SetString(PyExc_TypeError,
    2265                 :            :                         "refresh() takes no arguments (6 given)");
    2266                 :          0 :         return NULL;
    2267                 :            :     }
    2268                 :          0 :     Py_BEGIN_ALLOW_THREADS
    2269                 :          0 :     rtn = wrefresh(self->win);
    2270                 :          0 :     Py_END_ALLOW_THREADS
    2271                 :          0 :     return PyCursesCheckERR(rtn, "prefresh");
    2272                 :            : }
    2273                 :            : 
    2274                 :            : /*[clinic input]
    2275                 :            : _curses.window.setscrreg
    2276                 :            : 
    2277                 :            :     top: int
    2278                 :            :         First line number.
    2279                 :            :     bottom: int
    2280                 :            :         Last line number.
    2281                 :            :     /
    2282                 :            : 
    2283                 :            : Define a software scrolling region.
    2284                 :            : 
    2285                 :            : All scrolling actions will take place in this region.
    2286                 :            : [clinic start generated code]*/
    2287                 :            : 
    2288                 :            : static PyObject *
    2289                 :          0 : _curses_window_setscrreg_impl(PyCursesWindowObject *self, int top,
    2290                 :            :                               int bottom)
    2291                 :            : /*[clinic end generated code: output=486ab5db218d2b1a input=1b517b986838bf0e]*/
    2292                 :            : {
    2293                 :          0 :     return PyCursesCheckERR(wsetscrreg(self->win, top, bottom), "wsetscrreg");
    2294                 :            : }
    2295                 :            : 
    2296                 :            : /*[clinic input]
    2297                 :            : _curses.window.subwin
    2298                 :            : 
    2299                 :            :     [
    2300                 :            :     nlines: int = 0
    2301                 :            :         Height.
    2302                 :            :     ncols: int = 0
    2303                 :            :         Width.
    2304                 :            :     ]
    2305                 :            :     begin_y: int
    2306                 :            :         Top side y-coordinate.
    2307                 :            :     begin_x: int
    2308                 :            :         Left side x-coordinate.
    2309                 :            :     /
    2310                 :            : 
    2311                 :            : Create a sub-window (screen-relative coordinates).
    2312                 :            : 
    2313                 :            : By default, the sub-window will extend from the specified position to the
    2314                 :            : lower right corner of the window.
    2315                 :            : [clinic start generated code]*/
    2316                 :            : 
    2317                 :            : static PyObject *
    2318                 :          0 : _curses_window_subwin_impl(PyCursesWindowObject *self, int group_left_1,
    2319                 :            :                            int nlines, int ncols, int begin_y, int begin_x)
    2320                 :            : /*[clinic end generated code: output=93e898afc348f59a input=2129fa47fd57721c]*/
    2321                 :            : {
    2322                 :            :     WINDOW *win;
    2323                 :            : 
    2324                 :            :     /* printf("Subwin: %i %i %i %i   \n", nlines, ncols, begin_y, begin_x); */
    2325                 :            : #ifdef py_is_pad
    2326   [ #  #  #  # ]:          0 :     if (py_is_pad(self->win)) {
    2327                 :          0 :         win = subpad(self->win, nlines, ncols, begin_y, begin_x);
    2328                 :            :     }
    2329                 :            :     else
    2330                 :            : #endif
    2331                 :          0 :         win = subwin(self->win, nlines, ncols, begin_y, begin_x);
    2332                 :            : 
    2333         [ #  # ]:          0 :     if (win == NULL) {
    2334                 :          0 :         PyErr_SetString(PyCursesError, catchall_NULL);
    2335                 :          0 :         return NULL;
    2336                 :            :     }
    2337                 :            : 
    2338                 :          0 :     return (PyObject *)PyCursesWindow_New(win, self->encoding);
    2339                 :            : }
    2340                 :            : 
    2341                 :            : /*[clinic input]
    2342                 :            : _curses.window.scroll
    2343                 :            : 
    2344                 :            :     [
    2345                 :            :     lines: int = 1
    2346                 :            :         Number of lines to scroll.
    2347                 :            :     ]
    2348                 :            :     /
    2349                 :            : 
    2350                 :            : Scroll the screen or scrolling region.
    2351                 :            : 
    2352                 :            : Scroll upward if the argument is positive and downward if it is negative.
    2353                 :            : [clinic start generated code]*/
    2354                 :            : 
    2355                 :            : static PyObject *
    2356                 :          0 : _curses_window_scroll_impl(PyCursesWindowObject *self, int group_right_1,
    2357                 :            :                            int lines)
    2358                 :            : /*[clinic end generated code: output=4541a8a11852d360 input=c969ca0cfabbdbec]*/
    2359                 :            : {
    2360         [ #  # ]:          0 :     if (!group_right_1) {
    2361                 :          0 :         return PyCursesCheckERR(scroll(self->win), "scroll");
    2362                 :            :     }
    2363                 :            :     else {
    2364                 :          0 :         return PyCursesCheckERR(wscrl(self->win, lines), "scroll");
    2365                 :            :     }
    2366                 :            : }
    2367                 :            : 
    2368                 :            : /*[clinic input]
    2369                 :            : _curses.window.touchline
    2370                 :            : 
    2371                 :            :     start: int
    2372                 :            :     count: int
    2373                 :            :     [
    2374                 :            :     changed: bool = True
    2375                 :            :     ]
    2376                 :            :     /
    2377                 :            : 
    2378                 :            : Pretend count lines have been changed, starting with line start.
    2379                 :            : 
    2380                 :            : If changed is supplied, it specifies whether the affected lines are marked
    2381                 :            : as having been changed (changed=True) or unchanged (changed=False).
    2382                 :            : [clinic start generated code]*/
    2383                 :            : 
    2384                 :            : static PyObject *
    2385                 :          0 : _curses_window_touchline_impl(PyCursesWindowObject *self, int start,
    2386                 :            :                               int count, int group_right_1, int changed)
    2387                 :            : /*[clinic end generated code: output=65d05b3f7438c61d input=a98aa4f79b6be845]*/
    2388                 :            : {
    2389         [ #  # ]:          0 :     if (!group_right_1) {
    2390                 :          0 :         return PyCursesCheckERR(touchline(self->win, start, count), "touchline");
    2391                 :            :     }
    2392                 :            :     else {
    2393                 :          0 :         return PyCursesCheckERR(wtouchln(self->win, start, count, changed), "touchline");
    2394                 :            :     }
    2395                 :            : }
    2396                 :            : 
    2397                 :            : /*[clinic input]
    2398                 :            : _curses.window.vline
    2399                 :            : 
    2400                 :            :     [
    2401                 :            :     y: int
    2402                 :            :         Starting Y-coordinate.
    2403                 :            :     x: int
    2404                 :            :         Starting X-coordinate.
    2405                 :            :     ]
    2406                 :            : 
    2407                 :            :     ch: object
    2408                 :            :         Character to draw.
    2409                 :            :     n: int
    2410                 :            :         Line length.
    2411                 :            : 
    2412                 :            :     [
    2413                 :            :     attr: long(c_default="A_NORMAL") = _curses.A_NORMAL
    2414                 :            :         Attributes for the character.
    2415                 :            :     ]
    2416                 :            :     /
    2417                 :            : 
    2418                 :            : Display a vertical line.
    2419                 :            : [clinic start generated code]*/
    2420                 :            : 
    2421                 :            : static PyObject *
    2422                 :          0 : _curses_window_vline_impl(PyCursesWindowObject *self, int group_left_1,
    2423                 :            :                           int y, int x, PyObject *ch, int n,
    2424                 :            :                           int group_right_1, long attr)
    2425                 :            : /*[clinic end generated code: output=287ad1cc8982217f input=a6f2dc86a4648b32]*/
    2426                 :            : {
    2427                 :            :     chtype ch_;
    2428                 :            : 
    2429         [ #  # ]:          0 :     if (!PyCurses_ConvertToChtype(self, ch, &ch_))
    2430                 :          0 :         return NULL;
    2431         [ #  # ]:          0 :     if (group_left_1) {
    2432         [ #  # ]:          0 :         if (wmove(self->win, y, x) == ERR)
    2433                 :          0 :             return PyCursesCheckERR(ERR, "wmove");
    2434                 :            :     }
    2435                 :          0 :     return PyCursesCheckERR(wvline(self->win, ch_ | (attr_t)attr, n), "vline");
    2436                 :            : }
    2437                 :            : 
    2438                 :            : static PyObject *
    2439                 :          0 : PyCursesWindow_get_encoding(PyCursesWindowObject *self, void *closure)
    2440                 :            : {
    2441                 :          0 :     return PyUnicode_FromString(self->encoding);
    2442                 :            : }
    2443                 :            : 
    2444                 :            : static int
    2445                 :          0 : PyCursesWindow_set_encoding(PyCursesWindowObject *self, PyObject *value, void *Py_UNUSED(ignored))
    2446                 :            : {
    2447                 :            :     PyObject *ascii;
    2448                 :            :     char *encoding;
    2449                 :            : 
    2450                 :            :     /* It is illegal to del win.encoding */
    2451         [ #  # ]:          0 :     if (value == NULL) {
    2452                 :          0 :         PyErr_SetString(PyExc_TypeError,
    2453                 :            :                         "encoding may not be deleted");
    2454                 :          0 :         return -1;
    2455                 :            :     }
    2456                 :            : 
    2457         [ #  # ]:          0 :     if (!PyUnicode_Check(value)) {
    2458                 :          0 :         PyErr_SetString(PyExc_TypeError,
    2459                 :            :                         "setting encoding to a non-string");
    2460                 :          0 :         return -1;
    2461                 :            :     }
    2462                 :          0 :     ascii = PyUnicode_AsASCIIString(value);
    2463         [ #  # ]:          0 :     if (ascii == NULL)
    2464                 :          0 :         return -1;
    2465                 :          0 :     encoding = _PyMem_Strdup(PyBytes_AS_STRING(ascii));
    2466                 :          0 :     Py_DECREF(ascii);
    2467         [ #  # ]:          0 :     if (encoding == NULL) {
    2468                 :          0 :         PyErr_NoMemory();
    2469                 :          0 :         return -1;
    2470                 :            :     }
    2471                 :          0 :     PyMem_Free(self->encoding);
    2472                 :          0 :     self->encoding = encoding;
    2473                 :          0 :     return 0;
    2474                 :            : }
    2475                 :            : 
    2476                 :            : #include "clinic/_cursesmodule.c.h"
    2477                 :            : 
    2478                 :            : static PyMethodDef PyCursesWindow_Methods[] = {
    2479                 :            :     _CURSES_WINDOW_ADDCH_METHODDEF
    2480                 :            :     _CURSES_WINDOW_ADDNSTR_METHODDEF
    2481                 :            :     _CURSES_WINDOW_ADDSTR_METHODDEF
    2482                 :            :     _CURSES_WINDOW_ATTROFF_METHODDEF
    2483                 :            :     _CURSES_WINDOW_ATTRON_METHODDEF
    2484                 :            :     _CURSES_WINDOW_ATTRSET_METHODDEF
    2485                 :            :     _CURSES_WINDOW_BKGD_METHODDEF
    2486                 :            : #ifdef HAVE_CURSES_WCHGAT
    2487                 :            :     {"chgat",           (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS},
    2488                 :            : #endif
    2489                 :            :     _CURSES_WINDOW_BKGDSET_METHODDEF
    2490                 :            :     _CURSES_WINDOW_BORDER_METHODDEF
    2491                 :            :     _CURSES_WINDOW_BOX_METHODDEF
    2492                 :            :     {"clear",           (PyCFunction)PyCursesWindow_wclear, METH_NOARGS},
    2493                 :            :     {"clearok",         (PyCFunction)PyCursesWindow_clearok, METH_VARARGS},
    2494                 :            :     {"clrtobot",        (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS},
    2495                 :            :     {"clrtoeol",        (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS},
    2496                 :            :     {"cursyncup",       (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS},
    2497                 :            :     _CURSES_WINDOW_DELCH_METHODDEF
    2498                 :            :     {"deleteln",        (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS},
    2499                 :            :     _CURSES_WINDOW_DERWIN_METHODDEF
    2500                 :            :     _CURSES_WINDOW_ECHOCHAR_METHODDEF
    2501                 :            :     _CURSES_WINDOW_ENCLOSE_METHODDEF
    2502                 :            :     {"erase",           (PyCFunction)PyCursesWindow_werase, METH_NOARGS},
    2503                 :            :     {"getbegyx",        (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS},
    2504                 :            :     _CURSES_WINDOW_GETBKGD_METHODDEF
    2505                 :            :     _CURSES_WINDOW_GETCH_METHODDEF
    2506                 :            :     _CURSES_WINDOW_GETKEY_METHODDEF
    2507                 :            :     _CURSES_WINDOW_GET_WCH_METHODDEF
    2508                 :            :     {"getmaxyx",        (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS},
    2509                 :            :     {"getparyx",        (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS},
    2510                 :            :     {"getstr",          (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS},
    2511                 :            :     {"getyx",           (PyCFunction)PyCursesWindow_getyx, METH_NOARGS},
    2512                 :            :     _CURSES_WINDOW_HLINE_METHODDEF
    2513                 :            :     {"idcok",           (PyCFunction)PyCursesWindow_idcok, METH_VARARGS},
    2514                 :            :     {"idlok",           (PyCFunction)PyCursesWindow_idlok, METH_VARARGS},
    2515                 :            : #ifdef HAVE_CURSES_IMMEDOK
    2516                 :            :     {"immedok",         (PyCFunction)PyCursesWindow_immedok, METH_VARARGS},
    2517                 :            : #endif
    2518                 :            :     _CURSES_WINDOW_INCH_METHODDEF
    2519                 :            :     _CURSES_WINDOW_INSCH_METHODDEF
    2520                 :            :     {"insdelln",        (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS},
    2521                 :            :     {"insertln",        (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS},
    2522                 :            :     _CURSES_WINDOW_INSNSTR_METHODDEF
    2523                 :            :     _CURSES_WINDOW_INSSTR_METHODDEF
    2524                 :            :     {"instr",           (PyCFunction)PyCursesWindow_InStr, METH_VARARGS},
    2525                 :            :     _CURSES_WINDOW_IS_LINETOUCHED_METHODDEF
    2526                 :            :     {"is_wintouched",   (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS},
    2527                 :            :     {"keypad",          (PyCFunction)PyCursesWindow_keypad, METH_VARARGS},
    2528                 :            :     {"leaveok",         (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS},
    2529                 :            :     {"move",            (PyCFunction)PyCursesWindow_wmove, METH_VARARGS},
    2530                 :            :     {"mvderwin",        (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS},
    2531                 :            :     {"mvwin",           (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS},
    2532                 :            :     {"nodelay",         (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS},
    2533                 :            :     {"notimeout",       (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS},
    2534                 :            :     _CURSES_WINDOW_NOUTREFRESH_METHODDEF
    2535                 :            :     _CURSES_WINDOW_OVERLAY_METHODDEF
    2536                 :            :     _CURSES_WINDOW_OVERWRITE_METHODDEF
    2537                 :            :     _CURSES_WINDOW_PUTWIN_METHODDEF
    2538                 :            :     _CURSES_WINDOW_REDRAWLN_METHODDEF
    2539                 :            :     {"redrawwin",       (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS},
    2540                 :            :     _CURSES_WINDOW_REFRESH_METHODDEF
    2541                 :            : #ifndef STRICT_SYSV_CURSES
    2542                 :            :     {"resize",          (PyCFunction)PyCursesWindow_wresize, METH_VARARGS},
    2543                 :            : #endif
    2544                 :            :     _CURSES_WINDOW_SCROLL_METHODDEF
    2545                 :            :     {"scrollok",        (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS},
    2546                 :            :     _CURSES_WINDOW_SETSCRREG_METHODDEF
    2547                 :            :     {"standend",        (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS},
    2548                 :            :     {"standout",        (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS},
    2549                 :            :     {"subpad", (PyCFunction)_curses_window_subwin, METH_VARARGS, _curses_window_subwin__doc__},
    2550                 :            :     _CURSES_WINDOW_SUBWIN_METHODDEF
    2551                 :            :     {"syncdown",        (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS},
    2552                 :            : #ifdef HAVE_CURSES_SYNCOK
    2553                 :            :     {"syncok",          (PyCFunction)PyCursesWindow_syncok, METH_VARARGS},
    2554                 :            : #endif
    2555                 :            :     {"syncup",          (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS},
    2556                 :            :     {"timeout",         (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS},
    2557                 :            :     _CURSES_WINDOW_TOUCHLINE_METHODDEF
    2558                 :            :     {"touchwin",        (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS},
    2559                 :            :     {"untouchwin",      (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS},
    2560                 :            :     _CURSES_WINDOW_VLINE_METHODDEF
    2561                 :            :     {NULL,                  NULL}   /* sentinel */
    2562                 :            : };
    2563                 :            : 
    2564                 :            : static PyGetSetDef PyCursesWindow_getsets[] = {
    2565                 :            :     {"encoding",
    2566                 :            :      (getter)PyCursesWindow_get_encoding,
    2567                 :            :      (setter)PyCursesWindow_set_encoding,
    2568                 :            :      "the typecode character used to create the array"},
    2569                 :            :     {NULL, NULL, NULL, NULL }  /* sentinel */
    2570                 :            : };
    2571                 :            : 
    2572                 :            : /* -------------------------------------------------------*/
    2573                 :            : 
    2574                 :            : PyTypeObject PyCursesWindow_Type = {
    2575                 :            :     PyVarObject_HEAD_INIT(NULL, 0)
    2576                 :            :     "_curses.window",           /*tp_name*/
    2577                 :            :     sizeof(PyCursesWindowObject),       /*tp_basicsize*/
    2578                 :            :     0,                          /*tp_itemsize*/
    2579                 :            :     /* methods */
    2580                 :            :     (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
    2581                 :            :     0,                          /*tp_vectorcall_offset*/
    2582                 :            :     (getattrfunc)0,             /*tp_getattr*/
    2583                 :            :     (setattrfunc)0,             /*tp_setattr*/
    2584                 :            :     0,                          /*tp_as_async*/
    2585                 :            :     0,                          /*tp_repr*/
    2586                 :            :     0,                          /*tp_as_number*/
    2587                 :            :     0,                          /*tp_as_sequence*/
    2588                 :            :     0,                          /*tp_as_mapping*/
    2589                 :            :     0,                          /*tp_hash*/
    2590                 :            :     0,                          /*tp_call*/
    2591                 :            :     0,                          /*tp_str*/
    2592                 :            :     0,                          /*tp_getattro*/
    2593                 :            :     0,                          /*tp_setattro*/
    2594                 :            :     0,                          /*tp_as_buffer*/
    2595                 :            :     Py_TPFLAGS_DEFAULT,         /*tp_flags*/
    2596                 :            :     0,                          /*tp_doc*/
    2597                 :            :     0,                          /*tp_traverse*/
    2598                 :            :     0,                          /*tp_clear*/
    2599                 :            :     0,                          /*tp_richcompare*/
    2600                 :            :     0,                          /*tp_weaklistoffset*/
    2601                 :            :     0,                          /*tp_iter*/
    2602                 :            :     0,                          /*tp_iternext*/
    2603                 :            :     PyCursesWindow_Methods,     /*tp_methods*/
    2604                 :            :     0,                          /* tp_members */
    2605                 :            :     PyCursesWindow_getsets,     /* tp_getset */
    2606                 :            : };
    2607                 :            : 
    2608                 :            : /* Function Prototype Macros - They are ugly but very, very useful. ;-)
    2609                 :            : 
    2610                 :            :    X - function name
    2611                 :            :    TYPE - parameter Type
    2612                 :            :    ERGSTR - format string for construction of the return value
    2613                 :            :    PARSESTR - format string for argument parsing
    2614                 :            :    */
    2615                 :            : 
    2616                 :            : #define NoArgNoReturnFunctionBody(X) \
    2617                 :            : { \
    2618                 :            :   PyCursesInitialised \
    2619                 :            :   return PyCursesCheckERR(X(), # X); }
    2620                 :            : 
    2621                 :            : #define NoArgOrFlagNoReturnFunctionBody(X, flag) \
    2622                 :            : { \
    2623                 :            :     PyCursesInitialised \
    2624                 :            :     if (flag) \
    2625                 :            :         return PyCursesCheckERR(X(), # X); \
    2626                 :            :     else \
    2627                 :            :         return PyCursesCheckERR(no ## X(), # X); \
    2628                 :            : }
    2629                 :            : 
    2630                 :            : #define NoArgReturnIntFunctionBody(X) \
    2631                 :            : { \
    2632                 :            :  PyCursesInitialised \
    2633                 :            :  return PyLong_FromLong((long) X()); }
    2634                 :            : 
    2635                 :            : 
    2636                 :            : #define NoArgReturnStringFunctionBody(X) \
    2637                 :            : { \
    2638                 :            :   PyCursesInitialised \
    2639                 :            :   return PyBytes_FromString(X()); }
    2640                 :            : 
    2641                 :            : #define NoArgTrueFalseFunctionBody(X) \
    2642                 :            : { \
    2643                 :            :   PyCursesInitialised \
    2644                 :            :   return PyBool_FromLong(X()); }
    2645                 :            : 
    2646                 :            : #define NoArgNoReturnVoidFunctionBody(X) \
    2647                 :            : { \
    2648                 :            :   PyCursesInitialised \
    2649                 :            :   X(); \
    2650                 :            :   Py_RETURN_NONE; }
    2651                 :            : 
    2652                 :            : /*********************************************************************
    2653                 :            :  Global Functions
    2654                 :            : **********************************************************************/
    2655                 :            : 
    2656                 :            : #ifdef HAVE_CURSES_FILTER
    2657                 :            : /*[clinic input]
    2658                 :            : _curses.filter
    2659                 :            : 
    2660                 :            : [clinic start generated code]*/
    2661                 :            : 
    2662                 :            : static PyObject *
    2663                 :          0 : _curses_filter_impl(PyObject *module)
    2664                 :            : /*[clinic end generated code: output=fb5b8a3642eb70b5 input=668c75a6992d3624]*/
    2665                 :            : {
    2666                 :            :     /* not checking for PyCursesInitialised here since filter() must
    2667                 :            :        be called before initscr() */
    2668                 :          0 :     filter();
    2669                 :          0 :     Py_RETURN_NONE;
    2670                 :            : }
    2671                 :            : #endif
    2672                 :            : 
    2673                 :            : /*[clinic input]
    2674                 :            : _curses.baudrate
    2675                 :            : 
    2676                 :            : Return the output speed of the terminal in bits per second.
    2677                 :            : [clinic start generated code]*/
    2678                 :            : 
    2679                 :            : static PyObject *
    2680                 :          0 : _curses_baudrate_impl(PyObject *module)
    2681                 :            : /*[clinic end generated code: output=3c63c6c401d7d9c0 input=921f022ed04a0fd9]*/
    2682         [ #  # ]:          0 : NoArgReturnIntFunctionBody(baudrate)
    2683                 :            : 
    2684                 :            : /*[clinic input]
    2685                 :            : _curses.beep
    2686                 :            : 
    2687                 :            : Emit a short attention sound.
    2688                 :            : [clinic start generated code]*/
    2689                 :            : 
    2690                 :            : static PyObject *
    2691                 :          0 : _curses_beep_impl(PyObject *module)
    2692                 :            : /*[clinic end generated code: output=425274962abe49a2 input=a35698ca7d0162bc]*/
    2693         [ #  # ]:          0 : NoArgNoReturnFunctionBody(beep)
    2694                 :            : 
    2695                 :            : /*[clinic input]
    2696                 :            : _curses.can_change_color
    2697                 :            : 
    2698                 :            : Return True if the programmer can change the colors displayed by the terminal.
    2699                 :            : [clinic start generated code]*/
    2700                 :            : 
    2701                 :            : static PyObject *
    2702                 :          0 : _curses_can_change_color_impl(PyObject *module)
    2703                 :            : /*[clinic end generated code: output=359df8c3c77d8bf1 input=d7718884de0092f2]*/
    2704         [ #  # ]:          0 : NoArgTrueFalseFunctionBody(can_change_color)
    2705                 :            : 
    2706                 :            : /*[clinic input]
    2707                 :            : _curses.cbreak
    2708                 :            : 
    2709                 :            :     flag: bool = True
    2710                 :            :         If false, the effect is the same as calling nocbreak().
    2711                 :            :     /
    2712                 :            : 
    2713                 :            : Enter cbreak mode.
    2714                 :            : 
    2715                 :            : In cbreak mode (sometimes called "rare" mode) normal tty line buffering is
    2716                 :            : turned off and characters are available to be read one by one.  However,
    2717                 :            : unlike raw mode, special characters (interrupt, quit, suspend, and flow
    2718                 :            : control) retain their effects on the tty driver and calling program.
    2719                 :            : Calling first raw() then cbreak() leaves the terminal in cbreak mode.
    2720                 :            : [clinic start generated code]*/
    2721                 :            : 
    2722                 :            : static PyObject *
    2723                 :          0 : _curses_cbreak_impl(PyObject *module, int flag)
    2724                 :            : /*[clinic end generated code: output=9f9dee9664769751 input=c7d0bddda93016c1]*/
    2725   [ #  #  #  # ]:          0 : NoArgOrFlagNoReturnFunctionBody(cbreak, flag)
    2726                 :            : 
    2727                 :            : /*[clinic input]
    2728                 :            : _curses.color_content
    2729                 :            : 
    2730                 :            :     color_number: color
    2731                 :            :         The number of the color (0 - (COLORS-1)).
    2732                 :            :     /
    2733                 :            : 
    2734                 :            : Return the red, green, and blue (RGB) components of the specified color.
    2735                 :            : 
    2736                 :            : A 3-tuple is returned, containing the R, G, B values for the given color,
    2737                 :            : which will be between 0 (no component) and 1000 (maximum amount of component).
    2738                 :            : [clinic start generated code]*/
    2739                 :            : 
    2740                 :            : static PyObject *
    2741                 :          0 : _curses_color_content_impl(PyObject *module, int color_number)
    2742                 :            : /*[clinic end generated code: output=17b466df7054e0de input=03b5ed0472662aea]*/
    2743                 :            : {
    2744                 :            :     _CURSES_COLOR_VAL_TYPE r,g,b;
    2745                 :            : 
    2746         [ #  # ]:          0 :     PyCursesInitialised;
    2747         [ #  # ]:          0 :     PyCursesInitialisedColor;
    2748                 :            : 
    2749         [ #  # ]:          0 :     if (_COLOR_CONTENT_FUNC(color_number, &r, &g, &b) == ERR) {
    2750                 :          0 :         PyErr_Format(PyCursesError, "%s() returned ERR",
    2751                 :            :                         Py_STRINGIFY(_COLOR_CONTENT_FUNC));
    2752                 :          0 :         return NULL;
    2753                 :            :     }
    2754                 :            : 
    2755                 :          0 :     return Py_BuildValue("(iii)", r, g, b);
    2756                 :            : }
    2757                 :            : 
    2758                 :            : /*[clinic input]
    2759                 :            : _curses.color_pair
    2760                 :            : 
    2761                 :            :     pair_number: int
    2762                 :            :         The number of the color pair.
    2763                 :            :     /
    2764                 :            : 
    2765                 :            : Return the attribute value for displaying text in the specified color.
    2766                 :            : 
    2767                 :            : This attribute value can be combined with A_STANDOUT, A_REVERSE, and the
    2768                 :            : other A_* attributes.  pair_number() is the counterpart to this function.
    2769                 :            : [clinic start generated code]*/
    2770                 :            : 
    2771                 :            : static PyObject *
    2772                 :          0 : _curses_color_pair_impl(PyObject *module, int pair_number)
    2773                 :            : /*[clinic end generated code: output=60718abb10ce9feb input=6034e9146f343802]*/
    2774                 :            : {
    2775         [ #  # ]:          0 :     PyCursesInitialised;
    2776         [ #  # ]:          0 :     PyCursesInitialisedColor;
    2777                 :            : 
    2778                 :          0 :     return  PyLong_FromLong(COLOR_PAIR(pair_number));
    2779                 :            : }
    2780                 :            : 
    2781                 :            : /*[clinic input]
    2782                 :            : _curses.curs_set
    2783                 :            : 
    2784                 :            :     visibility: int
    2785                 :            :         0 for invisible, 1 for normal visible, or 2 for very visible.
    2786                 :            :     /
    2787                 :            : 
    2788                 :            : Set the cursor state.
    2789                 :            : 
    2790                 :            : If the terminal supports the visibility requested, the previous cursor
    2791                 :            : state is returned; otherwise, an exception is raised.  On many terminals,
    2792                 :            : the "visible" mode is an underline cursor and the "very visible" mode is
    2793                 :            : a block cursor.
    2794                 :            : [clinic start generated code]*/
    2795                 :            : 
    2796                 :            : static PyObject *
    2797                 :          0 : _curses_curs_set_impl(PyObject *module, int visibility)
    2798                 :            : /*[clinic end generated code: output=ee8e62483b1d6cd4 input=81a7924a65d29504]*/
    2799                 :            : {
    2800                 :            :     int erg;
    2801                 :            : 
    2802         [ #  # ]:          0 :     PyCursesInitialised;
    2803                 :            : 
    2804                 :          0 :     erg = curs_set(visibility);
    2805         [ #  # ]:          0 :     if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
    2806                 :            : 
    2807                 :          0 :     return PyLong_FromLong((long) erg);
    2808                 :            : }
    2809                 :            : 
    2810                 :            : /*[clinic input]
    2811                 :            : _curses.def_prog_mode
    2812                 :            : 
    2813                 :            : Save the current terminal mode as the "program" mode.
    2814                 :            : 
    2815                 :            : The "program" mode is the mode when the running program is using curses.
    2816                 :            : 
    2817                 :            : Subsequent calls to reset_prog_mode() will restore this mode.
    2818                 :            : [clinic start generated code]*/
    2819                 :            : 
    2820                 :            : static PyObject *
    2821                 :          0 : _curses_def_prog_mode_impl(PyObject *module)
    2822                 :            : /*[clinic end generated code: output=05d5a351fff874aa input=768b9cace620dda5]*/
    2823         [ #  # ]:          0 : NoArgNoReturnFunctionBody(def_prog_mode)
    2824                 :            : 
    2825                 :            : /*[clinic input]
    2826                 :            : _curses.def_shell_mode
    2827                 :            : 
    2828                 :            : Save the current terminal mode as the "shell" mode.
    2829                 :            : 
    2830                 :            : The "shell" mode is the mode when the running program is not using curses.
    2831                 :            : 
    2832                 :            : Subsequent calls to reset_shell_mode() will restore this mode.
    2833                 :            : [clinic start generated code]*/
    2834                 :            : 
    2835                 :            : static PyObject *
    2836                 :          0 : _curses_def_shell_mode_impl(PyObject *module)
    2837                 :            : /*[clinic end generated code: output=d6e42f5c768f860f input=5ead21f6f0baa894]*/
    2838         [ #  # ]:          0 : NoArgNoReturnFunctionBody(def_shell_mode)
    2839                 :            : 
    2840                 :            : /*[clinic input]
    2841                 :            : _curses.delay_output
    2842                 :            : 
    2843                 :            :     ms: int
    2844                 :            :         Duration in milliseconds.
    2845                 :            :     /
    2846                 :            : 
    2847                 :            : Insert a pause in output.
    2848                 :            : [clinic start generated code]*/
    2849                 :            : 
    2850                 :            : static PyObject *
    2851                 :          0 : _curses_delay_output_impl(PyObject *module, int ms)
    2852                 :            : /*[clinic end generated code: output=b6613a67f17fa4f4 input=5316457f5f59196c]*/
    2853                 :            : {
    2854         [ #  # ]:          0 :     PyCursesInitialised;
    2855                 :            : 
    2856                 :          0 :     return PyCursesCheckERR(delay_output(ms), "delay_output");
    2857                 :            : }
    2858                 :            : 
    2859                 :            : /*[clinic input]
    2860                 :            : _curses.doupdate
    2861                 :            : 
    2862                 :            : Update the physical screen to match the virtual screen.
    2863                 :            : [clinic start generated code]*/
    2864                 :            : 
    2865                 :            : static PyObject *
    2866                 :          0 : _curses_doupdate_impl(PyObject *module)
    2867                 :            : /*[clinic end generated code: output=f34536975a75680c input=8da80914432a6489]*/
    2868         [ #  # ]:          0 : NoArgNoReturnFunctionBody(doupdate)
    2869                 :            : 
    2870                 :            : /*[clinic input]
    2871                 :            : _curses.echo
    2872                 :            : 
    2873                 :            :     flag: bool = True
    2874                 :            :         If false, the effect is the same as calling noecho().
    2875                 :            :     /
    2876                 :            : 
    2877                 :            : Enter echo mode.
    2878                 :            : 
    2879                 :            : In echo mode, each character input is echoed to the screen as it is entered.
    2880                 :            : [clinic start generated code]*/
    2881                 :            : 
    2882                 :            : static PyObject *
    2883                 :          0 : _curses_echo_impl(PyObject *module, int flag)
    2884                 :            : /*[clinic end generated code: output=03acb2ddfa6c8729 input=86cd4d5bb1d569c0]*/
    2885   [ #  #  #  # ]:          0 : NoArgOrFlagNoReturnFunctionBody(echo, flag)
    2886                 :            : 
    2887                 :            : /*[clinic input]
    2888                 :            : _curses.endwin
    2889                 :            : 
    2890                 :            : De-initialize the library, and return terminal to normal status.
    2891                 :            : [clinic start generated code]*/
    2892                 :            : 
    2893                 :            : static PyObject *
    2894                 :          0 : _curses_endwin_impl(PyObject *module)
    2895                 :            : /*[clinic end generated code: output=c0150cd96d2f4128 input=e172cfa43062f3fa]*/
    2896         [ #  # ]:          0 : NoArgNoReturnFunctionBody(endwin)
    2897                 :            : 
    2898                 :            : /*[clinic input]
    2899                 :            : _curses.erasechar
    2900                 :            : 
    2901                 :            : Return the user's current erase character.
    2902                 :            : [clinic start generated code]*/
    2903                 :            : 
    2904                 :            : static PyObject *
    2905                 :          0 : _curses_erasechar_impl(PyObject *module)
    2906                 :            : /*[clinic end generated code: output=3df305dc6b926b3f input=628c136c3c5758d3]*/
    2907                 :            : {
    2908                 :            :     char ch;
    2909                 :            : 
    2910         [ #  # ]:          0 :     PyCursesInitialised;
    2911                 :            : 
    2912                 :          0 :     ch = erasechar();
    2913                 :            : 
    2914                 :          0 :     return PyBytes_FromStringAndSize(&ch, 1);
    2915                 :            : }
    2916                 :            : 
    2917                 :            : /*[clinic input]
    2918                 :            : _curses.flash
    2919                 :            : 
    2920                 :            : Flash the screen.
    2921                 :            : 
    2922                 :            : That is, change it to reverse-video and then change it back in a short interval.
    2923                 :            : [clinic start generated code]*/
    2924                 :            : 
    2925                 :            : static PyObject *
    2926                 :          0 : _curses_flash_impl(PyObject *module)
    2927                 :            : /*[clinic end generated code: output=488b8a0ebd9ea9b8 input=02fdfb06c8fc3171]*/
    2928         [ #  # ]:          0 : NoArgNoReturnFunctionBody(flash)
    2929                 :            : 
    2930                 :            : /*[clinic input]
    2931                 :            : _curses.flushinp
    2932                 :            : 
    2933                 :            : Flush all input buffers.
    2934                 :            : 
    2935                 :            : This throws away any typeahead that has been typed by the user and has not
    2936                 :            : yet been processed by the program.
    2937                 :            : [clinic start generated code]*/
    2938                 :            : 
    2939                 :            : static PyObject *
    2940                 :          0 : _curses_flushinp_impl(PyObject *module)
    2941                 :            : /*[clinic end generated code: output=7e7a1fc1473960f5 input=59d042e705cef5ec]*/
    2942         [ #  # ]:          0 : NoArgNoReturnVoidFunctionBody(flushinp)
    2943                 :            : 
    2944                 :            : #ifdef getsyx
    2945                 :            : /*[clinic input]
    2946                 :            : _curses.getsyx
    2947                 :            : 
    2948                 :            : Return the current coordinates of the virtual screen cursor.
    2949                 :            : 
    2950                 :            : Return a (y, x) tuple.  If leaveok is currently true, return (-1, -1).
    2951                 :            : [clinic start generated code]*/
    2952                 :            : 
    2953                 :            : static PyObject *
    2954                 :          0 : _curses_getsyx_impl(PyObject *module)
    2955                 :            : /*[clinic end generated code: output=c8e6c3f42349a038 input=9e1f862f3b4f7cba]*/
    2956                 :            : {
    2957                 :          0 :     int x = 0;
    2958                 :          0 :     int y = 0;
    2959                 :            : 
    2960         [ #  # ]:          0 :     PyCursesInitialised;
    2961                 :            : 
    2962   [ #  #  #  #  :          0 :     getsyx(y, x);
          #  #  #  #  #  
                      # ]
    2963                 :            : 
    2964                 :          0 :     return Py_BuildValue("(ii)", y, x);
    2965                 :            : }
    2966                 :            : #endif
    2967                 :            : 
    2968                 :            : #ifdef NCURSES_MOUSE_VERSION
    2969                 :            : /*[clinic input]
    2970                 :            : _curses.getmouse
    2971                 :            : 
    2972                 :            : Retrieve the queued mouse event.
    2973                 :            : 
    2974                 :            : After getch() returns KEY_MOUSE to signal a mouse event, this function
    2975                 :            : returns a 5-tuple (id, x, y, z, bstate).
    2976                 :            : [clinic start generated code]*/
    2977                 :            : 
    2978                 :            : static PyObject *
    2979                 :          0 : _curses_getmouse_impl(PyObject *module)
    2980                 :            : /*[clinic end generated code: output=ccf4242546b9cfa8 input=5b756ee6f5b481b1]*/
    2981                 :            : {
    2982                 :            :     int rtn;
    2983                 :            :     MEVENT event;
    2984                 :            : 
    2985         [ #  # ]:          0 :     PyCursesInitialised;
    2986                 :            : 
    2987                 :          0 :     rtn = getmouse( &event );
    2988         [ #  # ]:          0 :     if (rtn == ERR) {
    2989                 :          0 :         PyErr_SetString(PyCursesError, "getmouse() returned ERR");
    2990                 :          0 :         return NULL;
    2991                 :            :     }
    2992                 :          0 :     return Py_BuildValue("(hiiik)",
    2993                 :          0 :                          (short)event.id,
    2994                 :            :                          (int)event.x, (int)event.y, (int)event.z,
    2995                 :          0 :                          (unsigned long) event.bstate);
    2996                 :            : }
    2997                 :            : 
    2998                 :            : /*[clinic input]
    2999                 :            : _curses.ungetmouse
    3000                 :            : 
    3001                 :            :     id: short
    3002                 :            :     x: int
    3003                 :            :     y: int
    3004                 :            :     z: int
    3005                 :            :     bstate: unsigned_long(bitwise=True)
    3006                 :            :     /
    3007                 :            : 
    3008                 :            : Push a KEY_MOUSE event onto the input queue.
    3009                 :            : 
    3010                 :            : The following getmouse() will return the given state data.
    3011                 :            : [clinic start generated code]*/
    3012                 :            : 
    3013                 :            : static PyObject *
    3014                 :          0 : _curses_ungetmouse_impl(PyObject *module, short id, int x, int y, int z,
    3015                 :            :                         unsigned long bstate)
    3016                 :            : /*[clinic end generated code: output=3430c9b0fc5c4341 input=fd650b2ca5a01e8f]*/
    3017                 :            : {
    3018                 :            :     MEVENT event;
    3019                 :            : 
    3020         [ #  # ]:          0 :     PyCursesInitialised;
    3021                 :            : 
    3022                 :          0 :     event.id = id;
    3023                 :          0 :     event.x = x;
    3024                 :          0 :     event.y = y;
    3025                 :          0 :     event.z = z;
    3026                 :          0 :     event.bstate = bstate;
    3027                 :          0 :     return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
    3028                 :            : }
    3029                 :            : #endif
    3030                 :            : 
    3031                 :            : /*[clinic input]
    3032                 :            : _curses.getwin
    3033                 :            : 
    3034                 :            :     file: object
    3035                 :            :     /
    3036                 :            : 
    3037                 :            : Read window related data stored in the file by an earlier putwin() call.
    3038                 :            : 
    3039                 :            : The routine then creates and initializes a new window using that data,
    3040                 :            : returning the new window object.
    3041                 :            : [clinic start generated code]*/
    3042                 :            : 
    3043                 :            : static PyObject *
    3044                 :          0 : _curses_getwin(PyObject *module, PyObject *file)
    3045                 :            : /*[clinic end generated code: output=a79e0df3379af756 input=f713d2bba0e4c929]*/
    3046                 :            : {
    3047                 :            :     FILE *fp;
    3048                 :            :     PyObject *data;
    3049                 :            :     size_t datalen;
    3050                 :            :     WINDOW *win;
    3051                 :          0 :     PyObject *res = NULL;
    3052                 :            : 
    3053         [ #  # ]:          0 :     PyCursesInitialised;
    3054                 :            : 
    3055                 :          0 :     fp = tmpfile();
    3056         [ #  # ]:          0 :     if (fp == NULL)
    3057                 :          0 :         return PyErr_SetFromErrno(PyExc_OSError);
    3058                 :            : 
    3059         [ #  # ]:          0 :     if (_Py_set_inheritable(fileno(fp), 0, NULL) < 0)
    3060                 :          0 :         goto error;
    3061                 :            : 
    3062                 :          0 :     data = PyObject_CallMethod(file, "read", NULL);
    3063         [ #  # ]:          0 :     if (data == NULL)
    3064                 :          0 :         goto error;
    3065         [ #  # ]:          0 :     if (!PyBytes_Check(data)) {
    3066                 :          0 :         PyErr_Format(PyExc_TypeError,
    3067                 :            :                      "f.read() returned %.100s instead of bytes",
    3068                 :          0 :                      Py_TYPE(data)->tp_name);
    3069                 :          0 :         Py_DECREF(data);
    3070                 :          0 :         goto error;
    3071                 :            :     }
    3072                 :          0 :     datalen = PyBytes_GET_SIZE(data);
    3073         [ #  # ]:          0 :     if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) {
    3074                 :          0 :         Py_DECREF(data);
    3075                 :          0 :         PyErr_SetFromErrno(PyExc_OSError);
    3076                 :          0 :         goto error;
    3077                 :            :     }
    3078                 :          0 :     Py_DECREF(data);
    3079                 :            : 
    3080                 :          0 :     fseek(fp, 0, 0);
    3081                 :          0 :     win = getwin(fp);
    3082         [ #  # ]:          0 :     if (win == NULL) {
    3083                 :          0 :         PyErr_SetString(PyCursesError, catchall_NULL);
    3084                 :          0 :         goto error;
    3085                 :            :     }
    3086                 :          0 :     res = PyCursesWindow_New(win, NULL);
    3087                 :            : 
    3088                 :          0 : error:
    3089                 :          0 :     fclose(fp);
    3090                 :          0 :     return res;
    3091                 :            : }
    3092                 :            : 
    3093                 :            : /*[clinic input]
    3094                 :            : _curses.halfdelay
    3095                 :            : 
    3096                 :            :     tenths: byte
    3097                 :            :         Maximal blocking delay in tenths of seconds (1 - 255).
    3098                 :            :     /
    3099                 :            : 
    3100                 :            : Enter half-delay mode.
    3101                 :            : 
    3102                 :            : Use nocbreak() to leave half-delay mode.
    3103                 :            : [clinic start generated code]*/
    3104                 :            : 
    3105                 :            : static PyObject *
    3106                 :          0 : _curses_halfdelay_impl(PyObject *module, unsigned char tenths)
    3107                 :            : /*[clinic end generated code: output=e92cdf0ef33c0663 input=e42dce7259c15100]*/
    3108                 :            : {
    3109         [ #  # ]:          0 :     PyCursesInitialised;
    3110                 :            : 
    3111                 :          0 :     return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
    3112                 :            : }
    3113                 :            : 
    3114                 :            : /*[clinic input]
    3115                 :            : _curses.has_colors
    3116                 :            : 
    3117                 :            : Return True if the terminal can display colors; otherwise, return False.
    3118                 :            : [clinic start generated code]*/
    3119                 :            : 
    3120                 :            : static PyObject *
    3121                 :          0 : _curses_has_colors_impl(PyObject *module)
    3122                 :            : /*[clinic end generated code: output=db5667483139e3e2 input=b2ec41b739d896c6]*/
    3123         [ #  # ]:          0 : NoArgTrueFalseFunctionBody(has_colors)
    3124                 :            : 
    3125                 :            : /*[clinic input]
    3126                 :            : _curses.has_ic
    3127                 :            : 
    3128                 :            : Return True if the terminal has insert- and delete-character capabilities.
    3129                 :            : [clinic start generated code]*/
    3130                 :            : 
    3131                 :            : static PyObject *
    3132                 :          0 : _curses_has_ic_impl(PyObject *module)
    3133                 :            : /*[clinic end generated code: output=6be24da9cb1268fe input=9bc2d3a797cc7324]*/
    3134         [ #  # ]:          0 : NoArgTrueFalseFunctionBody(has_ic)
    3135                 :            : 
    3136                 :            : /*[clinic input]
    3137                 :            : _curses.has_il
    3138                 :            : 
    3139                 :            : Return True if the terminal has insert- and delete-line capabilities.
    3140                 :            : [clinic start generated code]*/
    3141                 :            : 
    3142                 :            : static PyObject *
    3143                 :          0 : _curses_has_il_impl(PyObject *module)
    3144                 :            : /*[clinic end generated code: output=d45bd7788ff9f5f4 input=cd939d5607ee5427]*/
    3145         [ #  # ]:          0 : NoArgTrueFalseFunctionBody(has_il)
    3146                 :            : 
    3147                 :            : #ifdef HAVE_CURSES_HAS_KEY
    3148                 :            : /*[clinic input]
    3149                 :            : _curses.has_key
    3150                 :            : 
    3151                 :            :     key: int
    3152                 :            :         Key number.
    3153                 :            :     /
    3154                 :            : 
    3155                 :            : Return True if the current terminal type recognizes a key with that value.
    3156                 :            : [clinic start generated code]*/
    3157                 :            : 
    3158                 :            : static PyObject *
    3159                 :          0 : _curses_has_key_impl(PyObject *module, int key)
    3160                 :            : /*[clinic end generated code: output=19ad48319414d0b1 input=78bd44acf1a4997c]*/
    3161                 :            : {
    3162         [ #  # ]:          0 :     PyCursesInitialised;
    3163                 :            : 
    3164                 :          0 :     return PyBool_FromLong(has_key(key));
    3165                 :            : }
    3166                 :            : #endif
    3167                 :            : 
    3168                 :            : /*[clinic input]
    3169                 :            : _curses.init_color
    3170                 :            : 
    3171                 :            :     color_number: color
    3172                 :            :         The number of the color to be changed (0 - (COLORS-1)).
    3173                 :            :     r: component
    3174                 :            :         Red component (0 - 1000).
    3175                 :            :     g: component
    3176                 :            :         Green component (0 - 1000).
    3177                 :            :     b: component
    3178                 :            :         Blue component (0 - 1000).
    3179                 :            :     /
    3180                 :            : 
    3181                 :            : Change the definition of a color.
    3182                 :            : 
    3183                 :            : When init_color() is used, all occurrences of that color on the screen
    3184                 :            : immediately change to the new definition.  This function is a no-op on
    3185                 :            : most terminals; it is active only if can_change_color() returns true.
    3186                 :            : [clinic start generated code]*/
    3187                 :            : 
    3188                 :            : static PyObject *
    3189                 :          0 : _curses_init_color_impl(PyObject *module, int color_number, short r, short g,
    3190                 :            :                         short b)
    3191                 :            : /*[clinic end generated code: output=d7ed71b2d818cdf2 input=ae2b8bea0f152c80]*/
    3192                 :            : {
    3193         [ #  # ]:          0 :     PyCursesInitialised;
    3194         [ #  # ]:          0 :     PyCursesInitialisedColor;
    3195                 :            : 
    3196                 :          0 :     return PyCursesCheckERR(_CURSES_INIT_COLOR_FUNC(color_number, r, g, b),
    3197                 :            :                             Py_STRINGIFY(_CURSES_INIT_COLOR_FUNC));
    3198                 :            : }
    3199                 :            : 
    3200                 :            : /*[clinic input]
    3201                 :            : _curses.init_pair
    3202                 :            : 
    3203                 :            :     pair_number: pair
    3204                 :            :         The number of the color-pair to be changed (1 - (COLOR_PAIRS-1)).
    3205                 :            :     fg: color_allow_default
    3206                 :            :         Foreground color number (-1 - (COLORS-1)).
    3207                 :            :     bg: color_allow_default
    3208                 :            :         Background color number (-1 - (COLORS-1)).
    3209                 :            :     /
    3210                 :            : 
    3211                 :            : Change the definition of a color-pair.
    3212                 :            : 
    3213                 :            : If the color-pair was previously initialized, the screen is refreshed and
    3214                 :            : all occurrences of that color-pair are changed to the new definition.
    3215                 :            : [clinic start generated code]*/
    3216                 :            : 
    3217                 :            : static PyObject *
    3218                 :          0 : _curses_init_pair_impl(PyObject *module, int pair_number, int fg, int bg)
    3219                 :            : /*[clinic end generated code: output=a0bba03d2bbc3ee6 input=54b421b44c12c389]*/
    3220                 :            : {
    3221         [ #  # ]:          0 :     PyCursesInitialised;
    3222         [ #  # ]:          0 :     PyCursesInitialisedColor;
    3223                 :            : 
    3224         [ #  # ]:          0 :     if (_CURSES_INIT_PAIR_FUNC(pair_number, fg, bg) == ERR) {
    3225         [ #  # ]:          0 :         if (pair_number >= COLOR_PAIRS) {
    3226                 :          0 :             PyErr_Format(PyExc_ValueError,
    3227                 :            :                          "Color pair is greater than COLOR_PAIRS-1 (%d).",
    3228                 :            :                          COLOR_PAIRS - 1);
    3229                 :            :         }
    3230                 :            :         else {
    3231                 :          0 :             PyErr_Format(PyCursesError, "%s() returned ERR",
    3232                 :            :                          Py_STRINGIFY(_CURSES_INIT_PAIR_FUNC));
    3233                 :            :         }
    3234                 :          0 :         return NULL;
    3235                 :            :     }
    3236                 :            : 
    3237                 :          0 :     Py_RETURN_NONE;
    3238                 :            : }
    3239                 :            : 
    3240                 :            : static PyObject *ModDict;
    3241                 :            : 
    3242                 :            : /*[clinic input]
    3243                 :            : _curses.initscr
    3244                 :            : 
    3245                 :            : Initialize the library.
    3246                 :            : 
    3247                 :            : Return a WindowObject which represents the whole screen.
    3248                 :            : [clinic start generated code]*/
    3249                 :            : 
    3250                 :            : static PyObject *
    3251                 :          0 : _curses_initscr_impl(PyObject *module)
    3252                 :            : /*[clinic end generated code: output=619fb68443810b7b input=514f4bce1821f6b5]*/
    3253                 :            : {
    3254                 :            :     WINDOW *win;
    3255                 :            :     PyCursesWindowObject *winobj;
    3256                 :            : 
    3257         [ #  # ]:          0 :     if (initialised) {
    3258                 :          0 :         wrefresh(stdscr);
    3259                 :          0 :         return (PyObject *)PyCursesWindow_New(stdscr, NULL);
    3260                 :            :     }
    3261                 :            : 
    3262                 :          0 :     win = initscr();
    3263                 :            : 
    3264         [ #  # ]:          0 :     if (win == NULL) {
    3265                 :          0 :         PyErr_SetString(PyCursesError, catchall_NULL);
    3266                 :          0 :         return NULL;
    3267                 :            :     }
    3268                 :            : 
    3269                 :          0 :     initialised = initialised_setupterm = TRUE;
    3270                 :            : 
    3271                 :            : /* This was moved from initcurses() because it core dumped on SGI,
    3272                 :            :    where they're not defined until you've called initscr() */
    3273                 :            : #define SetDictInt(string,ch)                                           \
    3274                 :            :     do {                                                                \
    3275                 :            :         PyObject *o = PyLong_FromLong((long) (ch));                     \
    3276                 :            :         if (o && PyDict_SetItemString(ModDict, string, o) == 0)     {   \
    3277                 :            :             Py_DECREF(o);                                               \
    3278                 :            :         }                                                               \
    3279                 :            :     } while (0)
    3280                 :            : 
    3281                 :            :     /* Here are some graphic symbols you can use */
    3282   [ #  #  #  # ]:          0 :     SetDictInt("ACS_ULCORNER",      (ACS_ULCORNER));
    3283   [ #  #  #  # ]:          0 :     SetDictInt("ACS_LLCORNER",      (ACS_LLCORNER));
    3284   [ #  #  #  # ]:          0 :     SetDictInt("ACS_URCORNER",      (ACS_URCORNER));
    3285   [ #  #  #  # ]:          0 :     SetDictInt("ACS_LRCORNER",      (ACS_LRCORNER));
    3286   [ #  #  #  # ]:          0 :     SetDictInt("ACS_LTEE",          (ACS_LTEE));
    3287   [ #  #  #  # ]:          0 :     SetDictInt("ACS_RTEE",          (ACS_RTEE));
    3288   [ #  #  #  # ]:          0 :     SetDictInt("ACS_BTEE",          (ACS_BTEE));
    3289   [ #  #  #  # ]:          0 :     SetDictInt("ACS_TTEE",          (ACS_TTEE));
    3290   [ #  #  #  # ]:          0 :     SetDictInt("ACS_HLINE",         (ACS_HLINE));
    3291   [ #  #  #  # ]:          0 :     SetDictInt("ACS_VLINE",         (ACS_VLINE));
    3292   [ #  #  #  # ]:          0 :     SetDictInt("ACS_PLUS",          (ACS_PLUS));
    3293                 :            : #if !defined(__hpux) || defined(HAVE_NCURSES_H)
    3294                 :            :     /* On HP/UX 11, these are of type cchar_t, which is not an
    3295                 :            :        integral type. If this is a problem on more platforms, a
    3296                 :            :        configure test should be added to determine whether ACS_S1
    3297                 :            :        is of integral type. */
    3298   [ #  #  #  # ]:          0 :     SetDictInt("ACS_S1",            (ACS_S1));
    3299   [ #  #  #  # ]:          0 :     SetDictInt("ACS_S9",            (ACS_S9));
    3300   [ #  #  #  # ]:          0 :     SetDictInt("ACS_DIAMOND",       (ACS_DIAMOND));
    3301   [ #  #  #  # ]:          0 :     SetDictInt("ACS_CKBOARD",       (ACS_CKBOARD));
    3302   [ #  #  #  # ]:          0 :     SetDictInt("ACS_DEGREE",        (ACS_DEGREE));
    3303   [ #  #  #  # ]:          0 :     SetDictInt("ACS_PLMINUS",       (ACS_PLMINUS));
    3304   [ #  #  #  # ]:          0 :     SetDictInt("ACS_BULLET",        (ACS_BULLET));
    3305   [ #  #  #  # ]:          0 :     SetDictInt("ACS_LARROW",        (ACS_LARROW));
    3306   [ #  #  #  # ]:          0 :     SetDictInt("ACS_RARROW",        (ACS_RARROW));
    3307   [ #  #  #  # ]:          0 :     SetDictInt("ACS_DARROW",        (ACS_DARROW));
    3308   [ #  #  #  # ]:          0 :     SetDictInt("ACS_UARROW",        (ACS_UARROW));
    3309   [ #  #  #  # ]:          0 :     SetDictInt("ACS_BOARD",         (ACS_BOARD));
    3310   [ #  #  #  # ]:          0 :     SetDictInt("ACS_LANTERN",       (ACS_LANTERN));
    3311   [ #  #  #  # ]:          0 :     SetDictInt("ACS_BLOCK",         (ACS_BLOCK));
    3312                 :            : #endif
    3313   [ #  #  #  # ]:          0 :     SetDictInt("ACS_BSSB",          (ACS_ULCORNER));
    3314   [ #  #  #  # ]:          0 :     SetDictInt("ACS_SSBB",          (ACS_LLCORNER));
    3315   [ #  #  #  # ]:          0 :     SetDictInt("ACS_BBSS",          (ACS_URCORNER));
    3316   [ #  #  #  # ]:          0 :     SetDictInt("ACS_SBBS",          (ACS_LRCORNER));
    3317   [ #  #  #  # ]:          0 :     SetDictInt("ACS_SBSS",          (ACS_RTEE));
    3318   [ #  #  #  # ]:          0 :     SetDictInt("ACS_SSSB",          (ACS_LTEE));
    3319   [ #  #  #  # ]:          0 :     SetDictInt("ACS_SSBS",          (ACS_BTEE));
    3320   [ #  #  #  # ]:          0 :     SetDictInt("ACS_BSSS",          (ACS_TTEE));
    3321   [ #  #  #  # ]:          0 :     SetDictInt("ACS_BSBS",          (ACS_HLINE));
    3322   [ #  #  #  # ]:          0 :     SetDictInt("ACS_SBSB",          (ACS_VLINE));
    3323   [ #  #  #  # ]:          0 :     SetDictInt("ACS_SSSS",          (ACS_PLUS));
    3324                 :            : 
    3325                 :            :     /* The following are never available with strict SYSV curses */
    3326                 :            : #ifdef ACS_S3
    3327   [ #  #  #  # ]:          0 :     SetDictInt("ACS_S3",            (ACS_S3));
    3328                 :            : #endif
    3329                 :            : #ifdef ACS_S7
    3330   [ #  #  #  # ]:          0 :     SetDictInt("ACS_S7",            (ACS_S7));
    3331                 :            : #endif
    3332                 :            : #ifdef ACS_LEQUAL
    3333   [ #  #  #  # ]:          0 :     SetDictInt("ACS_LEQUAL",        (ACS_LEQUAL));
    3334                 :            : #endif
    3335                 :            : #ifdef ACS_GEQUAL
    3336   [ #  #  #  # ]:          0 :     SetDictInt("ACS_GEQUAL",        (ACS_GEQUAL));
    3337                 :            : #endif
    3338                 :            : #ifdef ACS_PI
    3339   [ #  #  #  # ]:          0 :     SetDictInt("ACS_PI",            (ACS_PI));
    3340                 :            : #endif
    3341                 :            : #ifdef ACS_NEQUAL
    3342   [ #  #  #  # ]:          0 :     SetDictInt("ACS_NEQUAL",        (ACS_NEQUAL));
    3343                 :            : #endif
    3344                 :            : #ifdef ACS_STERLING
    3345   [ #  #  #  # ]:          0 :     SetDictInt("ACS_STERLING",      (ACS_STERLING));
    3346                 :            : #endif
    3347                 :            : 
    3348   [ #  #  #  # ]:          0 :     SetDictInt("LINES", LINES);
    3349   [ #  #  #  # ]:          0 :     SetDictInt("COLS", COLS);
    3350                 :            : 
    3351                 :          0 :     winobj = (PyCursesWindowObject *)PyCursesWindow_New(win, NULL);
    3352                 :          0 :     screen_encoding = winobj->encoding;
    3353                 :          0 :     return (PyObject *)winobj;
    3354                 :            : }
    3355                 :            : 
    3356                 :            : /*[clinic input]
    3357                 :            : _curses.setupterm
    3358                 :            : 
    3359                 :            :     term: str(accept={str, NoneType}) = None
    3360                 :            :         Terminal name.
    3361                 :            :         If omitted, the value of the TERM environment variable will be used.
    3362                 :            :     fd: int = -1
    3363                 :            :         File descriptor to which any initialization sequences will be sent.
    3364                 :            :         If not supplied, the file descriptor for sys.stdout will be used.
    3365                 :            : 
    3366                 :            : Initialize the terminal.
    3367                 :            : [clinic start generated code]*/
    3368                 :            : 
    3369                 :            : static PyObject *
    3370                 :          0 : _curses_setupterm_impl(PyObject *module, const char *term, int fd)
    3371                 :            : /*[clinic end generated code: output=4584e587350f2848 input=4511472766af0c12]*/
    3372                 :            : {
    3373                 :            :     int err;
    3374                 :            : 
    3375         [ #  # ]:          0 :     if (fd == -1) {
    3376                 :            :         PyObject* sys_stdout;
    3377                 :            : 
    3378                 :          0 :         sys_stdout = PySys_GetObject("stdout");
    3379                 :            : 
    3380   [ #  #  #  # ]:          0 :         if (sys_stdout == NULL || sys_stdout == Py_None) {
    3381                 :          0 :             PyErr_SetString(
    3382                 :            :                 PyCursesError,
    3383                 :            :                 "lost sys.stdout");
    3384                 :          0 :             return NULL;
    3385                 :            :         }
    3386                 :            : 
    3387                 :          0 :         fd = PyObject_AsFileDescriptor(sys_stdout);
    3388                 :            : 
    3389         [ #  # ]:          0 :         if (fd == -1) {
    3390                 :          0 :             return NULL;
    3391                 :            :         }
    3392                 :            :     }
    3393                 :            : 
    3394   [ #  #  #  # ]:          0 :     if (!initialised_setupterm && setupterm((char *)term, fd, &err) == ERR) {
    3395                 :          0 :         const char* s = "setupterm: unknown error";
    3396                 :            : 
    3397         [ #  # ]:          0 :         if (err == 0) {
    3398                 :          0 :             s = "setupterm: could not find terminal";
    3399         [ #  # ]:          0 :         } else if (err == -1) {
    3400                 :          0 :             s = "setupterm: could not find terminfo database";
    3401                 :            :         }
    3402                 :            : 
    3403                 :          0 :         PyErr_SetString(PyCursesError,s);
    3404                 :          0 :         return NULL;
    3405                 :            :     }
    3406                 :            : 
    3407                 :          0 :     initialised_setupterm = TRUE;
    3408                 :            : 
    3409                 :          0 :     Py_RETURN_NONE;
    3410                 :            : }
    3411                 :            : 
    3412                 :            : #if defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102
    3413                 :            : // https://invisible-island.net/ncurses/NEWS.html#index-t20080119
    3414                 :            : 
    3415                 :            : /*[clinic input]
    3416                 :            : _curses.get_escdelay
    3417                 :            : 
    3418                 :            : Gets the curses ESCDELAY setting.
    3419                 :            : 
    3420                 :            : Gets the number of milliseconds to wait after reading an escape character,
    3421                 :            : to distinguish between an individual escape character entered on the
    3422                 :            : keyboard from escape sequences sent by cursor and function keys.
    3423                 :            : [clinic start generated code]*/
    3424                 :            : 
    3425                 :            : static PyObject *
    3426                 :          0 : _curses_get_escdelay_impl(PyObject *module)
    3427                 :            : /*[clinic end generated code: output=222fa1a822555d60 input=be2d5b3dd974d0a4]*/
    3428                 :            : {
    3429                 :          0 :     return PyLong_FromLong(ESCDELAY);
    3430                 :            : }
    3431                 :            : /*[clinic input]
    3432                 :            : _curses.set_escdelay
    3433                 :            :     ms: int
    3434                 :            :         length of the delay in milliseconds.
    3435                 :            :     /
    3436                 :            : 
    3437                 :            : Sets the curses ESCDELAY setting.
    3438                 :            : 
    3439                 :            : Sets the number of milliseconds to wait after reading an escape character,
    3440                 :            : to distinguish between an individual escape character entered on the
    3441                 :            : keyboard from escape sequences sent by cursor and function keys.
    3442                 :            : [clinic start generated code]*/
    3443                 :            : 
    3444                 :            : static PyObject *
    3445                 :          0 : _curses_set_escdelay_impl(PyObject *module, int ms)
    3446                 :            : /*[clinic end generated code: output=43818efbf7980ac4 input=7796fe19f111e250]*/
    3447                 :            : {
    3448         [ #  # ]:          0 :     if (ms <= 0) {
    3449                 :          0 :         PyErr_SetString(PyExc_ValueError, "ms must be > 0");
    3450                 :          0 :         return NULL;
    3451                 :            :     }
    3452                 :            : 
    3453                 :          0 :     return PyCursesCheckERR(set_escdelay(ms), "set_escdelay");
    3454                 :            : }
    3455                 :            : 
    3456                 :            : /*[clinic input]
    3457                 :            : _curses.get_tabsize
    3458                 :            : 
    3459                 :            : Gets the curses TABSIZE setting.
    3460                 :            : 
    3461                 :            : Gets the number of columns used by the curses library when converting a tab
    3462                 :            : character to spaces as it adds the tab to a window.
    3463                 :            : [clinic start generated code]*/
    3464                 :            : 
    3465                 :            : static PyObject *
    3466                 :          0 : _curses_get_tabsize_impl(PyObject *module)
    3467                 :            : /*[clinic end generated code: output=7e9e51fb6126fbdf input=74af86bf6c9f5d7e]*/
    3468                 :            : {
    3469                 :          0 :     return PyLong_FromLong(TABSIZE);
    3470                 :            : }
    3471                 :            : /*[clinic input]
    3472                 :            : _curses.set_tabsize
    3473                 :            :     size: int
    3474                 :            :         rendered cell width of a tab character.
    3475                 :            :     /
    3476                 :            : 
    3477                 :            : Sets the curses TABSIZE setting.
    3478                 :            : 
    3479                 :            : Sets the number of columns used by the curses library when converting a tab
    3480                 :            : character to spaces as it adds the tab to a window.
    3481                 :            : [clinic start generated code]*/
    3482                 :            : 
    3483                 :            : static PyObject *
    3484                 :          0 : _curses_set_tabsize_impl(PyObject *module, int size)
    3485                 :            : /*[clinic end generated code: output=c1de5a76c0daab1e input=78cba6a3021ad061]*/
    3486                 :            : {
    3487         [ #  # ]:          0 :     if (size <= 0) {
    3488                 :          0 :         PyErr_SetString(PyExc_ValueError, "size must be > 0");
    3489                 :          0 :         return NULL;
    3490                 :            :     }
    3491                 :            : 
    3492                 :          0 :     return PyCursesCheckERR(set_tabsize(size), "set_tabsize");
    3493                 :            : }
    3494                 :            : #endif
    3495                 :            : 
    3496                 :            : /*[clinic input]
    3497                 :            : _curses.intrflush
    3498                 :            : 
    3499                 :            :     flag: bool
    3500                 :            :     /
    3501                 :            : 
    3502                 :            : [clinic start generated code]*/
    3503                 :            : 
    3504                 :            : static PyObject *
    3505                 :          0 : _curses_intrflush_impl(PyObject *module, int flag)
    3506                 :            : /*[clinic end generated code: output=c1986df35e999a0f input=c65fe2ef973fe40a]*/
    3507                 :            : {
    3508         [ #  # ]:          0 :     PyCursesInitialised;
    3509                 :            : 
    3510                 :          0 :     return PyCursesCheckERR(intrflush(NULL, flag), "intrflush");
    3511                 :            : }
    3512                 :            : 
    3513                 :            : /*[clinic input]
    3514                 :            : _curses.isendwin
    3515                 :            : 
    3516                 :            : Return True if endwin() has been called.
    3517                 :            : [clinic start generated code]*/
    3518                 :            : 
    3519                 :            : static PyObject *
    3520                 :          0 : _curses_isendwin_impl(PyObject *module)
    3521                 :            : /*[clinic end generated code: output=d73179e4a7e1eb8c input=6cdb01a7ebf71397]*/
    3522         [ #  # ]:          0 : NoArgTrueFalseFunctionBody(isendwin)
    3523                 :            : 
    3524                 :            : #ifdef HAVE_CURSES_IS_TERM_RESIZED
    3525                 :            : /*[clinic input]
    3526                 :            : _curses.is_term_resized
    3527                 :            : 
    3528                 :            :     nlines: int
    3529                 :            :         Height.
    3530                 :            :     ncols: int
    3531                 :            :         Width.
    3532                 :            :     /
    3533                 :            : 
    3534                 :            : Return True if resize_term() would modify the window structure, False otherwise.
    3535                 :            : [clinic start generated code]*/
    3536                 :            : 
    3537                 :            : static PyObject *
    3538                 :          0 : _curses_is_term_resized_impl(PyObject *module, int nlines, int ncols)
    3539                 :            : /*[clinic end generated code: output=aafe04afe50f1288 input=ca9c0bd0fb8ab444]*/
    3540                 :            : {
    3541         [ #  # ]:          0 :     PyCursesInitialised;
    3542                 :            : 
    3543                 :          0 :     return PyBool_FromLong(is_term_resized(nlines, ncols));
    3544                 :            : }
    3545                 :            : #endif /* HAVE_CURSES_IS_TERM_RESIZED */
    3546                 :            : 
    3547                 :            : /*[clinic input]
    3548                 :            : _curses.keyname
    3549                 :            : 
    3550                 :            :     key: int
    3551                 :            :         Key number.
    3552                 :            :     /
    3553                 :            : 
    3554                 :            : Return the name of specified key.
    3555                 :            : [clinic start generated code]*/
    3556                 :            : 
    3557                 :            : static PyObject *
    3558                 :          0 : _curses_keyname_impl(PyObject *module, int key)
    3559                 :            : /*[clinic end generated code: output=fa2675ab3f4e056b input=ee4b1d0f243a2a2b]*/
    3560                 :            : {
    3561                 :            :     const char *knp;
    3562                 :            : 
    3563         [ #  # ]:          0 :     PyCursesInitialised;
    3564                 :            : 
    3565         [ #  # ]:          0 :     if (key < 0) {
    3566                 :          0 :         PyErr_SetString(PyExc_ValueError, "invalid key number");
    3567                 :          0 :         return NULL;
    3568                 :            :     }
    3569                 :          0 :     knp = keyname(key);
    3570                 :            : 
    3571         [ #  # ]:          0 :     return PyBytes_FromString((knp == NULL) ? "" : knp);
    3572                 :            : }
    3573                 :            : 
    3574                 :            : /*[clinic input]
    3575                 :            : _curses.killchar
    3576                 :            : 
    3577                 :            : Return the user's current line kill character.
    3578                 :            : [clinic start generated code]*/
    3579                 :            : 
    3580                 :            : static PyObject *
    3581                 :          0 : _curses_killchar_impl(PyObject *module)
    3582                 :            : /*[clinic end generated code: output=31c3a45b2c528269 input=1ff171c38df5ccad]*/
    3583                 :            : {
    3584                 :            :     char ch;
    3585                 :            : 
    3586                 :          0 :     ch = killchar();
    3587                 :            : 
    3588                 :          0 :     return PyBytes_FromStringAndSize(&ch, 1);
    3589                 :            : }
    3590                 :            : 
    3591                 :            : /*[clinic input]
    3592                 :            : _curses.longname
    3593                 :            : 
    3594                 :            : Return the terminfo long name field describing the current terminal.
    3595                 :            : 
    3596                 :            : The maximum length of a verbose description is 128 characters.  It is defined
    3597                 :            : only after the call to initscr().
    3598                 :            : [clinic start generated code]*/
    3599                 :            : 
    3600                 :            : static PyObject *
    3601                 :          0 : _curses_longname_impl(PyObject *module)
    3602                 :            : /*[clinic end generated code: output=fdf30433727ef568 input=84c3f20201b1098e]*/
    3603         [ #  # ]:          0 : NoArgReturnStringFunctionBody(longname)
    3604                 :            : 
    3605                 :            : /*[clinic input]
    3606                 :            : _curses.meta
    3607                 :            : 
    3608                 :            :     yes: bool
    3609                 :            :     /
    3610                 :            : 
    3611                 :            : Enable/disable meta keys.
    3612                 :            : 
    3613                 :            : If yes is True, allow 8-bit characters to be input.  If yes is False,
    3614                 :            : allow only 7-bit characters.
    3615                 :            : [clinic start generated code]*/
    3616                 :            : 
    3617                 :            : static PyObject *
    3618                 :          0 : _curses_meta_impl(PyObject *module, int yes)
    3619                 :            : /*[clinic end generated code: output=22f5abda46a605d8 input=cfe7da79f51d0e30]*/
    3620                 :            : {
    3621         [ #  # ]:          0 :     PyCursesInitialised;
    3622                 :            : 
    3623                 :          0 :     return PyCursesCheckERR(meta(stdscr, yes), "meta");
    3624                 :            : }
    3625                 :            : 
    3626                 :            : #ifdef NCURSES_MOUSE_VERSION
    3627                 :            : /*[clinic input]
    3628                 :            : _curses.mouseinterval
    3629                 :            : 
    3630                 :            :     interval: int
    3631                 :            :         Time in milliseconds.
    3632                 :            :     /
    3633                 :            : 
    3634                 :            : Set and retrieve the maximum time between press and release in a click.
    3635                 :            : 
    3636                 :            : Set the maximum time that can elapse between press and release events in
    3637                 :            : order for them to be recognized as a click, and return the previous interval
    3638                 :            : value.
    3639                 :            : [clinic start generated code]*/
    3640                 :            : 
    3641                 :            : static PyObject *
    3642                 :          0 : _curses_mouseinterval_impl(PyObject *module, int interval)
    3643                 :            : /*[clinic end generated code: output=c4f5ff04354634c5 input=75aaa3f0db10ac4e]*/
    3644                 :            : {
    3645         [ #  # ]:          0 :     PyCursesInitialised;
    3646                 :            : 
    3647                 :          0 :     return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
    3648                 :            : }
    3649                 :            : 
    3650                 :            : /*[clinic input]
    3651                 :            : _curses.mousemask
    3652                 :            : 
    3653                 :            :     newmask: unsigned_long(bitwise=True)
    3654                 :            :     /
    3655                 :            : 
    3656                 :            : Set the mouse events to be reported, and return a tuple (availmask, oldmask).
    3657                 :            : 
    3658                 :            : Return a tuple (availmask, oldmask).  availmask indicates which of the
    3659                 :            : specified mouse events can be reported; on complete failure it returns 0.
    3660                 :            : oldmask is the previous value of the given window's mouse event mask.
    3661                 :            : If this function is never called, no mouse events are ever reported.
    3662                 :            : [clinic start generated code]*/
    3663                 :            : 
    3664                 :            : static PyObject *
    3665                 :          0 : _curses_mousemask_impl(PyObject *module, unsigned long newmask)
    3666                 :            : /*[clinic end generated code: output=9406cf1b8a36e485 input=bdf76b7568a3c541]*/
    3667                 :            : {
    3668                 :            :     mmask_t oldmask, availmask;
    3669                 :            : 
    3670         [ #  # ]:          0 :     PyCursesInitialised;
    3671                 :          0 :     availmask = mousemask((mmask_t)newmask, &oldmask);
    3672                 :          0 :     return Py_BuildValue("(kk)",
    3673                 :            :                          (unsigned long)availmask, (unsigned long)oldmask);
    3674                 :            : }
    3675                 :            : #endif
    3676                 :            : 
    3677                 :            : /*[clinic input]
    3678                 :            : _curses.napms
    3679                 :            : 
    3680                 :            :     ms: int
    3681                 :            :         Duration in milliseconds.
    3682                 :            :     /
    3683                 :            : 
    3684                 :            : Sleep for specified time.
    3685                 :            : [clinic start generated code]*/
    3686                 :            : 
    3687                 :            : static PyObject *
    3688                 :          0 : _curses_napms_impl(PyObject *module, int ms)
    3689                 :            : /*[clinic end generated code: output=a40a1da2e39ea438 input=20cd3af2b6900f56]*/
    3690                 :            : {
    3691         [ #  # ]:          0 :     PyCursesInitialised;
    3692                 :            : 
    3693                 :          0 :     return Py_BuildValue("i", napms(ms));
    3694                 :            : }
    3695                 :            : 
    3696                 :            : 
    3697                 :            : /*[clinic input]
    3698                 :            : _curses.newpad
    3699                 :            : 
    3700                 :            :     nlines: int
    3701                 :            :         Height.
    3702                 :            :     ncols: int
    3703                 :            :         Width.
    3704                 :            :     /
    3705                 :            : 
    3706                 :            : Create and return a pointer to a new pad data structure.
    3707                 :            : [clinic start generated code]*/
    3708                 :            : 
    3709                 :            : static PyObject *
    3710                 :          0 : _curses_newpad_impl(PyObject *module, int nlines, int ncols)
    3711                 :            : /*[clinic end generated code: output=de52a56eb1098ec9 input=93f1272f240d8894]*/
    3712                 :            : {
    3713                 :            :     WINDOW *win;
    3714                 :            : 
    3715         [ #  # ]:          0 :     PyCursesInitialised;
    3716                 :            : 
    3717                 :          0 :     win = newpad(nlines, ncols);
    3718                 :            : 
    3719         [ #  # ]:          0 :     if (win == NULL) {
    3720                 :          0 :         PyErr_SetString(PyCursesError, catchall_NULL);
    3721                 :          0 :         return NULL;
    3722                 :            :     }
    3723                 :            : 
    3724                 :          0 :     return (PyObject *)PyCursesWindow_New(win, NULL);
    3725                 :            : }
    3726                 :            : 
    3727                 :            : /*[clinic input]
    3728                 :            : _curses.newwin
    3729                 :            : 
    3730                 :            :     nlines: int
    3731                 :            :         Height.
    3732                 :            :     ncols: int
    3733                 :            :         Width.
    3734                 :            :     [
    3735                 :            :     begin_y: int = 0
    3736                 :            :         Top side y-coordinate.
    3737                 :            :     begin_x: int = 0
    3738                 :            :         Left side x-coordinate.
    3739                 :            :     ]
    3740                 :            :     /
    3741                 :            : 
    3742                 :            : Return a new window.
    3743                 :            : 
    3744                 :            : By default, the window will extend from the specified position to the lower
    3745                 :            : right corner of the screen.
    3746                 :            : [clinic start generated code]*/
    3747                 :            : 
    3748                 :            : static PyObject *
    3749                 :          0 : _curses_newwin_impl(PyObject *module, int nlines, int ncols,
    3750                 :            :                     int group_right_1, int begin_y, int begin_x)
    3751                 :            : /*[clinic end generated code: output=c1e0a8dc8ac2826c input=29312c15a72a003d]*/
    3752                 :            : {
    3753                 :            :     WINDOW *win;
    3754                 :            : 
    3755         [ #  # ]:          0 :     PyCursesInitialised;
    3756                 :            : 
    3757                 :          0 :     win = newwin(nlines,ncols,begin_y,begin_x);
    3758         [ #  # ]:          0 :     if (win == NULL) {
    3759                 :          0 :         PyErr_SetString(PyCursesError, catchall_NULL);
    3760                 :          0 :         return NULL;
    3761                 :            :     }
    3762                 :            : 
    3763                 :          0 :     return (PyObject *)PyCursesWindow_New(win, NULL);
    3764                 :            : }
    3765                 :            : 
    3766                 :            : /*[clinic input]
    3767                 :            : _curses.nl
    3768                 :            : 
    3769                 :            :     flag: bool = True
    3770                 :            :         If false, the effect is the same as calling nonl().
    3771                 :            :     /
    3772                 :            : 
    3773                 :            : Enter newline mode.
    3774                 :            : 
    3775                 :            : This mode translates the return key into newline on input, and translates
    3776                 :            : newline into return and line-feed on output.  Newline mode is initially on.
    3777                 :            : [clinic start generated code]*/
    3778                 :            : 
    3779                 :            : static PyObject *
    3780                 :          0 : _curses_nl_impl(PyObject *module, int flag)
    3781                 :            : /*[clinic end generated code: output=b39cc0ffc9015003 input=18e3e9c6e8cfcf6f]*/
    3782   [ #  #  #  # ]:          0 : NoArgOrFlagNoReturnFunctionBody(nl, flag)
    3783                 :            : 
    3784                 :            : /*[clinic input]
    3785                 :            : _curses.nocbreak
    3786                 :            : 
    3787                 :            : Leave cbreak mode.
    3788                 :            : 
    3789                 :            : Return to normal "cooked" mode with line buffering.
    3790                 :            : [clinic start generated code]*/
    3791                 :            : 
    3792                 :            : static PyObject *
    3793                 :          0 : _curses_nocbreak_impl(PyObject *module)
    3794                 :            : /*[clinic end generated code: output=eabf3833a4fbf620 input=e4b65f7d734af400]*/
    3795         [ #  # ]:          0 : NoArgNoReturnFunctionBody(nocbreak)
    3796                 :            : 
    3797                 :            : /*[clinic input]
    3798                 :            : _curses.noecho
    3799                 :            : 
    3800                 :            : Leave echo mode.
    3801                 :            : 
    3802                 :            : Echoing of input characters is turned off.
    3803                 :            : [clinic start generated code]*/
    3804                 :            : 
    3805                 :            : static PyObject *
    3806                 :          0 : _curses_noecho_impl(PyObject *module)
    3807                 :            : /*[clinic end generated code: output=cc95ab45bc98f41b input=76714df529e614c3]*/
    3808         [ #  # ]:          0 : NoArgNoReturnFunctionBody(noecho)
    3809                 :            : 
    3810                 :            : /*[clinic input]
    3811                 :            : _curses.nonl
    3812                 :            : 
    3813                 :            : Leave newline mode.
    3814                 :            : 
    3815                 :            : Disable translation of return into newline on input, and disable low-level
    3816                 :            : translation of newline into newline/return on output.
    3817                 :            : [clinic start generated code]*/
    3818                 :            : 
    3819                 :            : static PyObject *
    3820                 :          0 : _curses_nonl_impl(PyObject *module)
    3821                 :            : /*[clinic end generated code: output=99e917e9715770c6 input=9d37dd122d3022fc]*/
    3822         [ #  # ]:          0 : NoArgNoReturnFunctionBody(nonl)
    3823                 :            : 
    3824                 :            : /*[clinic input]
    3825                 :            : _curses.noqiflush
    3826                 :            : 
    3827                 :            : Disable queue flushing.
    3828                 :            : 
    3829                 :            : When queue flushing is disabled, normal flush of input and output queues
    3830                 :            : associated with the INTR, QUIT and SUSP characters will not be done.
    3831                 :            : [clinic start generated code]*/
    3832                 :            : 
    3833                 :            : static PyObject *
    3834                 :          0 : _curses_noqiflush_impl(PyObject *module)
    3835                 :            : /*[clinic end generated code: output=8b95a4229bbf0877 input=ba3e6b2e3e54c4df]*/
    3836         [ #  # ]:          0 : NoArgNoReturnVoidFunctionBody(noqiflush)
    3837                 :            : 
    3838                 :            : /*[clinic input]
    3839                 :            : _curses.noraw
    3840                 :            : 
    3841                 :            : Leave raw mode.
    3842                 :            : 
    3843                 :            : Return to normal "cooked" mode with line buffering.
    3844                 :            : [clinic start generated code]*/
    3845                 :            : 
    3846                 :            : static PyObject *
    3847                 :          0 : _curses_noraw_impl(PyObject *module)
    3848                 :            : /*[clinic end generated code: output=39894e5524c430cc input=6ec86692096dffb5]*/
    3849         [ #  # ]:          0 : NoArgNoReturnFunctionBody(noraw)
    3850                 :            : 
    3851                 :            : /*[clinic input]
    3852                 :            : _curses.pair_content
    3853                 :            : 
    3854                 :            :     pair_number: pair
    3855                 :            :         The number of the color pair (0 - (COLOR_PAIRS-1)).
    3856                 :            :     /
    3857                 :            : 
    3858                 :            : Return a tuple (fg, bg) containing the colors for the requested color pair.
    3859                 :            : [clinic start generated code]*/
    3860                 :            : 
    3861                 :            : static PyObject *
    3862                 :          0 : _curses_pair_content_impl(PyObject *module, int pair_number)
    3863                 :            : /*[clinic end generated code: output=4a726dd0e6885f3f input=03970f840fc7b739]*/
    3864                 :            : {
    3865                 :            :     _CURSES_COLOR_NUM_TYPE f, b;
    3866                 :            : 
    3867         [ #  # ]:          0 :     PyCursesInitialised;
    3868         [ #  # ]:          0 :     PyCursesInitialisedColor;
    3869                 :            : 
    3870         [ #  # ]:          0 :     if (_CURSES_PAIR_CONTENT_FUNC(pair_number, &f, &b) == ERR) {
    3871         [ #  # ]:          0 :         if (pair_number >= COLOR_PAIRS) {
    3872                 :          0 :             PyErr_Format(PyExc_ValueError,
    3873                 :            :                          "Color pair is greater than COLOR_PAIRS-1 (%d).",
    3874                 :            :                          COLOR_PAIRS - 1);
    3875                 :            :         }
    3876                 :            :         else {
    3877                 :          0 :             PyErr_Format(PyCursesError, "%s() returned ERR",
    3878                 :            :                          Py_STRINGIFY(_CURSES_PAIR_CONTENT_FUNC));
    3879                 :            :         }
    3880                 :          0 :         return NULL;
    3881                 :            :     }
    3882                 :            : 
    3883                 :          0 :     return Py_BuildValue("(ii)", f, b);
    3884                 :            : }
    3885                 :            : 
    3886                 :            : /*[clinic input]
    3887                 :            : _curses.pair_number
    3888                 :            : 
    3889                 :            :     attr: int
    3890                 :            :     /
    3891                 :            : 
    3892                 :            : Return the number of the color-pair set by the specified attribute value.
    3893                 :            : 
    3894                 :            : color_pair() is the counterpart to this function.
    3895                 :            : [clinic start generated code]*/
    3896                 :            : 
    3897                 :            : static PyObject *
    3898                 :          0 : _curses_pair_number_impl(PyObject *module, int attr)
    3899                 :            : /*[clinic end generated code: output=85bce7d65c0aa3f4 input=d478548e33f5e61a]*/
    3900                 :            : {
    3901         [ #  # ]:          0 :     PyCursesInitialised;
    3902         [ #  # ]:          0 :     PyCursesInitialisedColor;
    3903                 :            : 
    3904                 :          0 :     return PyLong_FromLong(PAIR_NUMBER(attr));
    3905                 :            : }
    3906                 :            : 
    3907                 :            : /*[clinic input]
    3908                 :            : _curses.putp
    3909                 :            : 
    3910                 :            :     string: str(accept={robuffer})
    3911                 :            :     /
    3912                 :            : 
    3913                 :            : Emit the value of a specified terminfo capability for the current terminal.
    3914                 :            : 
    3915                 :            : Note that the output of putp() always goes to standard output.
    3916                 :            : [clinic start generated code]*/
    3917                 :            : 
    3918                 :            : static PyObject *
    3919                 :          0 : _curses_putp_impl(PyObject *module, const char *string)
    3920                 :            : /*[clinic end generated code: output=e98081d1b8eb5816 input=1601faa828b44cb3]*/
    3921                 :            : {
    3922                 :          0 :     return PyCursesCheckERR(putp(string), "putp");
    3923                 :            : }
    3924                 :            : 
    3925                 :            : /*[clinic input]
    3926                 :            : _curses.qiflush
    3927                 :            : 
    3928                 :            :     flag: bool = True
    3929                 :            :         If false, the effect is the same as calling noqiflush().
    3930                 :            :     /
    3931                 :            : 
    3932                 :            : Enable queue flushing.
    3933                 :            : 
    3934                 :            : If queue flushing is enabled, all output in the display driver queue
    3935                 :            : will be flushed when the INTR, QUIT and SUSP characters are read.
    3936                 :            : [clinic start generated code]*/
    3937                 :            : 
    3938                 :            : static PyObject *
    3939                 :          0 : _curses_qiflush_impl(PyObject *module, int flag)
    3940                 :            : /*[clinic end generated code: output=9167e862f760ea30 input=6ec8b3e2b717ec40]*/
    3941                 :            : {
    3942         [ #  # ]:          0 :     PyCursesInitialised;
    3943                 :            : 
    3944         [ #  # ]:          0 :     if (flag) {
    3945                 :          0 :         qiflush();
    3946                 :            :     }
    3947                 :            :     else {
    3948                 :          0 :         noqiflush();
    3949                 :            :     }
    3950                 :          0 :     Py_RETURN_NONE;
    3951                 :            : }
    3952                 :            : 
    3953                 :            : /* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES
    3954                 :            :  * and _curses.COLS */
    3955                 :            : #if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM)
    3956                 :            : static int
    3957                 :          0 : update_lines_cols(void)
    3958                 :            : {
    3959                 :            :     PyObject *o;
    3960                 :          0 :     PyObject *m = PyImport_ImportModule("curses");
    3961                 :            : 
    3962         [ #  # ]:          0 :     if (!m)
    3963                 :          0 :         return 0;
    3964                 :            : 
    3965                 :          0 :     o = PyLong_FromLong(LINES);
    3966         [ #  # ]:          0 :     if (!o) {
    3967                 :          0 :         Py_DECREF(m);
    3968                 :          0 :         return 0;
    3969                 :            :     }
    3970         [ #  # ]:          0 :     if (PyObject_SetAttrString(m, "LINES", o)) {
    3971                 :          0 :         Py_DECREF(m);
    3972                 :          0 :         Py_DECREF(o);
    3973                 :          0 :         return 0;
    3974                 :            :     }
    3975         [ #  # ]:          0 :     if (PyDict_SetItemString(ModDict, "LINES", o)) {
    3976                 :          0 :         Py_DECREF(m);
    3977                 :          0 :         Py_DECREF(o);
    3978                 :          0 :         return 0;
    3979                 :            :     }
    3980                 :          0 :     Py_DECREF(o);
    3981                 :          0 :     o = PyLong_FromLong(COLS);
    3982         [ #  # ]:          0 :     if (!o) {
    3983                 :          0 :         Py_DECREF(m);
    3984                 :          0 :         return 0;
    3985                 :            :     }
    3986         [ #  # ]:          0 :     if (PyObject_SetAttrString(m, "COLS", o)) {
    3987                 :          0 :         Py_DECREF(m);
    3988                 :          0 :         Py_DECREF(o);
    3989                 :          0 :         return 0;
    3990                 :            :     }
    3991         [ #  # ]:          0 :     if (PyDict_SetItemString(ModDict, "COLS", o)) {
    3992                 :          0 :         Py_DECREF(m);
    3993                 :          0 :         Py_DECREF(o);
    3994                 :          0 :         return 0;
    3995                 :            :     }
    3996                 :          0 :     Py_DECREF(o);
    3997                 :          0 :     Py_DECREF(m);
    3998                 :          0 :     return 1;
    3999                 :            : }
    4000                 :            : 
    4001                 :            : /*[clinic input]
    4002                 :            : _curses.update_lines_cols
    4003                 :            : 
    4004                 :            : [clinic start generated code]*/
    4005                 :            : 
    4006                 :            : static PyObject *
    4007                 :          0 : _curses_update_lines_cols_impl(PyObject *module)
    4008                 :            : /*[clinic end generated code: output=423f2b1e63ed0f75 input=5f065ab7a28a5d90]*/
    4009                 :            : {
    4010         [ #  # ]:          0 :     if (!update_lines_cols()) {
    4011                 :          0 :         return NULL;
    4012                 :            :     }
    4013                 :          0 :     Py_RETURN_NONE;
    4014                 :            : }
    4015                 :            : 
    4016                 :            : #endif
    4017                 :            : 
    4018                 :            : /*[clinic input]
    4019                 :            : _curses.raw
    4020                 :            : 
    4021                 :            :     flag: bool = True
    4022                 :            :         If false, the effect is the same as calling noraw().
    4023                 :            :     /
    4024                 :            : 
    4025                 :            : Enter raw mode.
    4026                 :            : 
    4027                 :            : In raw mode, normal line buffering and processing of interrupt, quit,
    4028                 :            : suspend, and flow control keys are turned off; characters are presented to
    4029                 :            : curses input functions one by one.
    4030                 :            : [clinic start generated code]*/
    4031                 :            : 
    4032                 :            : static PyObject *
    4033                 :          0 : _curses_raw_impl(PyObject *module, int flag)
    4034                 :            : /*[clinic end generated code: output=a750e4b342be015b input=4b447701389fb4df]*/
    4035   [ #  #  #  # ]:          0 : NoArgOrFlagNoReturnFunctionBody(raw, flag)
    4036                 :            : 
    4037                 :            : /*[clinic input]
    4038                 :            : _curses.reset_prog_mode
    4039                 :            : 
    4040                 :            : Restore the terminal to "program" mode, as previously saved by def_prog_mode().
    4041                 :            : [clinic start generated code]*/
    4042                 :            : 
    4043                 :            : static PyObject *
    4044                 :          0 : _curses_reset_prog_mode_impl(PyObject *module)
    4045                 :            : /*[clinic end generated code: output=15eb765abf0b6575 input=3d82bea2b3243471]*/
    4046         [ #  # ]:          0 : NoArgNoReturnFunctionBody(reset_prog_mode)
    4047                 :            : 
    4048                 :            : /*[clinic input]
    4049                 :            : _curses.reset_shell_mode
    4050                 :            : 
    4051                 :            : Restore the terminal to "shell" mode, as previously saved by def_shell_mode().
    4052                 :            : [clinic start generated code]*/
    4053                 :            : 
    4054                 :            : static PyObject *
    4055                 :          0 : _curses_reset_shell_mode_impl(PyObject *module)
    4056                 :            : /*[clinic end generated code: output=0238de2962090d33 input=1c738fa64bd1a24f]*/
    4057         [ #  # ]:          0 : NoArgNoReturnFunctionBody(reset_shell_mode)
    4058                 :            : 
    4059                 :            : /*[clinic input]
    4060                 :            : _curses.resetty
    4061                 :            : 
    4062                 :            : Restore terminal mode.
    4063                 :            : [clinic start generated code]*/
    4064                 :            : 
    4065                 :            : static PyObject *
    4066                 :          0 : _curses_resetty_impl(PyObject *module)
    4067                 :            : /*[clinic end generated code: output=ff4b448e80a7cd63 input=940493de03624bb0]*/
    4068         [ #  # ]:          0 : NoArgNoReturnFunctionBody(resetty)
    4069                 :            : 
    4070                 :            : #ifdef HAVE_CURSES_RESIZETERM
    4071                 :            : /*[clinic input]
    4072                 :            : _curses.resizeterm
    4073                 :            : 
    4074                 :            :     nlines: int
    4075                 :            :         Height.
    4076                 :            :     ncols: int
    4077                 :            :         Width.
    4078                 :            :     /
    4079                 :            : 
    4080                 :            : Resize the standard and current windows to the specified dimensions.
    4081                 :            : 
    4082                 :            : Adjusts other bookkeeping data used by the curses library that record the
    4083                 :            : window dimensions (in particular the SIGWINCH handler).
    4084                 :            : [clinic start generated code]*/
    4085                 :            : 
    4086                 :            : static PyObject *
    4087                 :          0 : _curses_resizeterm_impl(PyObject *module, int nlines, int ncols)
    4088                 :            : /*[clinic end generated code: output=56d6bcc5194ad055 input=0fca02ebad5ffa82]*/
    4089                 :            : {
    4090                 :            :     PyObject *result;
    4091                 :            : 
    4092         [ #  # ]:          0 :     PyCursesInitialised;
    4093                 :            : 
    4094                 :          0 :     result = PyCursesCheckERR(resizeterm(nlines, ncols), "resizeterm");
    4095         [ #  # ]:          0 :     if (!result)
    4096                 :          0 :         return NULL;
    4097         [ #  # ]:          0 :     if (!update_lines_cols()) {
    4098                 :          0 :         Py_DECREF(result);
    4099                 :          0 :         return NULL;
    4100                 :            :     }
    4101                 :          0 :     return result;
    4102                 :            : }
    4103                 :            : 
    4104                 :            : #endif
    4105                 :            : 
    4106                 :            : #ifdef HAVE_CURSES_RESIZE_TERM
    4107                 :            : /*[clinic input]
    4108                 :            : _curses.resize_term
    4109                 :            : 
    4110                 :            :     nlines: int
    4111                 :            :         Height.
    4112                 :            :     ncols: int
    4113                 :            :         Width.
    4114                 :            :     /
    4115                 :            : 
    4116                 :            : Backend function used by resizeterm(), performing most of the work.
    4117                 :            : 
    4118                 :            : When resizing the windows, resize_term() blank-fills the areas that are
    4119                 :            : extended.  The calling application should fill in these areas with appropriate
    4120                 :            : data.  The resize_term() function attempts to resize all windows.  However,
    4121                 :            : due to the calling convention of pads, it is not possible to resize these
    4122                 :            : without additional interaction with the application.
    4123                 :            : [clinic start generated code]*/
    4124                 :            : 
    4125                 :            : static PyObject *
    4126                 :          0 : _curses_resize_term_impl(PyObject *module, int nlines, int ncols)
    4127                 :            : /*[clinic end generated code: output=9e26d8b9ea311ed2 input=2197edd05b049ed4]*/
    4128                 :            : {
    4129                 :            :     PyObject *result;
    4130                 :            : 
    4131         [ #  # ]:          0 :     PyCursesInitialised;
    4132                 :            : 
    4133                 :          0 :     result = PyCursesCheckERR(resize_term(nlines, ncols), "resize_term");
    4134         [ #  # ]:          0 :     if (!result)
    4135                 :          0 :         return NULL;
    4136         [ #  # ]:          0 :     if (!update_lines_cols()) {
    4137                 :          0 :         Py_DECREF(result);
    4138                 :          0 :         return NULL;
    4139                 :            :     }
    4140                 :          0 :     return result;
    4141                 :            : }
    4142                 :            : #endif /* HAVE_CURSES_RESIZE_TERM */
    4143                 :            : 
    4144                 :            : /*[clinic input]
    4145                 :            : _curses.savetty
    4146                 :            : 
    4147                 :            : Save terminal mode.
    4148                 :            : [clinic start generated code]*/
    4149                 :            : 
    4150                 :            : static PyObject *
    4151                 :          0 : _curses_savetty_impl(PyObject *module)
    4152                 :            : /*[clinic end generated code: output=6babc49f12b42199 input=fce6b2b7d2200102]*/
    4153         [ #  # ]:          0 : NoArgNoReturnFunctionBody(savetty)
    4154                 :            : 
    4155                 :            : #ifdef getsyx
    4156                 :            : /*[clinic input]
    4157                 :            : _curses.setsyx
    4158                 :            : 
    4159                 :            :     y: int
    4160                 :            :         Y-coordinate.
    4161                 :            :     x: int
    4162                 :            :         X-coordinate.
    4163                 :            :     /
    4164                 :            : 
    4165                 :            : Set the virtual screen cursor.
    4166                 :            : 
    4167                 :            : If y and x are both -1, then leaveok is set.
    4168                 :            : [clinic start generated code]*/
    4169                 :            : 
    4170                 :            : static PyObject *
    4171                 :          0 : _curses_setsyx_impl(PyObject *module, int y, int x)
    4172                 :            : /*[clinic end generated code: output=23dcf753511a2464 input=fa7f2b208e10a557]*/
    4173                 :            : {
    4174         [ #  # ]:          0 :     PyCursesInitialised;
    4175                 :            : 
    4176   [ #  #  #  #  :          0 :     setsyx(y,x);
                   #  # ]
    4177                 :            : 
    4178                 :          0 :     Py_RETURN_NONE;
    4179                 :            : }
    4180                 :            : #endif
    4181                 :            : 
    4182                 :            : /*[clinic input]
    4183                 :            : _curses.start_color
    4184                 :            : 
    4185                 :            : Initializes eight basic colors and global variables COLORS and COLOR_PAIRS.
    4186                 :            : 
    4187                 :            : Must be called if the programmer wants to use colors, and before any other
    4188                 :            : color manipulation routine is called.  It is good practice to call this
    4189                 :            : routine right after initscr().
    4190                 :            : 
    4191                 :            : It also restores the colors on the terminal to the values they had when the
    4192                 :            : terminal was just turned on.
    4193                 :            : [clinic start generated code]*/
    4194                 :            : 
    4195                 :            : static PyObject *
    4196                 :          0 : _curses_start_color_impl(PyObject *module)
    4197                 :            : /*[clinic end generated code: output=8b772b41d8090ede input=0ca0ecb2b77e1a12]*/
    4198                 :            : {
    4199                 :            :     int code;
    4200                 :            :     PyObject *c, *cp;
    4201                 :            : 
    4202         [ #  # ]:          0 :     PyCursesInitialised;
    4203                 :            : 
    4204                 :          0 :     code = start_color();
    4205         [ #  # ]:          0 :     if (code != ERR) {
    4206                 :          0 :         initialisedcolors = TRUE;
    4207                 :          0 :         c = PyLong_FromLong((long) COLORS);
    4208         [ #  # ]:          0 :         if (c == NULL)
    4209                 :          0 :             return NULL;
    4210         [ #  # ]:          0 :         if (PyDict_SetItemString(ModDict, "COLORS", c) < 0) {
    4211                 :          0 :             Py_DECREF(c);
    4212                 :          0 :             return NULL;
    4213                 :            :         }
    4214                 :          0 :         Py_DECREF(c);
    4215                 :          0 :         cp = PyLong_FromLong((long) COLOR_PAIRS);
    4216         [ #  # ]:          0 :         if (cp == NULL)
    4217                 :          0 :             return NULL;
    4218         [ #  # ]:          0 :         if (PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp) < 0) {
    4219                 :          0 :             Py_DECREF(cp);
    4220                 :          0 :             return NULL;
    4221                 :            :         }
    4222                 :          0 :         Py_DECREF(cp);
    4223                 :          0 :         Py_RETURN_NONE;
    4224                 :            :     } else {
    4225                 :          0 :         PyErr_SetString(PyCursesError, "start_color() returned ERR");
    4226                 :          0 :         return NULL;
    4227                 :            :     }
    4228                 :            : }
    4229                 :            : 
    4230                 :            : /*[clinic input]
    4231                 :            : _curses.termattrs
    4232                 :            : 
    4233                 :            : Return a logical OR of all video attributes supported by the terminal.
    4234                 :            : [clinic start generated code]*/
    4235                 :            : 
    4236                 :            : static PyObject *
    4237                 :          0 : _curses_termattrs_impl(PyObject *module)
    4238                 :            : /*[clinic end generated code: output=b06f437fce1b6fc4 input=0559882a04f84d1d]*/
    4239         [ #  # ]:          0 : NoArgReturnIntFunctionBody(termattrs)
    4240                 :            : 
    4241                 :            : /*[clinic input]
    4242                 :            : _curses.termname
    4243                 :            : 
    4244                 :            : Return the value of the environment variable TERM, truncated to 14 characters.
    4245                 :            : [clinic start generated code]*/
    4246                 :            : 
    4247                 :            : static PyObject *
    4248                 :          0 : _curses_termname_impl(PyObject *module)
    4249                 :            : /*[clinic end generated code: output=96375577ebbd67fd input=33c08d000944f33f]*/
    4250         [ #  # ]:          0 : NoArgReturnStringFunctionBody(termname)
    4251                 :            : 
    4252                 :            : /*[clinic input]
    4253                 :            : _curses.tigetflag
    4254                 :            : 
    4255                 :            :     capname: str
    4256                 :            :         The terminfo capability name.
    4257                 :            :     /
    4258                 :            : 
    4259                 :            : Return the value of the Boolean capability.
    4260                 :            : 
    4261                 :            : The value -1 is returned if capname is not a Boolean capability, or 0 if
    4262                 :            : it is canceled or absent from the terminal description.
    4263                 :            : [clinic start generated code]*/
    4264                 :            : 
    4265                 :            : static PyObject *
    4266                 :          0 : _curses_tigetflag_impl(PyObject *module, const char *capname)
    4267                 :            : /*[clinic end generated code: output=8853c0e55542195b input=b0787af9e3e9a6ce]*/
    4268                 :            : {
    4269         [ #  # ]:          0 :     PyCursesSetupTermCalled;
    4270                 :            : 
    4271                 :          0 :     return PyLong_FromLong( (long) tigetflag( (char *)capname ) );
    4272                 :            : }
    4273                 :            : 
    4274                 :            : /*[clinic input]
    4275                 :            : _curses.tigetnum
    4276                 :            : 
    4277                 :            :     capname: str
    4278                 :            :         The terminfo capability name.
    4279                 :            :     /
    4280                 :            : 
    4281                 :            : Return the value of the numeric capability.
    4282                 :            : 
    4283                 :            : The value -2 is returned if capname is not a numeric capability, or -1 if
    4284                 :            : it is canceled or absent from the terminal description.
    4285                 :            : [clinic start generated code]*/
    4286                 :            : 
    4287                 :            : static PyObject *
    4288                 :          0 : _curses_tigetnum_impl(PyObject *module, const char *capname)
    4289                 :            : /*[clinic end generated code: output=46f8b0a1b5dff42f input=5cdf2f410b109720]*/
    4290                 :            : {
    4291         [ #  # ]:          0 :     PyCursesSetupTermCalled;
    4292                 :            : 
    4293                 :          0 :     return PyLong_FromLong( (long) tigetnum( (char *)capname ) );
    4294                 :            : }
    4295                 :            : 
    4296                 :            : /*[clinic input]
    4297                 :            : _curses.tigetstr
    4298                 :            : 
    4299                 :            :     capname: str
    4300                 :            :         The terminfo capability name.
    4301                 :            :     /
    4302                 :            : 
    4303                 :            : Return the value of the string capability.
    4304                 :            : 
    4305                 :            : None is returned if capname is not a string capability, or is canceled or
    4306                 :            : absent from the terminal description.
    4307                 :            : [clinic start generated code]*/
    4308                 :            : 
    4309                 :            : static PyObject *
    4310                 :          0 : _curses_tigetstr_impl(PyObject *module, const char *capname)
    4311                 :            : /*[clinic end generated code: output=f22b576ad60248f3 input=36644df25c73c0a7]*/
    4312                 :            : {
    4313         [ #  # ]:          0 :     PyCursesSetupTermCalled;
    4314                 :            : 
    4315                 :          0 :     capname = tigetstr( (char *)capname );
    4316   [ #  #  #  # ]:          0 :     if (capname == NULL || capname == (char*) -1) {
    4317                 :          0 :         Py_RETURN_NONE;
    4318                 :            :     }
    4319                 :          0 :     return PyBytes_FromString( capname );
    4320                 :            : }
    4321                 :            : 
    4322                 :            : /*[clinic input]
    4323                 :            : _curses.tparm
    4324                 :            : 
    4325                 :            :     str: str(accept={robuffer})
    4326                 :            :         Parameterized byte string obtained from the terminfo database.
    4327                 :            :     i1: int = 0
    4328                 :            :     i2: int = 0
    4329                 :            :     i3: int = 0
    4330                 :            :     i4: int = 0
    4331                 :            :     i5: int = 0
    4332                 :            :     i6: int = 0
    4333                 :            :     i7: int = 0
    4334                 :            :     i8: int = 0
    4335                 :            :     i9: int = 0
    4336                 :            :     /
    4337                 :            : 
    4338                 :            : Instantiate the specified byte string with the supplied parameters.
    4339                 :            : [clinic start generated code]*/
    4340                 :            : 
    4341                 :            : static PyObject *
    4342                 :          0 : _curses_tparm_impl(PyObject *module, const char *str, int i1, int i2, int i3,
    4343                 :            :                    int i4, int i5, int i6, int i7, int i8, int i9)
    4344                 :            : /*[clinic end generated code: output=599f62b615c667ff input=5e30b15786f032aa]*/
    4345                 :            : {
    4346                 :          0 :     char* result = NULL;
    4347                 :            : 
    4348         [ #  # ]:          0 :     PyCursesSetupTermCalled;
    4349                 :            : 
    4350                 :          0 :     result = tparm((char *)str,i1,i2,i3,i4,i5,i6,i7,i8,i9);
    4351         [ #  # ]:          0 :     if (!result) {
    4352                 :          0 :         PyErr_SetString(PyCursesError, "tparm() returned NULL");
    4353                 :          0 :         return NULL;
    4354                 :            :     }
    4355                 :            : 
    4356                 :          0 :     return PyBytes_FromString(result);
    4357                 :            : }
    4358                 :            : 
    4359                 :            : #ifdef HAVE_CURSES_TYPEAHEAD
    4360                 :            : /*[clinic input]
    4361                 :            : _curses.typeahead
    4362                 :            : 
    4363                 :            :     fd: int
    4364                 :            :         File descriptor.
    4365                 :            :     /
    4366                 :            : 
    4367                 :            : Specify that the file descriptor fd be used for typeahead checking.
    4368                 :            : 
    4369                 :            : If fd is -1, then no typeahead checking is done.
    4370                 :            : [clinic start generated code]*/
    4371                 :            : 
    4372                 :            : static PyObject *
    4373                 :          0 : _curses_typeahead_impl(PyObject *module, int fd)
    4374                 :            : /*[clinic end generated code: output=084bb649d7066583 input=f2968d8e1805051b]*/
    4375                 :            : {
    4376         [ #  # ]:          0 :     PyCursesInitialised;
    4377                 :            : 
    4378                 :          0 :     return PyCursesCheckERR(typeahead( fd ), "typeahead");
    4379                 :            : }
    4380                 :            : #endif
    4381                 :            : 
    4382                 :            : /*[clinic input]
    4383                 :            : _curses.unctrl
    4384                 :            : 
    4385                 :            :     ch: object
    4386                 :            :     /
    4387                 :            : 
    4388                 :            : Return a string which is a printable representation of the character ch.
    4389                 :            : 
    4390                 :            : Control characters are displayed as a caret followed by the character,
    4391                 :            : for example as ^C.  Printing characters are left as they are.
    4392                 :            : [clinic start generated code]*/
    4393                 :            : 
    4394                 :            : static PyObject *
    4395                 :          0 : _curses_unctrl(PyObject *module, PyObject *ch)
    4396                 :            : /*[clinic end generated code: output=8e07fafc430c9434 input=cd1e35e16cd1ace4]*/
    4397                 :            : {
    4398                 :            :     chtype ch_;
    4399                 :            : 
    4400         [ #  # ]:          0 :     PyCursesInitialised;
    4401                 :            : 
    4402         [ #  # ]:          0 :     if (!PyCurses_ConvertToChtype(NULL, ch, &ch_))
    4403                 :          0 :         return NULL;
    4404                 :            : 
    4405                 :          0 :     return PyBytes_FromString(unctrl(ch_));
    4406                 :            : }
    4407                 :            : 
    4408                 :            : /*[clinic input]
    4409                 :            : _curses.ungetch
    4410                 :            : 
    4411                 :            :     ch: object
    4412                 :            :     /
    4413                 :            : 
    4414                 :            : Push ch so the next getch() will return it.
    4415                 :            : [clinic start generated code]*/
    4416                 :            : 
    4417                 :            : static PyObject *
    4418                 :          0 : _curses_ungetch(PyObject *module, PyObject *ch)
    4419                 :            : /*[clinic end generated code: output=9b19d8268376d887 input=6681e6ae4c42e5eb]*/
    4420                 :            : {
    4421                 :            :     chtype ch_;
    4422                 :            : 
    4423         [ #  # ]:          0 :     PyCursesInitialised;
    4424                 :            : 
    4425         [ #  # ]:          0 :     if (!PyCurses_ConvertToChtype(NULL, ch, &ch_))
    4426                 :          0 :         return NULL;
    4427                 :            : 
    4428                 :          0 :     return PyCursesCheckERR(ungetch(ch_), "ungetch");
    4429                 :            : }
    4430                 :            : 
    4431                 :            : #ifdef HAVE_NCURSESW
    4432                 :            : /* Convert an object to a character (wchar_t):
    4433                 :            : 
    4434                 :            :     - int
    4435                 :            :     - str of length 1
    4436                 :            : 
    4437                 :            :    Return 1 on success, 0 on error. */
    4438                 :            : static int
    4439                 :          0 : PyCurses_ConvertToWchar_t(PyObject *obj,
    4440                 :            :                           wchar_t *wch)
    4441                 :            : {
    4442         [ #  # ]:          0 :     if (PyUnicode_Check(obj)) {
    4443                 :            :         wchar_t buffer[2];
    4444         [ #  # ]:          0 :         if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) {
    4445                 :          0 :             PyErr_Format(PyExc_TypeError,
    4446                 :            :                          "expect str of length 1 or int, "
    4447                 :            :                          "got a str of length %zi",
    4448                 :            :                          PyUnicode_GET_LENGTH(obj));
    4449                 :          0 :             return 0;
    4450                 :            :         }
    4451                 :          0 :         *wch = buffer[0];
    4452                 :          0 :         return 2;
    4453                 :            :     }
    4454         [ #  # ]:          0 :     else if (PyLong_CheckExact(obj)) {
    4455                 :            :         long value;
    4456                 :            :         int overflow;
    4457                 :          0 :         value = PyLong_AsLongAndOverflow(obj, &overflow);
    4458         [ #  # ]:          0 :         if (overflow) {
    4459                 :          0 :             PyErr_SetString(PyExc_OverflowError,
    4460                 :            :                             "int doesn't fit in long");
    4461                 :          0 :             return 0;
    4462                 :            :         }
    4463                 :          0 :         *wch = (wchar_t)value;
    4464         [ #  # ]:          0 :         if ((long)*wch != value) {
    4465                 :          0 :             PyErr_Format(PyExc_OverflowError,
    4466                 :            :                          "character doesn't fit in wchar_t");
    4467                 :          0 :             return 0;
    4468                 :            :         }
    4469                 :          0 :         return 1;
    4470                 :            :     }
    4471                 :            :     else {
    4472                 :          0 :         PyErr_Format(PyExc_TypeError,
    4473                 :            :                      "expect str of length 1 or int, got %s",
    4474                 :          0 :                      Py_TYPE(obj)->tp_name);
    4475                 :          0 :         return 0;
    4476                 :            :     }
    4477                 :            : }
    4478                 :            : 
    4479                 :            : /*[clinic input]
    4480                 :            : _curses.unget_wch
    4481                 :            : 
    4482                 :            :     ch: object
    4483                 :            :     /
    4484                 :            : 
    4485                 :            : Push ch so the next get_wch() will return it.
    4486                 :            : [clinic start generated code]*/
    4487                 :            : 
    4488                 :            : static PyObject *
    4489                 :          0 : _curses_unget_wch(PyObject *module, PyObject *ch)
    4490                 :            : /*[clinic end generated code: output=1974c9fb01d37863 input=0d56dc65a46feebb]*/
    4491                 :            : {
    4492                 :            :     wchar_t wch;
    4493                 :            : 
    4494         [ #  # ]:          0 :     PyCursesInitialised;
    4495                 :            : 
    4496         [ #  # ]:          0 :     if (!PyCurses_ConvertToWchar_t(ch, &wch))
    4497                 :          0 :         return NULL;
    4498                 :          0 :     return PyCursesCheckERR(unget_wch(wch), "unget_wch");
    4499                 :            : }
    4500                 :            : #endif
    4501                 :            : 
    4502                 :            : #ifdef HAVE_CURSES_USE_ENV
    4503                 :            : /*[clinic input]
    4504                 :            : _curses.use_env
    4505                 :            : 
    4506                 :            :     flag: bool
    4507                 :            :     /
    4508                 :            : 
    4509                 :            : Use environment variables LINES and COLUMNS.
    4510                 :            : 
    4511                 :            : If used, this function should be called before initscr() or newterm() are
    4512                 :            : called.
    4513                 :            : 
    4514                 :            : When flag is False, the values of lines and columns specified in the terminfo
    4515                 :            : database will be used, even if environment variables LINES and COLUMNS (used
    4516                 :            : by default) are set, or if curses is running in a window (in which case
    4517                 :            : default behavior would be to use the window size if LINES and COLUMNS are
    4518                 :            : not set).
    4519                 :            : [clinic start generated code]*/
    4520                 :            : 
    4521                 :            : static PyObject *
    4522                 :          0 : _curses_use_env_impl(PyObject *module, int flag)
    4523                 :            : /*[clinic end generated code: output=b2c445e435c0b164 input=06ac30948f2d78e4]*/
    4524                 :            : {
    4525                 :          0 :     use_env(flag);
    4526                 :          0 :     Py_RETURN_NONE;
    4527                 :            : }
    4528                 :            : #endif
    4529                 :            : 
    4530                 :            : #ifndef STRICT_SYSV_CURSES
    4531                 :            : /*[clinic input]
    4532                 :            : _curses.use_default_colors
    4533                 :            : 
    4534                 :            : Allow use of default values for colors on terminals supporting this feature.
    4535                 :            : 
    4536                 :            : Use this to support transparency in your application.  The default color
    4537                 :            : is assigned to the color number -1.
    4538                 :            : [clinic start generated code]*/
    4539                 :            : 
    4540                 :            : static PyObject *
    4541                 :          0 : _curses_use_default_colors_impl(PyObject *module)
    4542                 :            : /*[clinic end generated code: output=a3b81ff71dd901be input=656844367470e8fc]*/
    4543                 :            : {
    4544                 :            :     int code;
    4545                 :            : 
    4546         [ #  # ]:          0 :     PyCursesInitialised;
    4547         [ #  # ]:          0 :     PyCursesInitialisedColor;
    4548                 :            : 
    4549                 :          0 :     code = use_default_colors();
    4550         [ #  # ]:          0 :     if (code != ERR) {
    4551                 :          0 :         Py_RETURN_NONE;
    4552                 :            :     } else {
    4553                 :          0 :         PyErr_SetString(PyCursesError, "use_default_colors() returned ERR");
    4554                 :          0 :         return NULL;
    4555                 :            :     }
    4556                 :            : }
    4557                 :            : #endif /* STRICT_SYSV_CURSES */
    4558                 :            : 
    4559                 :            : 
    4560                 :            : #ifdef NCURSES_VERSION
    4561                 :            : 
    4562                 :            : PyDoc_STRVAR(ncurses_version__doc__,
    4563                 :            : "curses.ncurses_version\n\
    4564                 :            : \n\
    4565                 :            : Ncurses version information as a named tuple.");
    4566                 :            : 
    4567                 :            : static PyStructSequence_Field ncurses_version_fields[] = {
    4568                 :            :     {"major", "Major release number"},
    4569                 :            :     {"minor", "Minor release number"},
    4570                 :            :     {"patch", "Patch release number"},
    4571                 :            :     {0}
    4572                 :            : };
    4573                 :            : 
    4574                 :            : static PyStructSequence_Desc ncurses_version_desc = {
    4575                 :            :     "curses.ncurses_version",  /* name */
    4576                 :            :     ncurses_version__doc__,    /* doc */
    4577                 :            :     ncurses_version_fields,    /* fields */
    4578                 :            :     3
    4579                 :            : };
    4580                 :            : 
    4581                 :            : static PyObject *
    4582                 :          1 : make_ncurses_version(PyTypeObject *type)
    4583                 :            : {
    4584                 :            :     PyObject *ncurses_version;
    4585                 :          1 :     int pos = 0;
    4586                 :            : 
    4587                 :          1 :     ncurses_version = PyStructSequence_New(type);
    4588         [ -  + ]:          1 :     if (ncurses_version == NULL) {
    4589                 :          0 :         return NULL;
    4590                 :            :     }
    4591                 :            : 
    4592                 :            : #define SetIntItem(flag) \
    4593                 :            :     PyStructSequence_SET_ITEM(ncurses_version, pos++, PyLong_FromLong(flag)); \
    4594                 :            :     if (PyErr_Occurred()) { \
    4595                 :            :         Py_CLEAR(ncurses_version); \
    4596                 :            :         return NULL; \
    4597                 :            :     }
    4598                 :            : 
    4599   [ -  +  -  - ]:          1 :     SetIntItem(NCURSES_VERSION_MAJOR)
    4600   [ -  +  -  - ]:          1 :     SetIntItem(NCURSES_VERSION_MINOR)
    4601   [ -  +  -  - ]:          1 :     SetIntItem(NCURSES_VERSION_PATCH)
    4602                 :            : #undef SetIntItem
    4603                 :            : 
    4604                 :          1 :     return ncurses_version;
    4605                 :            : }
    4606                 :            : 
    4607                 :            : #endif /* NCURSES_VERSION */
    4608                 :            : 
    4609                 :            : /*[clinic input]
    4610                 :            : _curses.has_extended_color_support
    4611                 :            : 
    4612                 :            : Return True if the module supports extended colors; otherwise, return False.
    4613                 :            : 
    4614                 :            : Extended color support allows more than 256 color-pairs for terminals
    4615                 :            : that support more than 16 colors (e.g. xterm-256color).
    4616                 :            : [clinic start generated code]*/
    4617                 :            : 
    4618                 :            : static PyObject *
    4619                 :          0 : _curses_has_extended_color_support_impl(PyObject *module)
    4620                 :            : /*[clinic end generated code: output=68f1be2b57d92e22 input=4b905f046e35ee9f]*/
    4621                 :            : {
    4622                 :          0 :     return PyBool_FromLong(_NCURSES_EXTENDED_COLOR_FUNCS);
    4623                 :            : }
    4624                 :            : 
    4625                 :            : /* List of functions defined in the module */
    4626                 :            : 
    4627                 :            : static PyMethodDef PyCurses_methods[] = {
    4628                 :            :     _CURSES_BAUDRATE_METHODDEF
    4629                 :            :     _CURSES_BEEP_METHODDEF
    4630                 :            :     _CURSES_CAN_CHANGE_COLOR_METHODDEF
    4631                 :            :     _CURSES_CBREAK_METHODDEF
    4632                 :            :     _CURSES_COLOR_CONTENT_METHODDEF
    4633                 :            :     _CURSES_COLOR_PAIR_METHODDEF
    4634                 :            :     _CURSES_CURS_SET_METHODDEF
    4635                 :            :     _CURSES_DEF_PROG_MODE_METHODDEF
    4636                 :            :     _CURSES_DEF_SHELL_MODE_METHODDEF
    4637                 :            :     _CURSES_DELAY_OUTPUT_METHODDEF
    4638                 :            :     _CURSES_DOUPDATE_METHODDEF
    4639                 :            :     _CURSES_ECHO_METHODDEF
    4640                 :            :     _CURSES_ENDWIN_METHODDEF
    4641                 :            :     _CURSES_ERASECHAR_METHODDEF
    4642                 :            :     _CURSES_FILTER_METHODDEF
    4643                 :            :     _CURSES_FLASH_METHODDEF
    4644                 :            :     _CURSES_FLUSHINP_METHODDEF
    4645                 :            :     _CURSES_GETMOUSE_METHODDEF
    4646                 :            :     _CURSES_UNGETMOUSE_METHODDEF
    4647                 :            :     _CURSES_GETSYX_METHODDEF
    4648                 :            :     _CURSES_GETWIN_METHODDEF
    4649                 :            :     _CURSES_HAS_COLORS_METHODDEF
    4650                 :            :     _CURSES_HAS_EXTENDED_COLOR_SUPPORT_METHODDEF
    4651                 :            :     _CURSES_HAS_IC_METHODDEF
    4652                 :            :     _CURSES_HAS_IL_METHODDEF
    4653                 :            :     _CURSES_HAS_KEY_METHODDEF
    4654                 :            :     _CURSES_HALFDELAY_METHODDEF
    4655                 :            :     _CURSES_INIT_COLOR_METHODDEF
    4656                 :            :     _CURSES_INIT_PAIR_METHODDEF
    4657                 :            :     _CURSES_INITSCR_METHODDEF
    4658                 :            :     _CURSES_INTRFLUSH_METHODDEF
    4659                 :            :     _CURSES_ISENDWIN_METHODDEF
    4660                 :            :     _CURSES_IS_TERM_RESIZED_METHODDEF
    4661                 :            :     _CURSES_KEYNAME_METHODDEF
    4662                 :            :     _CURSES_KILLCHAR_METHODDEF
    4663                 :            :     _CURSES_LONGNAME_METHODDEF
    4664                 :            :     _CURSES_META_METHODDEF
    4665                 :            :     _CURSES_MOUSEINTERVAL_METHODDEF
    4666                 :            :     _CURSES_MOUSEMASK_METHODDEF
    4667                 :            :     _CURSES_NAPMS_METHODDEF
    4668                 :            :     _CURSES_NEWPAD_METHODDEF
    4669                 :            :     _CURSES_NEWWIN_METHODDEF
    4670                 :            :     _CURSES_NL_METHODDEF
    4671                 :            :     _CURSES_NOCBREAK_METHODDEF
    4672                 :            :     _CURSES_NOECHO_METHODDEF
    4673                 :            :     _CURSES_NONL_METHODDEF
    4674                 :            :     _CURSES_NOQIFLUSH_METHODDEF
    4675                 :            :     _CURSES_NORAW_METHODDEF
    4676                 :            :     _CURSES_PAIR_CONTENT_METHODDEF
    4677                 :            :     _CURSES_PAIR_NUMBER_METHODDEF
    4678                 :            :     _CURSES_PUTP_METHODDEF
    4679                 :            :     _CURSES_QIFLUSH_METHODDEF
    4680                 :            :     _CURSES_RAW_METHODDEF
    4681                 :            :     _CURSES_RESET_PROG_MODE_METHODDEF
    4682                 :            :     _CURSES_RESET_SHELL_MODE_METHODDEF
    4683                 :            :     _CURSES_RESETTY_METHODDEF
    4684                 :            :     _CURSES_RESIZETERM_METHODDEF
    4685                 :            :     _CURSES_RESIZE_TERM_METHODDEF
    4686                 :            :     _CURSES_SAVETTY_METHODDEF
    4687                 :            : #if defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102
    4688                 :            :     _CURSES_GET_ESCDELAY_METHODDEF
    4689                 :            :     _CURSES_SET_ESCDELAY_METHODDEF
    4690                 :            : #endif
    4691                 :            :     _CURSES_GET_TABSIZE_METHODDEF
    4692                 :            :     _CURSES_SET_TABSIZE_METHODDEF
    4693                 :            :     _CURSES_SETSYX_METHODDEF
    4694                 :            :     _CURSES_SETUPTERM_METHODDEF
    4695                 :            :     _CURSES_START_COLOR_METHODDEF
    4696                 :            :     _CURSES_TERMATTRS_METHODDEF
    4697                 :            :     _CURSES_TERMNAME_METHODDEF
    4698                 :            :     _CURSES_TIGETFLAG_METHODDEF
    4699                 :            :     _CURSES_TIGETNUM_METHODDEF
    4700                 :            :     _CURSES_TIGETSTR_METHODDEF
    4701                 :            :     _CURSES_TPARM_METHODDEF
    4702                 :            :     _CURSES_TYPEAHEAD_METHODDEF
    4703                 :            :     _CURSES_UNCTRL_METHODDEF
    4704                 :            :     _CURSES_UNGETCH_METHODDEF
    4705                 :            :     _CURSES_UPDATE_LINES_COLS_METHODDEF
    4706                 :            :     _CURSES_UNGET_WCH_METHODDEF
    4707                 :            :     _CURSES_USE_ENV_METHODDEF
    4708                 :            :     _CURSES_USE_DEFAULT_COLORS_METHODDEF
    4709                 :            :     {NULL,                  NULL}         /* sentinel */
    4710                 :            : };
    4711                 :            : 
    4712                 :            : /* Initialization function for the module */
    4713                 :            : 
    4714                 :            : 
    4715                 :            : static struct PyModuleDef _cursesmodule = {
    4716                 :            :     PyModuleDef_HEAD_INIT,
    4717                 :            :     "_curses",
    4718                 :            :     NULL,
    4719                 :            :     -1,
    4720                 :            :     PyCurses_methods,
    4721                 :            :     NULL,
    4722                 :            :     NULL,
    4723                 :            :     NULL,
    4724                 :            :     NULL
    4725                 :            : };
    4726                 :            : 
    4727                 :            : static void
    4728                 :          1 : curses_destructor(PyObject *op)
    4729                 :            : {
    4730                 :          1 :     void *ptr = PyCapsule_GetPointer(op, PyCurses_CAPSULE_NAME);
    4731                 :          1 :     Py_DECREF(*(void **)ptr);
    4732                 :          1 :     PyMem_Free(ptr);
    4733                 :          1 : }
    4734                 :            : 
    4735                 :            : PyMODINIT_FUNC
    4736                 :          1 : PyInit__curses(void)
    4737                 :            : {
    4738                 :            :     PyObject *m, *d, *v, *c_api_object;
    4739                 :            : 
    4740                 :            :     /* Initialize object type */
    4741         [ -  + ]:          1 :     if (PyType_Ready(&PyCursesWindow_Type) < 0)
    4742                 :          0 :         return NULL;
    4743                 :            : 
    4744                 :            :     /* Create the module and add the functions */
    4745                 :          1 :     m = PyModule_Create(&_cursesmodule);
    4746         [ -  + ]:          1 :     if (m == NULL)
    4747                 :          0 :         return NULL;
    4748                 :            : 
    4749                 :            :     /* Add some symbolic constants to the module */
    4750                 :          1 :     d = PyModule_GetDict(m);
    4751         [ -  + ]:          1 :     if (d == NULL)
    4752                 :          0 :         return NULL;
    4753                 :          1 :     ModDict = d; /* For PyCurses_InitScr to use later */
    4754                 :            : 
    4755                 :          1 :     void **PyCurses_API = PyMem_Calloc(PyCurses_API_pointers, sizeof(void *));
    4756         [ -  + ]:          1 :     if (PyCurses_API == NULL) {
    4757                 :          0 :         PyErr_NoMemory();
    4758                 :          0 :         return NULL;
    4759                 :            :     }
    4760                 :            :     /* Initialize the C API pointer array */
    4761                 :          1 :     PyCurses_API[0] = (void *)Py_NewRef(&PyCursesWindow_Type);
    4762                 :          1 :     PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled;
    4763                 :          1 :     PyCurses_API[2] = (void *)func_PyCursesInitialised;
    4764                 :          1 :     PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;
    4765                 :            : 
    4766                 :            :     /* Add a capsule for the C API */
    4767                 :          1 :     c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME,
    4768                 :            :                                  curses_destructor);
    4769         [ -  + ]:          1 :     if (c_api_object == NULL) {
    4770                 :          0 :         Py_DECREF(PyCurses_API[0]);
    4771                 :          0 :         PyMem_Free(PyCurses_API);
    4772                 :          0 :         return NULL;
    4773                 :            :     }
    4774         [ -  + ]:          1 :     if (PyDict_SetItemString(d, "_C_API", c_api_object) < 0) {
    4775                 :          0 :         Py_DECREF(c_api_object);
    4776                 :          0 :         return NULL;
    4777                 :            :     }
    4778                 :          1 :     Py_DECREF(c_api_object);
    4779                 :            : 
    4780                 :            :     /* For exception curses.error */
    4781                 :          1 :     PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
    4782                 :          1 :     PyDict_SetItemString(d, "error", PyCursesError);
    4783                 :            : 
    4784                 :            :     /* Make the version available */
    4785                 :          1 :     v = PyBytes_FromString(PyCursesVersion);
    4786                 :          1 :     PyDict_SetItemString(d, "version", v);
    4787                 :          1 :     PyDict_SetItemString(d, "__version__", v);
    4788                 :          1 :     Py_DECREF(v);
    4789                 :            : 
    4790                 :            : #ifdef NCURSES_VERSION
    4791                 :            :     /* ncurses_version */
    4792                 :            :     PyTypeObject *version_type;
    4793                 :          1 :     version_type = _PyStructSequence_NewType(&ncurses_version_desc,
    4794                 :            :                                              Py_TPFLAGS_DISALLOW_INSTANTIATION);
    4795         [ -  + ]:          1 :     if (version_type == NULL) {
    4796                 :          0 :         return NULL;
    4797                 :            :     }
    4798                 :          1 :     v = make_ncurses_version(version_type);
    4799                 :          1 :     Py_DECREF(version_type);
    4800         [ -  + ]:          1 :     if (v == NULL) {
    4801                 :          0 :         return NULL;
    4802                 :            :     }
    4803                 :          1 :     PyDict_SetItemString(d, "ncurses_version", v);
    4804                 :          1 :     Py_DECREF(v);
    4805                 :            : #endif /* NCURSES_VERSION */
    4806                 :            : 
    4807   [ +  -  +  - ]:          1 :     SetDictInt("ERR", ERR);
    4808   [ +  -  +  - ]:          1 :     SetDictInt("OK", OK);
    4809                 :            : 
    4810                 :            :     /* Here are some attributes you can add to chars to print */
    4811                 :            : 
    4812   [ +  -  +  - ]:          1 :     SetDictInt("A_ATTRIBUTES",      A_ATTRIBUTES);
    4813   [ +  -  +  - ]:          1 :     SetDictInt("A_NORMAL",              A_NORMAL);
    4814   [ +  -  +  - ]:          1 :     SetDictInt("A_STANDOUT",            A_STANDOUT);
    4815   [ +  -  +  - ]:          1 :     SetDictInt("A_UNDERLINE",           A_UNDERLINE);
    4816   [ +  -  +  - ]:          1 :     SetDictInt("A_REVERSE",             A_REVERSE);
    4817   [ +  -  +  - ]:          1 :     SetDictInt("A_BLINK",               A_BLINK);
    4818   [ +  -  +  - ]:          1 :     SetDictInt("A_DIM",                 A_DIM);
    4819   [ +  -  +  - ]:          1 :     SetDictInt("A_BOLD",                A_BOLD);
    4820   [ +  -  +  - ]:          1 :     SetDictInt("A_ALTCHARSET",          A_ALTCHARSET);
    4821   [ +  -  +  - ]:          1 :     SetDictInt("A_INVIS",           A_INVIS);
    4822   [ +  -  +  - ]:          1 :     SetDictInt("A_PROTECT",         A_PROTECT);
    4823   [ +  -  +  - ]:          1 :     SetDictInt("A_CHARTEXT",        A_CHARTEXT);
    4824   [ +  -  +  - ]:          1 :     SetDictInt("A_COLOR",           A_COLOR);
    4825                 :            : 
    4826                 :            :     /* The following are never available with strict SYSV curses */
    4827                 :            : #ifdef A_HORIZONTAL
    4828   [ +  -  +  - ]:          1 :     SetDictInt("A_HORIZONTAL",      A_HORIZONTAL);
    4829                 :            : #endif
    4830                 :            : #ifdef A_LEFT
    4831   [ +  -  +  - ]:          1 :     SetDictInt("A_LEFT",            A_LEFT);
    4832                 :            : #endif
    4833                 :            : #ifdef A_LOW
    4834   [ +  -  +  - ]:          1 :     SetDictInt("A_LOW",             A_LOW);
    4835                 :            : #endif
    4836                 :            : #ifdef A_RIGHT
    4837   [ +  -  +  - ]:          1 :     SetDictInt("A_RIGHT",           A_RIGHT);
    4838                 :            : #endif
    4839                 :            : #ifdef A_TOP
    4840   [ +  -  +  - ]:          1 :     SetDictInt("A_TOP",             A_TOP);
    4841                 :            : #endif
    4842                 :            : #ifdef A_VERTICAL
    4843   [ +  -  +  - ]:          1 :     SetDictInt("A_VERTICAL",        A_VERTICAL);
    4844                 :            : #endif
    4845                 :            : 
    4846                 :            :     /* ncurses extension */
    4847                 :            : #ifdef A_ITALIC
    4848   [ +  -  +  - ]:          1 :     SetDictInt("A_ITALIC",          A_ITALIC);
    4849                 :            : #endif
    4850                 :            : 
    4851   [ +  -  +  - ]:          1 :     SetDictInt("COLOR_BLACK",       COLOR_BLACK);
    4852   [ +  -  +  - ]:          1 :     SetDictInt("COLOR_RED",         COLOR_RED);
    4853   [ +  -  +  - ]:          1 :     SetDictInt("COLOR_GREEN",       COLOR_GREEN);
    4854   [ +  -  +  - ]:          1 :     SetDictInt("COLOR_YELLOW",      COLOR_YELLOW);
    4855   [ +  -  +  - ]:          1 :     SetDictInt("COLOR_BLUE",        COLOR_BLUE);
    4856   [ +  -  +  - ]:          1 :     SetDictInt("COLOR_MAGENTA",     COLOR_MAGENTA);
    4857   [ +  -  +  - ]:          1 :     SetDictInt("COLOR_CYAN",        COLOR_CYAN);
    4858   [ +  -  +  - ]:          1 :     SetDictInt("COLOR_WHITE",       COLOR_WHITE);
    4859                 :            : 
    4860                 :            : #ifdef NCURSES_MOUSE_VERSION
    4861                 :            :     /* Mouse-related constants */
    4862   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON1_PRESSED",          BUTTON1_PRESSED);
    4863   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON1_RELEASED",         BUTTON1_RELEASED);
    4864   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON1_CLICKED",          BUTTON1_CLICKED);
    4865   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON1_DOUBLE_CLICKED",   BUTTON1_DOUBLE_CLICKED);
    4866   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON1_TRIPLE_CLICKED",   BUTTON1_TRIPLE_CLICKED);
    4867                 :            : 
    4868   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON2_PRESSED",          BUTTON2_PRESSED);
    4869   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON2_RELEASED",         BUTTON2_RELEASED);
    4870   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON2_CLICKED",          BUTTON2_CLICKED);
    4871   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON2_DOUBLE_CLICKED",   BUTTON2_DOUBLE_CLICKED);
    4872   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON2_TRIPLE_CLICKED",   BUTTON2_TRIPLE_CLICKED);
    4873                 :            : 
    4874   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON3_PRESSED",          BUTTON3_PRESSED);
    4875   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON3_RELEASED",         BUTTON3_RELEASED);
    4876   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON3_CLICKED",          BUTTON3_CLICKED);
    4877   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON3_DOUBLE_CLICKED",   BUTTON3_DOUBLE_CLICKED);
    4878   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON3_TRIPLE_CLICKED",   BUTTON3_TRIPLE_CLICKED);
    4879                 :            : 
    4880   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON4_PRESSED",          BUTTON4_PRESSED);
    4881   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON4_RELEASED",         BUTTON4_RELEASED);
    4882   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON4_CLICKED",          BUTTON4_CLICKED);
    4883   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON4_DOUBLE_CLICKED",   BUTTON4_DOUBLE_CLICKED);
    4884   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON4_TRIPLE_CLICKED",   BUTTON4_TRIPLE_CLICKED);
    4885                 :            : 
    4886                 :            : #if NCURSES_MOUSE_VERSION > 1
    4887   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON5_PRESSED",          BUTTON5_PRESSED);
    4888   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON5_RELEASED",         BUTTON5_RELEASED);
    4889   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON5_CLICKED",          BUTTON5_CLICKED);
    4890   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON5_DOUBLE_CLICKED",   BUTTON5_DOUBLE_CLICKED);
    4891   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON5_TRIPLE_CLICKED",   BUTTON5_TRIPLE_CLICKED);
    4892                 :            : #endif
    4893                 :            : 
    4894   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON_SHIFT",             BUTTON_SHIFT);
    4895   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON_CTRL",              BUTTON_CTRL);
    4896   [ +  -  +  - ]:          1 :     SetDictInt("BUTTON_ALT",               BUTTON_ALT);
    4897                 :            : 
    4898   [ +  -  +  - ]:          1 :     SetDictInt("ALL_MOUSE_EVENTS",         ALL_MOUSE_EVENTS);
    4899   [ +  -  +  - ]:          1 :     SetDictInt("REPORT_MOUSE_POSITION",    REPORT_MOUSE_POSITION);
    4900                 :            : #endif
    4901                 :            :     /* Now set everything up for KEY_ variables */
    4902                 :            :     {
    4903                 :            :         int key;
    4904                 :            :         char *key_n;
    4905                 :            :         char *key_n2;
    4906         [ +  + ]:        255 :         for (key=KEY_MIN;key < KEY_MAX; key++) {
    4907                 :        254 :             key_n = (char *)keyname(key);
    4908   [ +  +  -  + ]:        254 :             if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
    4909                 :        100 :                 continue;
    4910         [ +  + ]:        154 :             if (strncmp(key_n,"KEY_F(",6)==0) {
    4911                 :            :                 char *p1, *p2;
    4912                 :         64 :                 key_n2 = PyMem_Malloc(strlen(key_n)+1);
    4913         [ -  + ]:         64 :                 if (!key_n2) {
    4914                 :          0 :                     PyErr_NoMemory();
    4915                 :          0 :                     break;
    4916                 :            :                 }
    4917                 :         64 :                 p1 = key_n;
    4918                 :         64 :                 p2 = key_n2;
    4919         [ +  + ]:        630 :                 while (*p1) {
    4920   [ +  +  +  + ]:        566 :                     if (*p1 != '(' && *p1 != ')') {
    4921                 :        438 :                         *p2 = *p1;
    4922                 :        438 :                         p2++;
    4923                 :            :                     }
    4924                 :        566 :                     p1++;
    4925                 :            :                 }
    4926                 :         64 :                 *p2 = (char)0;
    4927                 :            :             } else
    4928                 :         90 :                 key_n2 = key_n;
    4929   [ +  -  +  - ]:        154 :             SetDictInt(key_n2,key);
    4930         [ +  + ]:        154 :             if (key_n2 != key_n)
    4931                 :         64 :                 PyMem_Free(key_n2);
    4932                 :            :         }
    4933   [ +  -  +  - ]:          1 :         SetDictInt("KEY_MIN", KEY_MIN);
    4934   [ +  -  +  - ]:          1 :         SetDictInt("KEY_MAX", KEY_MAX);
    4935                 :            :     }
    4936                 :            : 
    4937         [ -  + ]:          1 :     if (PyModule_AddType(m, &PyCursesWindow_Type) < 0) {
    4938                 :          0 :         return NULL;
    4939                 :            :     }
    4940                 :          1 :     return m;
    4941                 :            : }

Generated by: LCOV version 1.14