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