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