| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | :mod:`curses` --- Terminal handling for character-cell displays | 
 | 2 | =============================================================== | 
 | 3 |  | 
 | 4 | .. module:: curses | 
| Georg Brandl | 71515ca | 2009-05-17 12:29:12 +0000 | [diff] [blame] | 5 |    :synopsis: An interface to the curses library, providing portable | 
 | 6 |               terminal handling. | 
| Georg Brandl | 495f7b5 | 2009-10-27 15:28:25 +0000 | [diff] [blame] | 7 |    :platform: Unix | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 8 | .. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il> | 
 | 9 | .. sectionauthor:: Eric Raymond <esr@thyrsus.com> | 
 | 10 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 11 | The :mod:`curses` module provides an interface to the curses library, the | 
 | 12 | de-facto standard for portable advanced terminal handling. | 
 | 13 |  | 
 | 14 | While curses is most widely used in the Unix environment, versions are available | 
 | 15 | for DOS, OS/2, and possibly other systems as well.  This extension module is | 
 | 16 | designed to match the API of ncurses, an open-source curses library hosted on | 
 | 17 | Linux and the BSD variants of Unix. | 
 | 18 |  | 
| Christian Heimes | 587c2bf | 2008-01-19 16:21:02 +0000 | [diff] [blame] | 19 | .. note:: | 
 | 20 |  | 
 | 21 |    Since version 5.4, the ncurses library decides how to interpret non-ASCII data | 
 | 22 |    using the ``nl_langinfo`` function.  That means that you have to call | 
 | 23 |    :func:`locale.setlocale` in the application and encode Unicode strings | 
 | 24 |    using one of the system's available encodings.  This example uses the | 
 | 25 |    system's default encoding:: | 
 | 26 |  | 
 | 27 |       import locale | 
 | 28 |       locale.setlocale(locale.LC_ALL, '') | 
 | 29 |       code = locale.getpreferredencoding() | 
 | 30 |  | 
 | 31 |    Then use *code* as the encoding for :meth:`str.encode` calls. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 32 |  | 
 | 33 | .. seealso:: | 
 | 34 |  | 
 | 35 |    Module :mod:`curses.ascii` | 
 | 36 |       Utilities for working with ASCII characters, regardless of your locale settings. | 
 | 37 |  | 
 | 38 |    Module :mod:`curses.panel` | 
 | 39 |       A panel stack extension that adds depth to  curses windows. | 
 | 40 |  | 
 | 41 |    Module :mod:`curses.textpad` | 
 | 42 |       Editable text widget for curses supporting  :program:`Emacs`\ -like bindings. | 
 | 43 |  | 
| Christian Heimes | 2202f87 | 2008-02-06 14:31:34 +0000 | [diff] [blame] | 44 |    :ref:`curses-howto` | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 45 |       Tutorial material on using curses with Python, by Andrew Kuchling and Eric | 
| Christian Heimes | 2202f87 | 2008-02-06 14:31:34 +0000 | [diff] [blame] | 46 |       Raymond. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 47 |  | 
| Georg Brandl | 59b4472 | 2010-12-30 22:12:40 +0000 | [diff] [blame] | 48 |    The :file:`Tools/demo/` directory in the Python source distribution contains | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 49 |    some example programs using the curses bindings provided by this module. | 
 | 50 |  | 
 | 51 |  | 
 | 52 | .. _curses-functions: | 
 | 53 |  | 
 | 54 | Functions | 
 | 55 | --------- | 
 | 56 |  | 
 | 57 | The module :mod:`curses` defines the following exception: | 
 | 58 |  | 
 | 59 |  | 
 | 60 | .. exception:: error | 
 | 61 |  | 
 | 62 |    Exception raised when a curses library function returns an error. | 
 | 63 |  | 
 | 64 | .. note:: | 
 | 65 |  | 
 | 66 |    Whenever *x* or *y* arguments to a function or a method are optional, they | 
 | 67 |    default to the current cursor location. Whenever *attr* is optional, it defaults | 
 | 68 |    to :const:`A_NORMAL`. | 
 | 69 |  | 
 | 70 | The module :mod:`curses` defines the following functions: | 
 | 71 |  | 
 | 72 |  | 
 | 73 | .. function:: baudrate() | 
 | 74 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 75 |    Return the output speed of the terminal in bits per second.  On software | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 76 |    terminal emulators it will have a fixed high value. Included for historical | 
 | 77 |    reasons; in former times, it was used to  write output loops for time delays and | 
 | 78 |    occasionally to change interfaces depending on the line speed. | 
 | 79 |  | 
 | 80 |  | 
 | 81 | .. function:: beep() | 
 | 82 |  | 
 | 83 |    Emit a short attention sound. | 
 | 84 |  | 
 | 85 |  | 
 | 86 | .. function:: can_change_color() | 
 | 87 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 88 |    Return ``True`` or ``False``, depending on whether the programmer can change the colors | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 89 |    displayed by the terminal. | 
 | 90 |  | 
 | 91 |  | 
 | 92 | .. function:: cbreak() | 
 | 93 |  | 
 | 94 |    Enter cbreak mode.  In cbreak mode (sometimes called "rare" mode) normal tty | 
 | 95 |    line buffering is turned off and characters are available to be read one by one. | 
 | 96 |    However, unlike raw mode, special characters (interrupt, quit, suspend, and flow | 
 | 97 |    control) retain their effects on the tty driver and calling program.  Calling | 
 | 98 |    first :func:`raw` then :func:`cbreak` leaves the terminal in cbreak mode. | 
 | 99 |  | 
 | 100 |  | 
 | 101 | .. function:: color_content(color_number) | 
 | 102 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 103 |    Return the intensity of the red, green, and blue (RGB) components in the color | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 104 |    *color_number*, which must be between ``0`` and :const:`COLORS`.  A 3-tuple is | 
 | 105 |    returned, containing the R,G,B values for the given color, which will be between | 
 | 106 |    ``0`` (no component) and ``1000`` (maximum amount of component). | 
 | 107 |  | 
 | 108 |  | 
 | 109 | .. function:: color_pair(color_number) | 
 | 110 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 111 |    Return the attribute value for displaying text in the specified color.  This | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 112 |    attribute value can be combined with :const:`A_STANDOUT`, :const:`A_REVERSE`, | 
 | 113 |    and the other :const:`A_\*` attributes.  :func:`pair_number` is the counterpart | 
 | 114 |    to this function. | 
 | 115 |  | 
 | 116 |  | 
 | 117 | .. function:: curs_set(visibility) | 
 | 118 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 119 |    Set the cursor state.  *visibility* can be set to 0, 1, or 2, for invisible, | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 120 |    normal, or very visible.  If the terminal supports the visibility requested, the | 
 | 121 |    previous cursor state is returned; otherwise, an exception is raised.  On many | 
 | 122 |    terminals, the "visible" mode is an underline cursor and the "very visible" mode | 
 | 123 |    is a block cursor. | 
 | 124 |  | 
 | 125 |  | 
 | 126 | .. function:: def_prog_mode() | 
 | 127 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 128 |    Save the current terminal mode as the "program" mode, the mode when the running | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 129 |    program is using curses.  (Its counterpart is the "shell" mode, for when the | 
 | 130 |    program is not in curses.)  Subsequent calls to :func:`reset_prog_mode` will | 
 | 131 |    restore this mode. | 
 | 132 |  | 
 | 133 |  | 
 | 134 | .. function:: def_shell_mode() | 
 | 135 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 136 |    Save the current terminal mode as the "shell" mode, the mode when the running | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 137 |    program is not using curses.  (Its counterpart is the "program" mode, when the | 
 | 138 |    program is using curses capabilities.) Subsequent calls to | 
 | 139 |    :func:`reset_shell_mode` will restore this mode. | 
 | 140 |  | 
 | 141 |  | 
 | 142 | .. function:: delay_output(ms) | 
 | 143 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 144 |    Insert an *ms* millisecond pause in output. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 145 |  | 
 | 146 |  | 
 | 147 | .. function:: doupdate() | 
 | 148 |  | 
 | 149 |    Update the physical screen.  The curses library keeps two data structures, one | 
 | 150 |    representing the current physical screen contents and a virtual screen | 
 | 151 |    representing the desired next state.  The :func:`doupdate` ground updates the | 
 | 152 |    physical screen to match the virtual screen. | 
 | 153 |  | 
 | 154 |    The virtual screen may be updated by a :meth:`noutrefresh` call after write | 
 | 155 |    operations such as :meth:`addstr` have been performed on a window.  The normal | 
 | 156 |    :meth:`refresh` call is simply :meth:`noutrefresh` followed by :func:`doupdate`; | 
 | 157 |    if you have to update multiple windows, you can speed performance and perhaps | 
 | 158 |    reduce screen flicker by issuing :meth:`noutrefresh` calls on all windows, | 
 | 159 |    followed by a single :func:`doupdate`. | 
 | 160 |  | 
 | 161 |  | 
 | 162 | .. function:: echo() | 
 | 163 |  | 
 | 164 |    Enter echo mode.  In echo mode, each character input is echoed to the screen as | 
 | 165 |    it is entered. | 
 | 166 |  | 
 | 167 |  | 
 | 168 | .. function:: endwin() | 
 | 169 |  | 
 | 170 |    De-initialize the library, and return terminal to normal status. | 
 | 171 |  | 
 | 172 |  | 
 | 173 | .. function:: erasechar() | 
 | 174 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 175 |    Return the user's current erase character.  Under Unix operating systems this | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 176 |    is a property of the controlling tty of the curses program, and is not set by | 
 | 177 |    the curses library itself. | 
 | 178 |  | 
 | 179 |  | 
 | 180 | .. function:: filter() | 
 | 181 |  | 
| Georg Brandl | 502d9a5 | 2009-07-26 15:02:41 +0000 | [diff] [blame] | 182 |    The :func:`.filter` routine, if used, must be called before :func:`initscr` is | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 183 |    called.  The effect is that, during those calls, :envvar:`LINES` is set to 1; the | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 184 |    capabilities clear, cup, cud, cud1, cuu1, cuu, vpa are disabled; and the home | 
 | 185 |    string is set to the value of cr. The effect is that the cursor is confined to | 
 | 186 |    the current line, and so are screen updates.  This may be used for enabling | 
 | 187 |    character-at-a-time  line editing without touching the rest of the screen. | 
 | 188 |  | 
 | 189 |  | 
 | 190 | .. function:: flash() | 
 | 191 |  | 
 | 192 |    Flash the screen.  That is, change it to reverse-video and then change it back | 
 | 193 |    in a short interval.  Some people prefer such as 'visible bell' to the audible | 
 | 194 |    attention signal produced by :func:`beep`. | 
 | 195 |  | 
 | 196 |  | 
 | 197 | .. function:: flushinp() | 
 | 198 |  | 
 | 199 |    Flush all input buffers.  This throws away any  typeahead  that  has been typed | 
 | 200 |    by the user and has not yet been processed by the program. | 
 | 201 |  | 
 | 202 |  | 
 | 203 | .. function:: getmouse() | 
 | 204 |  | 
 | 205 |    After :meth:`getch` returns :const:`KEY_MOUSE` to signal a mouse event, this | 
 | 206 |    method should be call to retrieve the queued mouse event, represented as a | 
 | 207 |    5-tuple ``(id, x, y, z, bstate)``. *id* is an ID value used to distinguish | 
 | 208 |    multiple devices, and *x*, *y*, *z* are the event's coordinates.  (*z* is | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 209 |    currently unused.)  *bstate* is an integer value whose bits will be set to | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 210 |    indicate the type of event, and will be the bitwise OR of one or more of the | 
 | 211 |    following constants, where *n* is the button number from 1 to 4: | 
 | 212 |    :const:`BUTTONn_PRESSED`, :const:`BUTTONn_RELEASED`, :const:`BUTTONn_CLICKED`, | 
 | 213 |    :const:`BUTTONn_DOUBLE_CLICKED`, :const:`BUTTONn_TRIPLE_CLICKED`, | 
 | 214 |    :const:`BUTTON_SHIFT`, :const:`BUTTON_CTRL`, :const:`BUTTON_ALT`. | 
 | 215 |  | 
 | 216 |  | 
 | 217 | .. function:: getsyx() | 
 | 218 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 219 |    Return the current coordinates of the virtual screen cursor in y and x.  If | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 220 |    leaveok is currently true, then -1,-1 is returned. | 
 | 221 |  | 
 | 222 |  | 
 | 223 | .. function:: getwin(file) | 
 | 224 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 225 |    Read window related data stored in the file by an earlier :func:`putwin` call. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 226 |    The routine then creates and initializes a new window using that data, returning | 
 | 227 |    the new window object. | 
 | 228 |  | 
 | 229 |  | 
 | 230 | .. function:: has_colors() | 
 | 231 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 232 |    Return ``True`` if the terminal can display colors; otherwise, return ``False``. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 233 |  | 
 | 234 |  | 
 | 235 | .. function:: has_ic() | 
 | 236 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 237 |    Return ``True`` if the terminal has insert- and delete-character capabilities. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 238 |    This function is included for historical reasons only, as all modern software | 
 | 239 |    terminal emulators have such capabilities. | 
 | 240 |  | 
 | 241 |  | 
 | 242 | .. function:: has_il() | 
 | 243 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 244 |    Return ``True`` if the terminal has insert- and delete-line capabilities, or can | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 245 |    simulate  them  using scrolling regions. This function is included for | 
 | 246 |    historical reasons only, as all modern software terminal emulators have such | 
 | 247 |    capabilities. | 
 | 248 |  | 
 | 249 |  | 
 | 250 | .. function:: has_key(ch) | 
 | 251 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 252 |    Take a key value *ch*, and return ``True`` if the current terminal type recognizes | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 253 |    a key with that value. | 
 | 254 |  | 
 | 255 |  | 
 | 256 | .. function:: halfdelay(tenths) | 
 | 257 |  | 
 | 258 |    Used for half-delay mode, which is similar to cbreak mode in that characters | 
 | 259 |    typed by the user are immediately available to the program. However, after | 
 | 260 |    blocking for *tenths* tenths of seconds, an exception is raised if nothing has | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 261 |    been typed.  The value of *tenths* must be a number between ``1`` and ``255``.  Use | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 262 |    :func:`nocbreak` to leave half-delay mode. | 
 | 263 |  | 
 | 264 |  | 
 | 265 | .. function:: init_color(color_number, r, g, b) | 
 | 266 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 267 |    Change the definition of a color, taking the number of the color to be changed | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 268 |    followed by three RGB values (for the amounts of red, green, and blue | 
 | 269 |    components).  The value of *color_number* must be between ``0`` and | 
 | 270 |    :const:`COLORS`.  Each of *r*, *g*, *b*, must be a value between ``0`` and | 
 | 271 |    ``1000``.  When :func:`init_color` is used, all occurrences of that color on the | 
 | 272 |    screen immediately change to the new definition.  This function is a no-op on | 
 | 273 |    most terminals; it is active only if :func:`can_change_color` returns ``1``. | 
 | 274 |  | 
 | 275 |  | 
 | 276 | .. function:: init_pair(pair_number, fg, bg) | 
 | 277 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 278 |    Change the definition of a color-pair.  It takes three arguments: the number of | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 279 |    the color-pair to be changed, the foreground color number, and the background | 
 | 280 |    color number.  The value of *pair_number* must be between ``1`` and | 
 | 281 |    ``COLOR_PAIRS - 1`` (the ``0`` color pair is wired to white on black and cannot | 
 | 282 |    be changed).  The value of *fg* and *bg* arguments must be between ``0`` and | 
 | 283 |    :const:`COLORS`.  If the color-pair was previously initialized, the screen is | 
 | 284 |    refreshed and all occurrences of that color-pair are changed to the new | 
 | 285 |    definition. | 
 | 286 |  | 
 | 287 |  | 
 | 288 | .. function:: initscr() | 
 | 289 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 290 |    Initialize the library. Return a :class:`WindowObject` which represents the | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 291 |    whole screen. | 
 | 292 |  | 
 | 293 |    .. note:: | 
 | 294 |  | 
 | 295 |       If there is an error opening the terminal, the underlying curses library may | 
 | 296 |       cause the interpreter to exit. | 
 | 297 |  | 
 | 298 |  | 
| Ezio Melotti | 4850d52 | 2011-06-26 13:34:56 +0300 | [diff] [blame] | 299 | .. function:: is_term_resized(nlines, ncols) | 
 | 300 |  | 
 | 301 |    Return ``True`` if :func:`resize_term` would modify the window structure, | 
 | 302 |    ``False`` otherwise. | 
 | 303 |  | 
 | 304 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 305 | .. function:: isendwin() | 
 | 306 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 307 |    Return ``True`` if :func:`endwin` has been called (that is, the  curses library has | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 308 |    been deinitialized). | 
 | 309 |  | 
 | 310 |  | 
 | 311 | .. function:: keyname(k) | 
 | 312 |  | 
 | 313 |    Return the name of the key numbered *k*.  The name of a key generating printable | 
 | 314 |    ASCII character is the key's character.  The name of a control-key combination | 
 | 315 |    is a two-character string consisting of a caret followed by the corresponding | 
 | 316 |    printable ASCII character.  The name of an alt-key combination (128-255) is a | 
 | 317 |    string consisting of the prefix 'M-' followed by the name of the corresponding | 
 | 318 |    ASCII character. | 
 | 319 |  | 
 | 320 |  | 
 | 321 | .. function:: killchar() | 
 | 322 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 323 |    Return the user's current line kill character. Under Unix operating systems | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 324 |    this is a property of the controlling tty of the curses program, and is not set | 
 | 325 |    by the curses library itself. | 
 | 326 |  | 
 | 327 |  | 
 | 328 | .. function:: longname() | 
 | 329 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 330 |    Return a string containing the terminfo long name field describing the current | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 331 |    terminal.  The maximum length of a verbose description is 128 characters.  It is | 
 | 332 |    defined only after the call to :func:`initscr`. | 
 | 333 |  | 
 | 334 |  | 
 | 335 | .. function:: meta(yes) | 
 | 336 |  | 
 | 337 |    If *yes* is 1, allow 8-bit characters to be input. If *yes* is 0,  allow only | 
 | 338 |    7-bit chars. | 
 | 339 |  | 
 | 340 |  | 
 | 341 | .. function:: mouseinterval(interval) | 
 | 342 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 343 |    Set the maximum time in milliseconds that can elapse between press and release | 
 | 344 |    events in order for them to be recognized as a click, and return the previous | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 345 |    interval value.  The default value is 200 msec, or one fifth of a second. | 
 | 346 |  | 
 | 347 |  | 
 | 348 | .. function:: mousemask(mousemask) | 
 | 349 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 350 |    Set the mouse events to be reported, and return a tuple ``(availmask, | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 351 |    oldmask)``.   *availmask* indicates which of the specified mouse events can be | 
 | 352 |    reported; on complete failure it returns 0.  *oldmask* is the previous value of | 
 | 353 |    the given window's mouse event mask.  If this function is never called, no mouse | 
 | 354 |    events are ever reported. | 
 | 355 |  | 
 | 356 |  | 
 | 357 | .. function:: napms(ms) | 
 | 358 |  | 
 | 359 |    Sleep for *ms* milliseconds. | 
 | 360 |  | 
 | 361 |  | 
 | 362 | .. function:: newpad(nlines, ncols) | 
 | 363 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 364 |    Create and return a pointer to a new pad data structure with the given number | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 365 |    of lines and columns.  A pad is returned as a window object. | 
 | 366 |  | 
 | 367 |    A pad is like a window, except that it is not restricted by the screen size, and | 
 | 368 |    is not necessarily associated with a particular part of the screen.  Pads can be | 
 | 369 |    used when a large window is needed, and only a part of the window will be on the | 
 | 370 |    screen at one time.  Automatic refreshes of pads (such as from scrolling or | 
 | 371 |    echoing of input) do not occur.  The :meth:`refresh` and :meth:`noutrefresh` | 
 | 372 |    methods of a pad require 6 arguments to specify the part of the pad to be | 
 | 373 |    displayed and the location on the screen to be used for the display. The | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 374 |    arguments are *pminrow*, *pmincol*, *sminrow*, *smincol*, *smaxrow*, *smaxcol*; the *p* | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 375 |    arguments refer to the upper left corner of the pad region to be displayed and | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 376 |    the *s* arguments define a clipping box on the screen within which the pad region | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 377 |    is to be displayed. | 
 | 378 |  | 
 | 379 |  | 
 | 380 | .. function:: newwin([nlines, ncols,] begin_y, begin_x) | 
 | 381 |  | 
 | 382 |    Return a new window, whose left-upper corner is at  ``(begin_y, begin_x)``, and | 
 | 383 |    whose height/width is  *nlines*/*ncols*. | 
 | 384 |  | 
 | 385 |    By default, the window will extend from the  specified position to the lower | 
 | 386 |    right corner of the screen. | 
 | 387 |  | 
 | 388 |  | 
 | 389 | .. function:: nl() | 
 | 390 |  | 
 | 391 |    Enter newline mode.  This mode translates the return key into newline on input, | 
 | 392 |    and translates newline into return and line-feed on output. Newline mode is | 
 | 393 |    initially on. | 
 | 394 |  | 
 | 395 |  | 
 | 396 | .. function:: nocbreak() | 
 | 397 |  | 
 | 398 |    Leave cbreak mode.  Return to normal "cooked" mode with line buffering. | 
 | 399 |  | 
 | 400 |  | 
 | 401 | .. function:: noecho() | 
 | 402 |  | 
 | 403 |    Leave echo mode.  Echoing of input characters is turned off. | 
 | 404 |  | 
 | 405 |  | 
 | 406 | .. function:: nonl() | 
 | 407 |  | 
 | 408 |    Leave newline mode.  Disable translation of return into newline on input, and | 
 | 409 |    disable low-level translation of newline into newline/return on output (but this | 
 | 410 |    does not change the behavior of ``addch('\n')``, which always does the | 
 | 411 |    equivalent of return and line feed on the virtual screen).  With translation | 
 | 412 |    off, curses can sometimes speed up vertical motion a little; also, it will be | 
 | 413 |    able to detect the return key on input. | 
 | 414 |  | 
 | 415 |  | 
 | 416 | .. function:: noqiflush() | 
 | 417 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 418 |    When the :func:`noqiflush` routine is used, normal flush of input and output queues | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 419 |    associated with the INTR, QUIT and SUSP characters will not be done.  You may | 
 | 420 |    want to call :func:`noqiflush` in a signal handler if you want output to | 
 | 421 |    continue as though the interrupt had not occurred, after the handler exits. | 
 | 422 |  | 
 | 423 |  | 
 | 424 | .. function:: noraw() | 
 | 425 |  | 
 | 426 |    Leave raw mode. Return to normal "cooked" mode with line buffering. | 
 | 427 |  | 
 | 428 |  | 
 | 429 | .. function:: pair_content(pair_number) | 
 | 430 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 431 |    Return a tuple ``(fg, bg)`` containing the colors for the requested color pair. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 432 |    The value of *pair_number* must be between ``1`` and ``COLOR_PAIRS - 1``. | 
 | 433 |  | 
 | 434 |  | 
 | 435 | .. function:: pair_number(attr) | 
 | 436 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 437 |    Return the number of the color-pair set by the attribute value *attr*. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 438 |    :func:`color_pair` is the counterpart to this function. | 
 | 439 |  | 
 | 440 |  | 
 | 441 | .. function:: putp(string) | 
 | 442 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 443 |    Equivalent to ``tputs(str, 1, putchar)``; emit the value of a specified | 
 | 444 |    terminfo capability for the current terminal.  Note that the output of :func:`putp` | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 445 |    always goes to standard output. | 
 | 446 |  | 
 | 447 |  | 
 | 448 | .. function:: qiflush( [flag] ) | 
 | 449 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 450 |    If *flag* is ``False``, the effect is the same as calling :func:`noqiflush`. If | 
 | 451 |    *flag* is ``True``, or no argument is provided, the queues will be flushed when | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 452 |    these control characters are read. | 
 | 453 |  | 
 | 454 |  | 
 | 455 | .. function:: raw() | 
 | 456 |  | 
 | 457 |    Enter raw mode.  In raw mode, normal line buffering and  processing of | 
 | 458 |    interrupt, quit, suspend, and flow control keys are turned off; characters are | 
 | 459 |    presented to curses input functions one by one. | 
 | 460 |  | 
 | 461 |  | 
 | 462 | .. function:: reset_prog_mode() | 
 | 463 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 464 |    Restore the  terminal  to "program" mode, as previously saved  by | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 465 |    :func:`def_prog_mode`. | 
 | 466 |  | 
 | 467 |  | 
 | 468 | .. function:: reset_shell_mode() | 
 | 469 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 470 |    Restore the  terminal  to "shell" mode, as previously saved  by | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 471 |    :func:`def_shell_mode`. | 
 | 472 |  | 
 | 473 |  | 
| Ezio Melotti | 4850d52 | 2011-06-26 13:34:56 +0300 | [diff] [blame] | 474 | .. function:: resetty() | 
 | 475 |  | 
 | 476 |    Restore the state of the terminal modes to what it was at the last call to | 
 | 477 |    :func:`savetty`. | 
 | 478 |  | 
 | 479 |  | 
 | 480 | .. function:: resize_term(nlines, ncols) | 
 | 481 |  | 
 | 482 |    Backend function used by :func:`resizeterm`, performing most of the work; | 
 | 483 |    when resizing the windows, :func:`resize_term` blank-fills the areas that are | 
 | 484 |    extended.  The calling application should fill in these areas with | 
 | 485 |    appropriate data.  The :func:`resize_term` function attempts to resize all | 
 | 486 |    windows.  However, due to the calling convention of pads, it is not possible | 
 | 487 |    to resize these without additional interaction with the application. | 
 | 488 |  | 
 | 489 |  | 
 | 490 | .. function:: resizeterm(nlines, ncols) | 
 | 491 |  | 
 | 492 |    Resize the standard and current windows to the specified dimensions, and | 
 | 493 |    adjusts other bookkeeping data used by the curses library that record the | 
 | 494 |    window dimensions (in particular the SIGWINCH handler). | 
 | 495 |  | 
 | 496 |  | 
 | 497 | .. function:: savetty() | 
 | 498 |  | 
 | 499 |    Save the current state of the terminal modes in a buffer, usable by | 
 | 500 |    :func:`resetty`. | 
 | 501 |  | 
 | 502 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 503 | .. function:: setsyx(y, x) | 
 | 504 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 505 |    Set the virtual screen cursor to *y*, *x*. If *y* and *x* are both -1, then | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 506 |    leaveok is set. | 
 | 507 |  | 
 | 508 |  | 
 | 509 | .. function:: setupterm([termstr, fd]) | 
 | 510 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 511 |    Initialize the terminal.  *termstr* is a string giving the terminal name; if | 
 | 512 |    omitted, the value of the :envvar:`TERM` environment variable will be used.  *fd* is the | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 513 |    file descriptor to which any initialization sequences will be sent; if not | 
 | 514 |    supplied, the file descriptor for ``sys.stdout`` will be used. | 
 | 515 |  | 
 | 516 |  | 
 | 517 | .. function:: start_color() | 
 | 518 |  | 
 | 519 |    Must be called if the programmer wants to use colors, and before any other color | 
 | 520 |    manipulation routine is called.  It is good practice to call this routine right | 
 | 521 |    after :func:`initscr`. | 
 | 522 |  | 
 | 523 |    :func:`start_color` initializes eight basic colors (black, red,  green, yellow, | 
 | 524 |    blue, magenta, cyan, and white), and two global variables in the :mod:`curses` | 
 | 525 |    module, :const:`COLORS` and :const:`COLOR_PAIRS`, containing the maximum number | 
 | 526 |    of colors and color-pairs the terminal can support.  It also restores the colors | 
 | 527 |    on the terminal to the values they had when the terminal was just turned on. | 
 | 528 |  | 
 | 529 |  | 
 | 530 | .. function:: termattrs() | 
 | 531 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 532 |    Return a logical OR of all video attributes supported by the terminal.  This | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 533 |    information is useful when a curses program needs complete control over the | 
 | 534 |    appearance of the screen. | 
 | 535 |  | 
 | 536 |  | 
 | 537 | .. function:: termname() | 
 | 538 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 539 |    Return the value of the environment variable :envvar:`TERM`, truncated to 14 characters. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 540 |  | 
 | 541 |  | 
 | 542 | .. function:: tigetflag(capname) | 
 | 543 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 544 |    Return the value of the Boolean capability corresponding to the terminfo | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 545 |    capability name *capname*.  The value ``-1`` is returned if *capname* is not a | 
 | 546 |    Boolean capability, or ``0`` if it is canceled or absent from the terminal | 
 | 547 |    description. | 
 | 548 |  | 
 | 549 |  | 
 | 550 | .. function:: tigetnum(capname) | 
 | 551 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 552 |    Return the value of the numeric capability corresponding to the terminfo | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 553 |    capability name *capname*.  The value ``-2`` is returned if *capname* is not a | 
 | 554 |    numeric capability, or ``-1`` if it is canceled or absent from the terminal | 
 | 555 |    description. | 
 | 556 |  | 
 | 557 |  | 
 | 558 | .. function:: tigetstr(capname) | 
 | 559 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 560 |    Return the value of the string capability corresponding to the terminfo | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 561 |    capability name *capname*.  ``None`` is returned if *capname* is not a string | 
 | 562 |    capability, or is canceled or absent from the terminal description. | 
 | 563 |  | 
 | 564 |  | 
| Georg Brandl | c2a4f4f | 2009-04-10 09:03:43 +0000 | [diff] [blame] | 565 | .. function:: tparm(str[, ...]) | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 566 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 567 |    Instantiate the string *str* with the supplied parameters, where *str* should | 
 | 568 |    be a parameterized string obtained from the terminfo database.  E.g. | 
| Victor Stinner | 2662133 | 2011-11-02 23:45:29 +0100 | [diff] [blame] | 569 |    ``tparm(tigetstr("cup"), 5, 3)`` could result in ``b'\033[6;4H'``, the exact | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 570 |    result depending on terminal type. | 
 | 571 |  | 
 | 572 |  | 
 | 573 | .. function:: typeahead(fd) | 
 | 574 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 575 |    Specify that the file descriptor *fd* be used for typeahead checking.  If *fd* | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 576 |    is ``-1``, then no typeahead checking is done. | 
 | 577 |  | 
 | 578 |    The curses library does "line-breakout optimization" by looking for typeahead | 
 | 579 |    periodically while updating the screen.  If input is found, and it is coming | 
 | 580 |    from a tty, the current update is postponed until refresh or doupdate is called | 
 | 581 |    again, allowing faster response to commands typed in advance. This function | 
 | 582 |    allows specifying a different file descriptor for typeahead checking. | 
 | 583 |  | 
 | 584 |  | 
 | 585 | .. function:: unctrl(ch) | 
 | 586 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 587 |    Return a string which is a printable representation of the character *ch*. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 588 |    Control characters are displayed as a caret followed by the character, for | 
 | 589 |    example as ``^C``. Printing characters are left as they are. | 
 | 590 |  | 
 | 591 |  | 
 | 592 | .. function:: ungetch(ch) | 
 | 593 |  | 
 | 594 |    Push *ch* so the next :meth:`getch` will return it. | 
 | 595 |  | 
 | 596 |    .. note:: | 
 | 597 |  | 
 | 598 |       Only one *ch* can be pushed before :meth:`getch` is called. | 
 | 599 |  | 
 | 600 |  | 
 | 601 | .. function:: ungetmouse(id, x, y, z, bstate) | 
 | 602 |  | 
 | 603 |    Push a :const:`KEY_MOUSE` event onto the input queue, associating the given | 
 | 604 |    state data with it. | 
 | 605 |  | 
 | 606 |  | 
 | 607 | .. function:: use_env(flag) | 
 | 608 |  | 
 | 609 |    If used, this function should be called before :func:`initscr` or newterm are | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 610 |    called.  When *flag* is ``False``, the values of lines and columns specified in the | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 611 |    terminfo database will be used, even if environment variables :envvar:`LINES` | 
 | 612 |    and :envvar:`COLUMNS` (used by default) are set, or if curses is running in a | 
 | 613 |    window (in which case default behavior would be to use the window size if | 
 | 614 |    :envvar:`LINES` and :envvar:`COLUMNS` are not set). | 
 | 615 |  | 
 | 616 |  | 
 | 617 | .. function:: use_default_colors() | 
 | 618 |  | 
 | 619 |    Allow use of default values for colors on terminals supporting this feature. Use | 
 | 620 |    this to support transparency in your application.  The default color is assigned | 
 | 621 |    to the color number -1. After calling this function,  ``init_pair(x, | 
 | 622 |    curses.COLOR_RED, -1)`` initializes, for instance, color pair *x* to a red | 
 | 623 |    foreground color on the default background. | 
 | 624 |  | 
 | 625 |  | 
| R David Murray | 409c32f | 2011-06-18 19:34:12 -0400 | [diff] [blame] | 626 | .. function:: wrapper(func, ...) | 
 | 627 |  | 
 | 628 |    Initialize curses and call another callable object, *func*, which should be the | 
 | 629 |    rest of your curses-using application.  If the application raises an exception, | 
 | 630 |    this function will restore the terminal to a sane state before re-raising the | 
 | 631 |    exception and generating a traceback.  The callable object *func* is then passed | 
 | 632 |    the main window 'stdscr' as its first argument, followed by any other arguments | 
 | 633 |    passed to :func:`wrapper`.  Before calling *func*, :func:`wrapper` turns on | 
 | 634 |    cbreak mode, turns off echo, enables the terminal keypad, and initializes colors | 
 | 635 |    if the terminal has color support.  On exit (whether normally or by exception) | 
 | 636 |    it restores cooked mode, turns on echo, and disables the terminal keypad. | 
 | 637 |  | 
 | 638 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 639 | .. _curses-window-objects: | 
 | 640 |  | 
 | 641 | Window Objects | 
 | 642 | -------------- | 
 | 643 |  | 
 | 644 | Window objects, as returned by :func:`initscr` and :func:`newwin` above, have | 
 | 645 | the following methods: | 
 | 646 |  | 
 | 647 |  | 
 | 648 | .. method:: window.addch([y, x,] ch[, attr]) | 
 | 649 |  | 
 | 650 |    .. note:: | 
 | 651 |  | 
| Sandro Tosi | 8a3b657 | 2011-08-12 19:31:32 +0200 | [diff] [blame] | 652 |       A *character* means a C character (an ASCII code), rather than a Python | 
| Georg Brandl | 22b3431 | 2009-07-26 14:54:51 +0000 | [diff] [blame] | 653 |       character (a string of length 1). (This note is true whenever the | 
 | 654 |       documentation mentions a character.) The built-in :func:`ord` is handy for | 
 | 655 |       conveying strings to codes. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 656 |  | 
 | 657 |    Paint character *ch* at ``(y, x)`` with attributes *attr*, overwriting any | 
 | 658 |    character previously painter at that location.  By default, the character | 
 | 659 |    position and attributes are the current settings for the window object. | 
 | 660 |  | 
 | 661 |  | 
 | 662 | .. method:: window.addnstr([y, x,] str, n[, attr]) | 
 | 663 |  | 
 | 664 |    Paint at most *n* characters of the  string *str* at ``(y, x)`` with attributes | 
 | 665 |    *attr*, overwriting anything previously on the display. | 
 | 666 |  | 
 | 667 |  | 
 | 668 | .. method:: window.addstr([y, x,] str[, attr]) | 
 | 669 |  | 
 | 670 |    Paint the string *str* at ``(y, x)`` with attributes *attr*, overwriting | 
 | 671 |    anything previously on the display. | 
 | 672 |  | 
 | 673 |  | 
 | 674 | .. method:: window.attroff(attr) | 
 | 675 |  | 
 | 676 |    Remove attribute *attr* from the "background" set applied to all writes to the | 
 | 677 |    current window. | 
 | 678 |  | 
 | 679 |  | 
 | 680 | .. method:: window.attron(attr) | 
 | 681 |  | 
 | 682 |    Add attribute *attr* from the "background" set applied to all writes to the | 
 | 683 |    current window. | 
 | 684 |  | 
 | 685 |  | 
 | 686 | .. method:: window.attrset(attr) | 
 | 687 |  | 
 | 688 |    Set the "background" set of attributes to *attr*.  This set is initially 0 (no | 
 | 689 |    attributes). | 
 | 690 |  | 
 | 691 |  | 
 | 692 | .. method:: window.bkgd(ch[, attr]) | 
 | 693 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 694 |    Set the background property of the window to the character *ch*, with | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 695 |    attributes *attr*.  The change is then applied to every character position in | 
 | 696 |    that window: | 
 | 697 |  | 
 | 698 |    * The attribute of every character in the window  is changed to the new | 
 | 699 |      background attribute. | 
 | 700 |  | 
 | 701 |    * Wherever  the  former background character appears, it is changed to the new | 
 | 702 |      background character. | 
 | 703 |  | 
 | 704 |  | 
 | 705 | .. method:: window.bkgdset(ch[, attr]) | 
 | 706 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 707 |    Set the window's background.  A window's background consists of a character and | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 708 |    any combination of attributes.  The attribute part of the background is combined | 
 | 709 |    (OR'ed) with all non-blank characters that are written into the window.  Both | 
 | 710 |    the character and attribute parts of the background are combined with the blank | 
 | 711 |    characters.  The background becomes a property of the character and moves with | 
 | 712 |    the character through any scrolling and insert/delete line/character operations. | 
 | 713 |  | 
 | 714 |  | 
 | 715 | .. method:: window.border([ls[, rs[, ts[, bs[, tl[, tr[, bl[, br]]]]]]]]) | 
 | 716 |  | 
 | 717 |    Draw a border around the edges of the window. Each parameter specifies  the | 
 | 718 |    character to use for a specific part of the border; see the table below for more | 
 | 719 |    details.  The characters can be specified as integers or as one-character | 
 | 720 |    strings. | 
 | 721 |  | 
 | 722 |    .. note:: | 
 | 723 |  | 
 | 724 |       A ``0`` value for any parameter will cause the default character to be used for | 
 | 725 |       that parameter.  Keyword parameters can *not* be used.  The defaults are listed | 
 | 726 |       in this table: | 
 | 727 |  | 
 | 728 |    +-----------+---------------------+-----------------------+ | 
 | 729 |    | Parameter | Description         | Default value         | | 
 | 730 |    +===========+=====================+=======================+ | 
 | 731 |    | *ls*      | Left side           | :const:`ACS_VLINE`    | | 
 | 732 |    +-----------+---------------------+-----------------------+ | 
 | 733 |    | *rs*      | Right side          | :const:`ACS_VLINE`    | | 
 | 734 |    +-----------+---------------------+-----------------------+ | 
 | 735 |    | *ts*      | Top                 | :const:`ACS_HLINE`    | | 
 | 736 |    +-----------+---------------------+-----------------------+ | 
 | 737 |    | *bs*      | Bottom              | :const:`ACS_HLINE`    | | 
 | 738 |    +-----------+---------------------+-----------------------+ | 
 | 739 |    | *tl*      | Upper-left corner   | :const:`ACS_ULCORNER` | | 
 | 740 |    +-----------+---------------------+-----------------------+ | 
 | 741 |    | *tr*      | Upper-right corner  | :const:`ACS_URCORNER` | | 
 | 742 |    +-----------+---------------------+-----------------------+ | 
 | 743 |    | *bl*      | Bottom-left corner  | :const:`ACS_LLCORNER` | | 
 | 744 |    +-----------+---------------------+-----------------------+ | 
 | 745 |    | *br*      | Bottom-right corner | :const:`ACS_LRCORNER` | | 
 | 746 |    +-----------+---------------------+-----------------------+ | 
 | 747 |  | 
 | 748 |  | 
 | 749 | .. method:: window.box([vertch, horch]) | 
 | 750 |  | 
 | 751 |    Similar to :meth:`border`, but both *ls* and *rs* are *vertch* and both *ts* and | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 752 |    *bs* are *horch*.  The default corner characters are always used by this function. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 753 |  | 
 | 754 |  | 
 | 755 | .. method:: window.chgat([y, x, ] [num,] attr) | 
 | 756 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 757 |    Set the attributes of *num* characters at the current cursor position, or at | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 758 |    position ``(y, x)`` if supplied. If no value of *num* is given or *num* = -1, | 
 | 759 |    the attribute will  be set on all the characters to the end of the line.  This | 
 | 760 |    function does not move the cursor. The changed line will be touched using the | 
 | 761 |    :meth:`touchline` method so that the contents will be redisplayed by the next | 
 | 762 |    window refresh. | 
 | 763 |  | 
 | 764 |  | 
 | 765 | .. method:: window.clear() | 
 | 766 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 767 |    Like :meth:`erase`, but also cause the whole window to be repainted upon next | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 768 |    call to :meth:`refresh`. | 
 | 769 |  | 
 | 770 |  | 
 | 771 | .. method:: window.clearok(yes) | 
 | 772 |  | 
 | 773 |    If *yes* is 1, the next call to :meth:`refresh` will clear the window | 
 | 774 |    completely. | 
 | 775 |  | 
 | 776 |  | 
 | 777 | .. method:: window.clrtobot() | 
 | 778 |  | 
 | 779 |    Erase from cursor to the end of the window: all lines below the cursor are | 
 | 780 |    deleted, and then the equivalent of :meth:`clrtoeol` is performed. | 
 | 781 |  | 
 | 782 |  | 
 | 783 | .. method:: window.clrtoeol() | 
 | 784 |  | 
 | 785 |    Erase from cursor to the end of the line. | 
 | 786 |  | 
 | 787 |  | 
 | 788 | .. method:: window.cursyncup() | 
 | 789 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 790 |    Update the current cursor position of all the ancestors of the window to | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 791 |    reflect the current cursor position of the window. | 
 | 792 |  | 
 | 793 |  | 
 | 794 | .. method:: window.delch([y, x]) | 
 | 795 |  | 
 | 796 |    Delete any character at ``(y, x)``. | 
 | 797 |  | 
 | 798 |  | 
 | 799 | .. method:: window.deleteln() | 
 | 800 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 801 |    Delete the line under the cursor. All following lines are moved up by one line. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 802 |  | 
 | 803 |  | 
 | 804 | .. method:: window.derwin([nlines, ncols,] begin_y, begin_x) | 
 | 805 |  | 
 | 806 |    An abbreviation for "derive window", :meth:`derwin` is the same as calling | 
 | 807 |    :meth:`subwin`, except that *begin_y* and *begin_x* are relative to the origin | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 808 |    of the window, rather than relative to the entire screen.  Return a window | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 809 |    object for the derived window. | 
 | 810 |  | 
 | 811 |  | 
 | 812 | .. method:: window.echochar(ch[, attr]) | 
 | 813 |  | 
 | 814 |    Add character *ch* with attribute *attr*, and immediately  call :meth:`refresh` | 
 | 815 |    on the window. | 
 | 816 |  | 
 | 817 |  | 
 | 818 | .. method:: window.enclose(y, x) | 
 | 819 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 820 |    Test whether the given pair of screen-relative character-cell coordinates are | 
 | 821 |    enclosed by the given window, returning ``True`` or ``False``.  It is useful for | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 822 |    determining what subset of the screen windows enclose the location of a mouse | 
 | 823 |    event. | 
 | 824 |  | 
 | 825 |  | 
 | 826 | .. method:: window.erase() | 
 | 827 |  | 
 | 828 |    Clear the window. | 
 | 829 |  | 
 | 830 |  | 
 | 831 | .. method:: window.getbegyx() | 
 | 832 |  | 
 | 833 |    Return a tuple ``(y, x)`` of co-ordinates of upper-left corner. | 
 | 834 |  | 
 | 835 |  | 
| Ezio Melotti | 4850d52 | 2011-06-26 13:34:56 +0300 | [diff] [blame] | 836 | .. method:: window.getbkgd() | 
 | 837 |  | 
 | 838 |    Return the given window's current background character/attribute pair. | 
 | 839 |  | 
 | 840 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 841 | .. method:: window.getch([y, x]) | 
 | 842 |  | 
 | 843 |    Get a character. Note that the integer returned does *not* have to be in ASCII | 
 | 844 |    range: function keys, keypad keys and so on return numbers higher than 256. In | 
| Georg Brandl | e810e5a | 2009-06-17 10:03:58 +0000 | [diff] [blame] | 845 |    no-delay mode, -1 is returned if there is no input, else :func:`getch` waits | 
 | 846 |    until a key is pressed. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 847 |  | 
 | 848 |  | 
 | 849 | .. method:: window.getkey([y, x]) | 
 | 850 |  | 
 | 851 |    Get a character, returning a string instead of an integer, as :meth:`getch` | 
 | 852 |    does. Function keys, keypad keys and so on return a multibyte string containing | 
 | 853 |    the key name.  In no-delay mode, an exception is raised if there is no input. | 
 | 854 |  | 
 | 855 |  | 
 | 856 | .. method:: window.getmaxyx() | 
 | 857 |  | 
 | 858 |    Return a tuple ``(y, x)`` of the height and width of the window. | 
 | 859 |  | 
 | 860 |  | 
 | 861 | .. method:: window.getparyx() | 
 | 862 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 863 |    Return the beginning coordinates of this window relative to its parent window | 
 | 864 |    into two integer variables y and x.  Return ``-1, -1`` if this window has no | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 865 |    parent. | 
 | 866 |  | 
 | 867 |  | 
 | 868 | .. method:: window.getstr([y, x]) | 
 | 869 |  | 
 | 870 |    Read a string from the user, with primitive line editing capacity. | 
 | 871 |  | 
 | 872 |  | 
 | 873 | .. method:: window.getyx() | 
 | 874 |  | 
 | 875 |    Return a tuple ``(y, x)`` of current cursor position  relative to the window's | 
 | 876 |    upper-left corner. | 
 | 877 |  | 
 | 878 |  | 
 | 879 | .. method:: window.hline([y, x,] ch, n) | 
 | 880 |  | 
 | 881 |    Display a horizontal line starting at ``(y, x)`` with length *n* consisting of | 
 | 882 |    the character *ch*. | 
 | 883 |  | 
 | 884 |  | 
 | 885 | .. method:: window.idcok(flag) | 
 | 886 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 887 |    If *flag* is ``False``, curses no longer considers using the hardware insert/delete | 
 | 888 |    character feature of the terminal; if *flag* is ``True``, use of character insertion | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 889 |    and deletion is enabled.  When curses is first initialized, use of character | 
 | 890 |    insert/delete is enabled by default. | 
 | 891 |  | 
 | 892 |  | 
 | 893 | .. method:: window.idlok(yes) | 
 | 894 |  | 
 | 895 |    If called with *yes* equal to 1, :mod:`curses` will try and use hardware line | 
 | 896 |    editing facilities. Otherwise, line insertion/deletion are disabled. | 
 | 897 |  | 
 | 898 |  | 
 | 899 | .. method:: window.immedok(flag) | 
 | 900 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 901 |    If *flag* is ``True``, any change in the window image automatically causes the | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 902 |    window to be refreshed; you no longer have to call :meth:`refresh` yourself. | 
 | 903 |    However, it may degrade performance considerably, due to repeated calls to | 
 | 904 |    wrefresh.  This option is disabled by default. | 
 | 905 |  | 
 | 906 |  | 
 | 907 | .. method:: window.inch([y, x]) | 
 | 908 |  | 
 | 909 |    Return the character at the given position in the window. The bottom 8 bits are | 
 | 910 |    the character proper, and upper bits are the attributes. | 
 | 911 |  | 
 | 912 |  | 
 | 913 | .. method:: window.insch([y, x,] ch[, attr]) | 
 | 914 |  | 
 | 915 |    Paint character *ch* at ``(y, x)`` with attributes *attr*, moving the line from | 
 | 916 |    position *x* right by one character. | 
 | 917 |  | 
 | 918 |  | 
 | 919 | .. method:: window.insdelln(nlines) | 
 | 920 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 921 |    Insert *nlines* lines into the specified window above the current line.  The | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 922 |    *nlines* bottom lines are lost.  For negative *nlines*, delete *nlines* lines | 
 | 923 |    starting with the one under the cursor, and move the remaining lines up.  The | 
 | 924 |    bottom *nlines* lines are cleared.  The current cursor position remains the | 
 | 925 |    same. | 
 | 926 |  | 
 | 927 |  | 
 | 928 | .. method:: window.insertln() | 
 | 929 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 930 |    Insert a blank line under the cursor. All following lines are moved down by one | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 931 |    line. | 
 | 932 |  | 
 | 933 |  | 
 | 934 | .. method:: window.insnstr([y, x,] str, n [, attr]) | 
 | 935 |  | 
 | 936 |    Insert a character string (as many characters as will fit on the line) before | 
 | 937 |    the character under the cursor, up to *n* characters.   If *n* is zero or | 
 | 938 |    negative, the entire string is inserted. All characters to the right of the | 
 | 939 |    cursor are shifted right, with the rightmost characters on the line being lost. | 
 | 940 |    The cursor position does not change (after moving to *y*, *x*, if specified). | 
 | 941 |  | 
 | 942 |  | 
 | 943 | .. method:: window.insstr([y, x, ] str [, attr]) | 
 | 944 |  | 
 | 945 |    Insert a character string (as many characters as will fit on the line) before | 
 | 946 |    the character under the cursor.  All characters to the right of the cursor are | 
 | 947 |    shifted right, with the rightmost characters on the line being lost.  The cursor | 
 | 948 |    position does not change (after moving to *y*, *x*, if specified). | 
 | 949 |  | 
 | 950 |  | 
 | 951 | .. method:: window.instr([y, x] [, n]) | 
 | 952 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 953 |    Return a string of characters, extracted from the window starting at the | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 954 |    current cursor position, or at *y*, *x* if specified. Attributes are stripped | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 955 |    from the characters.  If *n* is specified, :meth:`instr` returns a string | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 956 |    at most *n* characters long (exclusive of the trailing NUL). | 
 | 957 |  | 
 | 958 |  | 
 | 959 | .. method:: window.is_linetouched(line) | 
 | 960 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 961 |    Return ``True`` if the specified line was modified since the last call to | 
 | 962 |    :meth:`refresh`; otherwise return ``False``.  Raise a :exc:`curses.error` | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 963 |    exception if *line* is not valid for the given window. | 
 | 964 |  | 
 | 965 |  | 
 | 966 | .. method:: window.is_wintouched() | 
 | 967 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 968 |    Return ``True`` if the specified window was modified since the last call to | 
 | 969 |    :meth:`refresh`; otherwise return ``False``. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 970 |  | 
 | 971 |  | 
 | 972 | .. method:: window.keypad(yes) | 
 | 973 |  | 
 | 974 |    If *yes* is 1, escape sequences generated by some keys (keypad,  function keys) | 
 | 975 |    will be interpreted by :mod:`curses`. If *yes* is 0, escape sequences will be | 
 | 976 |    left as is in the input stream. | 
 | 977 |  | 
 | 978 |  | 
 | 979 | .. method:: window.leaveok(yes) | 
 | 980 |  | 
 | 981 |    If *yes* is 1, cursor is left where it is on update, instead of being at "cursor | 
 | 982 |    position."  This reduces cursor movement where possible. If possible the cursor | 
 | 983 |    will be made invisible. | 
 | 984 |  | 
 | 985 |    If *yes* is 0, cursor will always be at "cursor position" after an update. | 
 | 986 |  | 
 | 987 |  | 
 | 988 | .. method:: window.move(new_y, new_x) | 
 | 989 |  | 
 | 990 |    Move cursor to ``(new_y, new_x)``. | 
 | 991 |  | 
 | 992 |  | 
 | 993 | .. method:: window.mvderwin(y, x) | 
 | 994 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 995 |    Move the window inside its parent window.  The screen-relative parameters of | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 996 |    the window are not changed.  This routine is used to display different parts of | 
 | 997 |    the parent window at the same physical position on the screen. | 
 | 998 |  | 
 | 999 |  | 
 | 1000 | .. method:: window.mvwin(new_y, new_x) | 
 | 1001 |  | 
 | 1002 |    Move the window so its upper-left corner is at ``(new_y, new_x)``. | 
 | 1003 |  | 
 | 1004 |  | 
 | 1005 | .. method:: window.nodelay(yes) | 
 | 1006 |  | 
 | 1007 |    If *yes* is ``1``, :meth:`getch` will be non-blocking. | 
 | 1008 |  | 
 | 1009 |  | 
 | 1010 | .. method:: window.notimeout(yes) | 
 | 1011 |  | 
 | 1012 |    If *yes* is ``1``, escape sequences will not be timed out. | 
 | 1013 |  | 
 | 1014 |    If *yes* is ``0``, after a few milliseconds, an escape sequence will not be | 
 | 1015 |    interpreted, and will be left in the input stream as is. | 
 | 1016 |  | 
 | 1017 |  | 
 | 1018 | .. method:: window.noutrefresh() | 
 | 1019 |  | 
 | 1020 |    Mark for refresh but wait.  This function updates the data structure | 
 | 1021 |    representing the desired state of the window, but does not force an update of | 
 | 1022 |    the physical screen.  To accomplish that, call  :func:`doupdate`. | 
 | 1023 |  | 
 | 1024 |  | 
 | 1025 | .. method:: window.overlay(destwin[, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol]) | 
 | 1026 |  | 
 | 1027 |    Overlay the window on top of *destwin*. The windows need not be the same size, | 
 | 1028 |    only the overlapping region is copied. This copy is non-destructive, which means | 
 | 1029 |    that the current background character does not overwrite the old contents of | 
 | 1030 |    *destwin*. | 
 | 1031 |  | 
 | 1032 |    To get fine-grained control over the copied region, the second form of | 
 | 1033 |    :meth:`overlay` can be used. *sminrow* and *smincol* are the upper-left | 
 | 1034 |    coordinates of the source window, and the other variables mark a rectangle in | 
 | 1035 |    the destination window. | 
 | 1036 |  | 
 | 1037 |  | 
 | 1038 | .. method:: window.overwrite(destwin[, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol]) | 
 | 1039 |  | 
 | 1040 |    Overwrite the window on top of *destwin*. The windows need not be the same size, | 
 | 1041 |    in which case only the overlapping region is copied. This copy is destructive, | 
 | 1042 |    which means that the current background character overwrites the old contents of | 
 | 1043 |    *destwin*. | 
 | 1044 |  | 
 | 1045 |    To get fine-grained control over the copied region, the second form of | 
 | 1046 |    :meth:`overwrite` can be used. *sminrow* and *smincol* are the upper-left | 
 | 1047 |    coordinates of the source window, the other variables mark a rectangle in the | 
 | 1048 |    destination window. | 
 | 1049 |  | 
 | 1050 |  | 
 | 1051 | .. method:: window.putwin(file) | 
 | 1052 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 1053 |    Write all data associated with the window into the provided file object.  This | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1054 |    information can be later retrieved using the :func:`getwin` function. | 
 | 1055 |  | 
 | 1056 |  | 
 | 1057 | .. method:: window.redrawln(beg, num) | 
 | 1058 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 1059 |    Indicate that the *num* screen lines, starting at line *beg*, are corrupted and | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1060 |    should be completely redrawn on the next :meth:`refresh` call. | 
 | 1061 |  | 
 | 1062 |  | 
 | 1063 | .. method:: window.redrawwin() | 
 | 1064 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 1065 |    Touch the entire window, causing it to be completely redrawn on the next | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1066 |    :meth:`refresh` call. | 
 | 1067 |  | 
 | 1068 |  | 
 | 1069 | .. method:: window.refresh([pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol]) | 
 | 1070 |  | 
 | 1071 |    Update the display immediately (sync actual screen with previous | 
 | 1072 |    drawing/deleting methods). | 
 | 1073 |  | 
 | 1074 |    The 6 optional arguments can only be specified when the window is a pad created | 
 | 1075 |    with :func:`newpad`.  The additional parameters are needed to indicate what part | 
 | 1076 |    of the pad and screen are involved. *pminrow* and *pmincol* specify the upper | 
 | 1077 |    left-hand corner of the rectangle to be displayed in the pad.  *sminrow*, | 
 | 1078 |    *smincol*, *smaxrow*, and *smaxcol* specify the edges of the rectangle to be | 
 | 1079 |    displayed on the screen.  The lower right-hand corner of the rectangle to be | 
 | 1080 |    displayed in the pad is calculated from the screen coordinates, since the | 
 | 1081 |    rectangles must be the same size.  Both rectangles must be entirely contained | 
 | 1082 |    within their respective structures.  Negative values of *pminrow*, *pmincol*, | 
 | 1083 |    *sminrow*, or *smincol* are treated as if they were zero. | 
 | 1084 |  | 
 | 1085 |  | 
| Ezio Melotti | 4850d52 | 2011-06-26 13:34:56 +0300 | [diff] [blame] | 1086 | .. method:: window.resize(nlines, ncols) | 
 | 1087 |  | 
 | 1088 |    Reallocate storage for a curses window to adjust its dimensions to the | 
 | 1089 |    specified values.  If either dimension is larger than the current values, the | 
 | 1090 |    window's data is filled with blanks that have the current background | 
 | 1091 |    rendition (as set by :meth:`bkgdset`) merged into them. | 
 | 1092 |  | 
 | 1093 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1094 | .. method:: window.scroll([lines=1]) | 
 | 1095 |  | 
 | 1096 |    Scroll the screen or scrolling region upward by *lines* lines. | 
 | 1097 |  | 
 | 1098 |  | 
 | 1099 | .. method:: window.scrollok(flag) | 
 | 1100 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 1101 |    Control what happens when the cursor of a window is moved off the edge of the | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1102 |    window or scrolling region, either as a result of a newline action on the bottom | 
 | 1103 |    line, or typing the last character of the last line.  If *flag* is false, the | 
 | 1104 |    cursor is left on the bottom line.  If *flag* is true, the window is scrolled up | 
 | 1105 |    one line.  Note that in order to get the physical scrolling effect on the | 
 | 1106 |    terminal, it is also necessary to call :meth:`idlok`. | 
 | 1107 |  | 
 | 1108 |  | 
 | 1109 | .. method:: window.setscrreg(top, bottom) | 
 | 1110 |  | 
 | 1111 |    Set the scrolling region from line *top* to line *bottom*. All scrolling actions | 
 | 1112 |    will take place in this region. | 
 | 1113 |  | 
 | 1114 |  | 
 | 1115 | .. method:: window.standend() | 
 | 1116 |  | 
 | 1117 |    Turn off the standout attribute.  On some terminals this has the side effect of | 
 | 1118 |    turning off all attributes. | 
 | 1119 |  | 
 | 1120 |  | 
 | 1121 | .. method:: window.standout() | 
 | 1122 |  | 
 | 1123 |    Turn on attribute *A_STANDOUT*. | 
 | 1124 |  | 
 | 1125 |  | 
 | 1126 | .. method:: window.subpad([nlines, ncols,] begin_y, begin_x) | 
 | 1127 |  | 
 | 1128 |    Return a sub-window, whose upper-left corner is at ``(begin_y, begin_x)``, and | 
 | 1129 |    whose width/height is *ncols*/*nlines*. | 
 | 1130 |  | 
 | 1131 |  | 
 | 1132 | .. method:: window.subwin([nlines, ncols,] begin_y, begin_x) | 
 | 1133 |  | 
 | 1134 |    Return a sub-window, whose upper-left corner is at ``(begin_y, begin_x)``, and | 
 | 1135 |    whose width/height is *ncols*/*nlines*. | 
 | 1136 |  | 
 | 1137 |    By default, the sub-window will extend from the specified position to the lower | 
 | 1138 |    right corner of the window. | 
 | 1139 |  | 
 | 1140 |  | 
 | 1141 | .. method:: window.syncdown() | 
 | 1142 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 1143 |    Touch each location in the window that has been touched in any of its ancestor | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1144 |    windows.  This routine is called by :meth:`refresh`, so it should almost never | 
 | 1145 |    be necessary to call it manually. | 
 | 1146 |  | 
 | 1147 |  | 
 | 1148 | .. method:: window.syncok(flag) | 
 | 1149 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 1150 |    If called with *flag* set to ``True``, then :meth:`syncup` is called automatically | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1151 |    whenever there is a change in the window. | 
 | 1152 |  | 
 | 1153 |  | 
 | 1154 | .. method:: window.syncup() | 
 | 1155 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 1156 |    Touch all locations in ancestors of the window that have been changed in  the | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1157 |    window. | 
 | 1158 |  | 
 | 1159 |  | 
 | 1160 | .. method:: window.timeout(delay) | 
 | 1161 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 1162 |    Set blocking or non-blocking read behavior for the window.  If *delay* is | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1163 |    negative, blocking read is used (which will wait indefinitely for input).  If | 
 | 1164 |    *delay* is zero, then non-blocking read is used, and -1 will be returned by | 
 | 1165 |    :meth:`getch` if no input is waiting.  If *delay* is positive, then | 
 | 1166 |    :meth:`getch` will block for *delay* milliseconds, and return -1 if there is | 
 | 1167 |    still no input at the end of that time. | 
 | 1168 |  | 
 | 1169 |  | 
 | 1170 | .. method:: window.touchline(start, count[, changed]) | 
 | 1171 |  | 
 | 1172 |    Pretend *count* lines have been changed, starting with line *start*.  If | 
 | 1173 |    *changed* is supplied, it specifies whether the affected lines are marked as | 
 | 1174 |    having been changed (*changed*\ =1) or unchanged (*changed*\ =0). | 
 | 1175 |  | 
 | 1176 |  | 
 | 1177 | .. method:: window.touchwin() | 
 | 1178 |  | 
 | 1179 |    Pretend the whole window has been changed, for purposes of drawing | 
 | 1180 |    optimizations. | 
 | 1181 |  | 
 | 1182 |  | 
 | 1183 | .. method:: window.untouchwin() | 
 | 1184 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 1185 |    Mark all lines in  the  window  as unchanged since the last call to | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1186 |    :meth:`refresh`. | 
 | 1187 |  | 
 | 1188 |  | 
 | 1189 | .. method:: window.vline([y, x,] ch, n) | 
 | 1190 |  | 
 | 1191 |    Display a vertical line starting at ``(y, x)`` with length *n* consisting of the | 
 | 1192 |    character *ch*. | 
 | 1193 |  | 
 | 1194 |  | 
 | 1195 | Constants | 
 | 1196 | --------- | 
 | 1197 |  | 
 | 1198 | The :mod:`curses` module defines the following data members: | 
 | 1199 |  | 
 | 1200 |  | 
 | 1201 | .. data:: ERR | 
 | 1202 |  | 
 | 1203 |    Some curses routines  that  return  an integer, such as  :func:`getch`, return | 
 | 1204 |    :const:`ERR` upon failure. | 
 | 1205 |  | 
 | 1206 |  | 
 | 1207 | .. data:: OK | 
 | 1208 |  | 
 | 1209 |    Some curses routines  that  return  an integer, such as  :func:`napms`, return | 
 | 1210 |    :const:`OK` upon success. | 
 | 1211 |  | 
 | 1212 |  | 
 | 1213 | .. data:: version | 
 | 1214 |  | 
 | 1215 |    A string representing the current version of the module.  Also available as | 
 | 1216 |    :const:`__version__`. | 
 | 1217 |  | 
 | 1218 | Several constants are available to specify character cell attributes: | 
 | 1219 |  | 
 | 1220 | +------------------+-------------------------------+ | 
 | 1221 | | Attribute        | Meaning                       | | 
 | 1222 | +==================+===============================+ | 
 | 1223 | | ``A_ALTCHARSET`` | Alternate character set mode. | | 
 | 1224 | +------------------+-------------------------------+ | 
 | 1225 | | ``A_BLINK``      | Blink mode.                   | | 
 | 1226 | +------------------+-------------------------------+ | 
 | 1227 | | ``A_BOLD``       | Bold mode.                    | | 
 | 1228 | +------------------+-------------------------------+ | 
 | 1229 | | ``A_DIM``        | Dim mode.                     | | 
 | 1230 | +------------------+-------------------------------+ | 
 | 1231 | | ``A_NORMAL``     | Normal attribute.             | | 
 | 1232 | +------------------+-------------------------------+ | 
| Georg Brandl | 931e5c1 | 2011-03-06 11:08:35 +0100 | [diff] [blame] | 1233 | | ``A_REVERSE``    | Reverse background and        | | 
 | 1234 | |                  | foreground colors.            | | 
 | 1235 | +------------------+-------------------------------+ | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1236 | | ``A_STANDOUT``   | Standout mode.                | | 
 | 1237 | +------------------+-------------------------------+ | 
 | 1238 | | ``A_UNDERLINE``  | Underline mode.               | | 
 | 1239 | +------------------+-------------------------------+ | 
 | 1240 |  | 
 | 1241 | Keys are referred to by integer constants with names starting with  ``KEY_``. | 
 | 1242 | The exact keycaps available are system dependent. | 
 | 1243 |  | 
| Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 1244 | .. XXX this table is far too large! should it be alphabetized? | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1245 |  | 
 | 1246 | +-------------------+--------------------------------------------+ | 
 | 1247 | | Key constant      | Key                                        | | 
 | 1248 | +===================+============================================+ | 
 | 1249 | | ``KEY_MIN``       | Minimum key value                          | | 
 | 1250 | +-------------------+--------------------------------------------+ | 
 | 1251 | | ``KEY_BREAK``     | Break key (unreliable)                     | | 
 | 1252 | +-------------------+--------------------------------------------+ | 
 | 1253 | | ``KEY_DOWN``      | Down-arrow                                 | | 
 | 1254 | +-------------------+--------------------------------------------+ | 
 | 1255 | | ``KEY_UP``        | Up-arrow                                   | | 
 | 1256 | +-------------------+--------------------------------------------+ | 
 | 1257 | | ``KEY_LEFT``      | Left-arrow                                 | | 
 | 1258 | +-------------------+--------------------------------------------+ | 
 | 1259 | | ``KEY_RIGHT``     | Right-arrow                                | | 
 | 1260 | +-------------------+--------------------------------------------+ | 
 | 1261 | | ``KEY_HOME``      | Home key (upward+left arrow)               | | 
 | 1262 | +-------------------+--------------------------------------------+ | 
 | 1263 | | ``KEY_BACKSPACE`` | Backspace (unreliable)                     | | 
 | 1264 | +-------------------+--------------------------------------------+ | 
 | 1265 | | ``KEY_F0``        | Function keys.  Up to 64 function keys are | | 
 | 1266 | |                   | supported.                                 | | 
 | 1267 | +-------------------+--------------------------------------------+ | 
 | 1268 | | ``KEY_Fn``        | Value of function key *n*                  | | 
 | 1269 | +-------------------+--------------------------------------------+ | 
 | 1270 | | ``KEY_DL``        | Delete line                                | | 
 | 1271 | +-------------------+--------------------------------------------+ | 
 | 1272 | | ``KEY_IL``        | Insert line                                | | 
 | 1273 | +-------------------+--------------------------------------------+ | 
 | 1274 | | ``KEY_DC``        | Delete character                           | | 
 | 1275 | +-------------------+--------------------------------------------+ | 
 | 1276 | | ``KEY_IC``        | Insert char or enter insert mode           | | 
 | 1277 | +-------------------+--------------------------------------------+ | 
 | 1278 | | ``KEY_EIC``       | Exit insert char mode                      | | 
 | 1279 | +-------------------+--------------------------------------------+ | 
 | 1280 | | ``KEY_CLEAR``     | Clear screen                               | | 
 | 1281 | +-------------------+--------------------------------------------+ | 
 | 1282 | | ``KEY_EOS``       | Clear to end of screen                     | | 
 | 1283 | +-------------------+--------------------------------------------+ | 
 | 1284 | | ``KEY_EOL``       | Clear to end of line                       | | 
 | 1285 | +-------------------+--------------------------------------------+ | 
 | 1286 | | ``KEY_SF``        | Scroll 1 line forward                      | | 
 | 1287 | +-------------------+--------------------------------------------+ | 
 | 1288 | | ``KEY_SR``        | Scroll 1 line backward (reverse)           | | 
 | 1289 | +-------------------+--------------------------------------------+ | 
 | 1290 | | ``KEY_NPAGE``     | Next page                                  | | 
 | 1291 | +-------------------+--------------------------------------------+ | 
 | 1292 | | ``KEY_PPAGE``     | Previous page                              | | 
 | 1293 | +-------------------+--------------------------------------------+ | 
 | 1294 | | ``KEY_STAB``      | Set tab                                    | | 
 | 1295 | +-------------------+--------------------------------------------+ | 
 | 1296 | | ``KEY_CTAB``      | Clear tab                                  | | 
 | 1297 | +-------------------+--------------------------------------------+ | 
 | 1298 | | ``KEY_CATAB``     | Clear all tabs                             | | 
 | 1299 | +-------------------+--------------------------------------------+ | 
 | 1300 | | ``KEY_ENTER``     | Enter or send (unreliable)                 | | 
 | 1301 | +-------------------+--------------------------------------------+ | 
 | 1302 | | ``KEY_SRESET``    | Soft (partial) reset (unreliable)          | | 
 | 1303 | +-------------------+--------------------------------------------+ | 
 | 1304 | | ``KEY_RESET``     | Reset or hard reset (unreliable)           | | 
 | 1305 | +-------------------+--------------------------------------------+ | 
 | 1306 | | ``KEY_PRINT``     | Print                                      | | 
 | 1307 | +-------------------+--------------------------------------------+ | 
 | 1308 | | ``KEY_LL``        | Home down or bottom (lower left)           | | 
 | 1309 | +-------------------+--------------------------------------------+ | 
 | 1310 | | ``KEY_A1``        | Upper left of keypad                       | | 
 | 1311 | +-------------------+--------------------------------------------+ | 
 | 1312 | | ``KEY_A3``        | Upper right of keypad                      | | 
 | 1313 | +-------------------+--------------------------------------------+ | 
 | 1314 | | ``KEY_B2``        | Center of keypad                           | | 
 | 1315 | +-------------------+--------------------------------------------+ | 
 | 1316 | | ``KEY_C1``        | Lower left of keypad                       | | 
 | 1317 | +-------------------+--------------------------------------------+ | 
 | 1318 | | ``KEY_C3``        | Lower right of keypad                      | | 
 | 1319 | +-------------------+--------------------------------------------+ | 
 | 1320 | | ``KEY_BTAB``      | Back tab                                   | | 
 | 1321 | +-------------------+--------------------------------------------+ | 
 | 1322 | | ``KEY_BEG``       | Beg (beginning)                            | | 
 | 1323 | +-------------------+--------------------------------------------+ | 
 | 1324 | | ``KEY_CANCEL``    | Cancel                                     | | 
 | 1325 | +-------------------+--------------------------------------------+ | 
 | 1326 | | ``KEY_CLOSE``     | Close                                      | | 
 | 1327 | +-------------------+--------------------------------------------+ | 
 | 1328 | | ``KEY_COMMAND``   | Cmd (command)                              | | 
 | 1329 | +-------------------+--------------------------------------------+ | 
 | 1330 | | ``KEY_COPY``      | Copy                                       | | 
 | 1331 | +-------------------+--------------------------------------------+ | 
 | 1332 | | ``KEY_CREATE``    | Create                                     | | 
 | 1333 | +-------------------+--------------------------------------------+ | 
 | 1334 | | ``KEY_END``       | End                                        | | 
 | 1335 | +-------------------+--------------------------------------------+ | 
 | 1336 | | ``KEY_EXIT``      | Exit                                       | | 
 | 1337 | +-------------------+--------------------------------------------+ | 
 | 1338 | | ``KEY_FIND``      | Find                                       | | 
 | 1339 | +-------------------+--------------------------------------------+ | 
 | 1340 | | ``KEY_HELP``      | Help                                       | | 
 | 1341 | +-------------------+--------------------------------------------+ | 
 | 1342 | | ``KEY_MARK``      | Mark                                       | | 
 | 1343 | +-------------------+--------------------------------------------+ | 
 | 1344 | | ``KEY_MESSAGE``   | Message                                    | | 
 | 1345 | +-------------------+--------------------------------------------+ | 
 | 1346 | | ``KEY_MOVE``      | Move                                       | | 
 | 1347 | +-------------------+--------------------------------------------+ | 
 | 1348 | | ``KEY_NEXT``      | Next                                       | | 
 | 1349 | +-------------------+--------------------------------------------+ | 
 | 1350 | | ``KEY_OPEN``      | Open                                       | | 
 | 1351 | +-------------------+--------------------------------------------+ | 
 | 1352 | | ``KEY_OPTIONS``   | Options                                    | | 
 | 1353 | +-------------------+--------------------------------------------+ | 
 | 1354 | | ``KEY_PREVIOUS``  | Prev (previous)                            | | 
 | 1355 | +-------------------+--------------------------------------------+ | 
 | 1356 | | ``KEY_REDO``      | Redo                                       | | 
 | 1357 | +-------------------+--------------------------------------------+ | 
 | 1358 | | ``KEY_REFERENCE`` | Ref (reference)                            | | 
 | 1359 | +-------------------+--------------------------------------------+ | 
 | 1360 | | ``KEY_REFRESH``   | Refresh                                    | | 
 | 1361 | +-------------------+--------------------------------------------+ | 
 | 1362 | | ``KEY_REPLACE``   | Replace                                    | | 
 | 1363 | +-------------------+--------------------------------------------+ | 
 | 1364 | | ``KEY_RESTART``   | Restart                                    | | 
 | 1365 | +-------------------+--------------------------------------------+ | 
 | 1366 | | ``KEY_RESUME``    | Resume                                     | | 
 | 1367 | +-------------------+--------------------------------------------+ | 
 | 1368 | | ``KEY_SAVE``      | Save                                       | | 
 | 1369 | +-------------------+--------------------------------------------+ | 
 | 1370 | | ``KEY_SBEG``      | Shifted Beg (beginning)                    | | 
 | 1371 | +-------------------+--------------------------------------------+ | 
 | 1372 | | ``KEY_SCANCEL``   | Shifted Cancel                             | | 
 | 1373 | +-------------------+--------------------------------------------+ | 
 | 1374 | | ``KEY_SCOMMAND``  | Shifted Command                            | | 
 | 1375 | +-------------------+--------------------------------------------+ | 
 | 1376 | | ``KEY_SCOPY``     | Shifted Copy                               | | 
 | 1377 | +-------------------+--------------------------------------------+ | 
 | 1378 | | ``KEY_SCREATE``   | Shifted Create                             | | 
 | 1379 | +-------------------+--------------------------------------------+ | 
 | 1380 | | ``KEY_SDC``       | Shifted Delete char                        | | 
 | 1381 | +-------------------+--------------------------------------------+ | 
 | 1382 | | ``KEY_SDL``       | Shifted Delete line                        | | 
 | 1383 | +-------------------+--------------------------------------------+ | 
 | 1384 | | ``KEY_SELECT``    | Select                                     | | 
 | 1385 | +-------------------+--------------------------------------------+ | 
 | 1386 | | ``KEY_SEND``      | Shifted End                                | | 
 | 1387 | +-------------------+--------------------------------------------+ | 
 | 1388 | | ``KEY_SEOL``      | Shifted Clear line                         | | 
 | 1389 | +-------------------+--------------------------------------------+ | 
 | 1390 | | ``KEY_SEXIT``     | Shifted Dxit                               | | 
 | 1391 | +-------------------+--------------------------------------------+ | 
 | 1392 | | ``KEY_SFIND``     | Shifted Find                               | | 
 | 1393 | +-------------------+--------------------------------------------+ | 
 | 1394 | | ``KEY_SHELP``     | Shifted Help                               | | 
 | 1395 | +-------------------+--------------------------------------------+ | 
 | 1396 | | ``KEY_SHOME``     | Shifted Home                               | | 
 | 1397 | +-------------------+--------------------------------------------+ | 
 | 1398 | | ``KEY_SIC``       | Shifted Input                              | | 
 | 1399 | +-------------------+--------------------------------------------+ | 
 | 1400 | | ``KEY_SLEFT``     | Shifted Left arrow                         | | 
 | 1401 | +-------------------+--------------------------------------------+ | 
 | 1402 | | ``KEY_SMESSAGE``  | Shifted Message                            | | 
 | 1403 | +-------------------+--------------------------------------------+ | 
 | 1404 | | ``KEY_SMOVE``     | Shifted Move                               | | 
 | 1405 | +-------------------+--------------------------------------------+ | 
 | 1406 | | ``KEY_SNEXT``     | Shifted Next                               | | 
 | 1407 | +-------------------+--------------------------------------------+ | 
 | 1408 | | ``KEY_SOPTIONS``  | Shifted Options                            | | 
 | 1409 | +-------------------+--------------------------------------------+ | 
 | 1410 | | ``KEY_SPREVIOUS`` | Shifted Prev                               | | 
 | 1411 | +-------------------+--------------------------------------------+ | 
 | 1412 | | ``KEY_SPRINT``    | Shifted Print                              | | 
 | 1413 | +-------------------+--------------------------------------------+ | 
 | 1414 | | ``KEY_SREDO``     | Shifted Redo                               | | 
 | 1415 | +-------------------+--------------------------------------------+ | 
 | 1416 | | ``KEY_SREPLACE``  | Shifted Replace                            | | 
 | 1417 | +-------------------+--------------------------------------------+ | 
 | 1418 | | ``KEY_SRIGHT``    | Shifted Right arrow                        | | 
 | 1419 | +-------------------+--------------------------------------------+ | 
 | 1420 | | ``KEY_SRSUME``    | Shifted Resume                             | | 
 | 1421 | +-------------------+--------------------------------------------+ | 
 | 1422 | | ``KEY_SSAVE``     | Shifted Save                               | | 
 | 1423 | +-------------------+--------------------------------------------+ | 
 | 1424 | | ``KEY_SSUSPEND``  | Shifted Suspend                            | | 
 | 1425 | +-------------------+--------------------------------------------+ | 
 | 1426 | | ``KEY_SUNDO``     | Shifted Undo                               | | 
 | 1427 | +-------------------+--------------------------------------------+ | 
 | 1428 | | ``KEY_SUSPEND``   | Suspend                                    | | 
 | 1429 | +-------------------+--------------------------------------------+ | 
 | 1430 | | ``KEY_UNDO``      | Undo                                       | | 
 | 1431 | +-------------------+--------------------------------------------+ | 
 | 1432 | | ``KEY_MOUSE``     | Mouse event has occurred                   | | 
 | 1433 | +-------------------+--------------------------------------------+ | 
 | 1434 | | ``KEY_RESIZE``    | Terminal resize event                      | | 
 | 1435 | +-------------------+--------------------------------------------+ | 
 | 1436 | | ``KEY_MAX``       | Maximum key value                          | | 
 | 1437 | +-------------------+--------------------------------------------+ | 
 | 1438 |  | 
 | 1439 | On VT100s and their software emulations, such as X terminal emulators, there are | 
 | 1440 | normally at least four function keys (:const:`KEY_F1`, :const:`KEY_F2`, | 
 | 1441 | :const:`KEY_F3`, :const:`KEY_F4`) available, and the arrow keys mapped to | 
 | 1442 | :const:`KEY_UP`, :const:`KEY_DOWN`, :const:`KEY_LEFT` and :const:`KEY_RIGHT` in | 
 | 1443 | the obvious way.  If your machine has a PC keyboard, it is safe to expect arrow | 
 | 1444 | keys and twelve function keys (older PC keyboards may have only ten function | 
 | 1445 | keys); also, the following keypad mappings are standard: | 
 | 1446 |  | 
 | 1447 | +------------------+-----------+ | 
 | 1448 | | Keycap           | Constant  | | 
 | 1449 | +==================+===========+ | 
 | 1450 | | :kbd:`Insert`    | KEY_IC    | | 
 | 1451 | +------------------+-----------+ | 
 | 1452 | | :kbd:`Delete`    | KEY_DC    | | 
 | 1453 | +------------------+-----------+ | 
 | 1454 | | :kbd:`Home`      | KEY_HOME  | | 
 | 1455 | +------------------+-----------+ | 
 | 1456 | | :kbd:`End`       | KEY_END   | | 
 | 1457 | +------------------+-----------+ | 
 | 1458 | | :kbd:`Page Up`   | KEY_NPAGE | | 
 | 1459 | +------------------+-----------+ | 
 | 1460 | | :kbd:`Page Down` | KEY_PPAGE | | 
 | 1461 | +------------------+-----------+ | 
 | 1462 |  | 
 | 1463 | The following table lists characters from the alternate character set. These are | 
 | 1464 | inherited from the VT100 terminal, and will generally be  available on software | 
 | 1465 | emulations such as X terminals.  When there is no graphic available, curses | 
 | 1466 | falls back on a crude printable ASCII approximation. | 
 | 1467 |  | 
 | 1468 | .. note:: | 
 | 1469 |  | 
 | 1470 |    These are available only after :func:`initscr` has  been called. | 
 | 1471 |  | 
 | 1472 | +------------------+------------------------------------------+ | 
 | 1473 | | ACS code         | Meaning                                  | | 
 | 1474 | +==================+==========================================+ | 
 | 1475 | | ``ACS_BBSS``     | alternate name for upper right corner    | | 
 | 1476 | +------------------+------------------------------------------+ | 
 | 1477 | | ``ACS_BLOCK``    | solid square block                       | | 
 | 1478 | +------------------+------------------------------------------+ | 
 | 1479 | | ``ACS_BOARD``    | board of squares                         | | 
 | 1480 | +------------------+------------------------------------------+ | 
 | 1481 | | ``ACS_BSBS``     | alternate name for horizontal line       | | 
 | 1482 | +------------------+------------------------------------------+ | 
 | 1483 | | ``ACS_BSSB``     | alternate name for upper left corner     | | 
 | 1484 | +------------------+------------------------------------------+ | 
 | 1485 | | ``ACS_BSSS``     | alternate name for top tee               | | 
 | 1486 | +------------------+------------------------------------------+ | 
 | 1487 | | ``ACS_BTEE``     | bottom tee                               | | 
 | 1488 | +------------------+------------------------------------------+ | 
 | 1489 | | ``ACS_BULLET``   | bullet                                   | | 
 | 1490 | +------------------+------------------------------------------+ | 
 | 1491 | | ``ACS_CKBOARD``  | checker board (stipple)                  | | 
 | 1492 | +------------------+------------------------------------------+ | 
 | 1493 | | ``ACS_DARROW``   | arrow pointing down                      | | 
 | 1494 | +------------------+------------------------------------------+ | 
 | 1495 | | ``ACS_DEGREE``   | degree symbol                            | | 
 | 1496 | +------------------+------------------------------------------+ | 
 | 1497 | | ``ACS_DIAMOND``  | diamond                                  | | 
 | 1498 | +------------------+------------------------------------------+ | 
 | 1499 | | ``ACS_GEQUAL``   | greater-than-or-equal-to                 | | 
 | 1500 | +------------------+------------------------------------------+ | 
 | 1501 | | ``ACS_HLINE``    | horizontal line                          | | 
 | 1502 | +------------------+------------------------------------------+ | 
 | 1503 | | ``ACS_LANTERN``  | lantern symbol                           | | 
 | 1504 | +------------------+------------------------------------------+ | 
 | 1505 | | ``ACS_LARROW``   | left arrow                               | | 
 | 1506 | +------------------+------------------------------------------+ | 
 | 1507 | | ``ACS_LEQUAL``   | less-than-or-equal-to                    | | 
 | 1508 | +------------------+------------------------------------------+ | 
 | 1509 | | ``ACS_LLCORNER`` | lower left-hand corner                   | | 
 | 1510 | +------------------+------------------------------------------+ | 
 | 1511 | | ``ACS_LRCORNER`` | lower right-hand corner                  | | 
 | 1512 | +------------------+------------------------------------------+ | 
 | 1513 | | ``ACS_LTEE``     | left tee                                 | | 
 | 1514 | +------------------+------------------------------------------+ | 
 | 1515 | | ``ACS_NEQUAL``   | not-equal sign                           | | 
 | 1516 | +------------------+------------------------------------------+ | 
 | 1517 | | ``ACS_PI``       | letter pi                                | | 
 | 1518 | +------------------+------------------------------------------+ | 
 | 1519 | | ``ACS_PLMINUS``  | plus-or-minus sign                       | | 
 | 1520 | +------------------+------------------------------------------+ | 
 | 1521 | | ``ACS_PLUS``     | big plus sign                            | | 
 | 1522 | +------------------+------------------------------------------+ | 
 | 1523 | | ``ACS_RARROW``   | right arrow                              | | 
 | 1524 | +------------------+------------------------------------------+ | 
 | 1525 | | ``ACS_RTEE``     | right tee                                | | 
 | 1526 | +------------------+------------------------------------------+ | 
 | 1527 | | ``ACS_S1``       | scan line 1                              | | 
 | 1528 | +------------------+------------------------------------------+ | 
 | 1529 | | ``ACS_S3``       | scan line 3                              | | 
 | 1530 | +------------------+------------------------------------------+ | 
 | 1531 | | ``ACS_S7``       | scan line 7                              | | 
 | 1532 | +------------------+------------------------------------------+ | 
 | 1533 | | ``ACS_S9``       | scan line 9                              | | 
 | 1534 | +------------------+------------------------------------------+ | 
 | 1535 | | ``ACS_SBBS``     | alternate name for lower right corner    | | 
 | 1536 | +------------------+------------------------------------------+ | 
 | 1537 | | ``ACS_SBSB``     | alternate name for vertical line         | | 
 | 1538 | +------------------+------------------------------------------+ | 
 | 1539 | | ``ACS_SBSS``     | alternate name for right tee             | | 
 | 1540 | +------------------+------------------------------------------+ | 
 | 1541 | | ``ACS_SSBB``     | alternate name for lower left corner     | | 
 | 1542 | +------------------+------------------------------------------+ | 
 | 1543 | | ``ACS_SSBS``     | alternate name for bottom tee            | | 
 | 1544 | +------------------+------------------------------------------+ | 
 | 1545 | | ``ACS_SSSB``     | alternate name for left tee              | | 
 | 1546 | +------------------+------------------------------------------+ | 
 | 1547 | | ``ACS_SSSS``     | alternate name for crossover or big plus | | 
 | 1548 | +------------------+------------------------------------------+ | 
 | 1549 | | ``ACS_STERLING`` | pound sterling                           | | 
 | 1550 | +------------------+------------------------------------------+ | 
 | 1551 | | ``ACS_TTEE``     | top tee                                  | | 
 | 1552 | +------------------+------------------------------------------+ | 
 | 1553 | | ``ACS_UARROW``   | up arrow                                 | | 
 | 1554 | +------------------+------------------------------------------+ | 
 | 1555 | | ``ACS_ULCORNER`` | upper left corner                        | | 
 | 1556 | +------------------+------------------------------------------+ | 
 | 1557 | | ``ACS_URCORNER`` | upper right corner                       | | 
 | 1558 | +------------------+------------------------------------------+ | 
 | 1559 | | ``ACS_VLINE``    | vertical line                            | | 
 | 1560 | +------------------+------------------------------------------+ | 
 | 1561 |  | 
 | 1562 | The following table lists the predefined colors: | 
 | 1563 |  | 
 | 1564 | +-------------------+----------------------------+ | 
 | 1565 | | Constant          | Color                      | | 
 | 1566 | +===================+============================+ | 
 | 1567 | | ``COLOR_BLACK``   | Black                      | | 
 | 1568 | +-------------------+----------------------------+ | 
 | 1569 | | ``COLOR_BLUE``    | Blue                       | | 
 | 1570 | +-------------------+----------------------------+ | 
 | 1571 | | ``COLOR_CYAN``    | Cyan (light greenish blue) | | 
 | 1572 | +-------------------+----------------------------+ | 
 | 1573 | | ``COLOR_GREEN``   | Green                      | | 
 | 1574 | +-------------------+----------------------------+ | 
 | 1575 | | ``COLOR_MAGENTA`` | Magenta (purplish red)     | | 
 | 1576 | +-------------------+----------------------------+ | 
 | 1577 | | ``COLOR_RED``     | Red                        | | 
 | 1578 | +-------------------+----------------------------+ | 
 | 1579 | | ``COLOR_WHITE``   | White                      | | 
 | 1580 | +-------------------+----------------------------+ | 
 | 1581 | | ``COLOR_YELLOW``  | Yellow                     | | 
 | 1582 | +-------------------+----------------------------+ | 
 | 1583 |  | 
 | 1584 |  | 
 | 1585 | :mod:`curses.textpad` --- Text input widget for curses programs | 
 | 1586 | =============================================================== | 
 | 1587 |  | 
 | 1588 | .. module:: curses.textpad | 
 | 1589 |    :synopsis: Emacs-like input editing in a curses window. | 
 | 1590 | .. moduleauthor:: Eric Raymond <esr@thyrsus.com> | 
 | 1591 | .. sectionauthor:: Eric Raymond <esr@thyrsus.com> | 
 | 1592 |  | 
 | 1593 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1594 | The :mod:`curses.textpad` module provides a :class:`Textbox` class that handles | 
 | 1595 | elementary text editing in a curses window, supporting a set of keybindings | 
 | 1596 | resembling those of Emacs (thus, also of Netscape Navigator, BBedit 6.x, | 
 | 1597 | FrameMaker, and many other programs).  The module also provides a | 
 | 1598 | rectangle-drawing function useful for framing text boxes or for other purposes. | 
 | 1599 |  | 
 | 1600 | The module :mod:`curses.textpad` defines the following function: | 
 | 1601 |  | 
 | 1602 |  | 
 | 1603 | .. function:: rectangle(win, uly, ulx, lry, lrx) | 
 | 1604 |  | 
 | 1605 |    Draw a rectangle.  The first argument must be a window object; the remaining | 
 | 1606 |    arguments are coordinates relative to that window.  The second and third | 
 | 1607 |    arguments are the y and x coordinates of the upper left hand corner of the | 
 | 1608 |    rectangle to be drawn; the fourth and fifth arguments are the y and x | 
 | 1609 |    coordinates of the lower right hand corner. The rectangle will be drawn using | 
 | 1610 |    VT100/IBM PC forms characters on terminals that make this possible (including | 
 | 1611 |    xterm and most other software terminal emulators).  Otherwise it will be drawn | 
 | 1612 |    with ASCII  dashes, vertical bars, and plus signs. | 
 | 1613 |  | 
 | 1614 |  | 
 | 1615 | .. _curses-textpad-objects: | 
 | 1616 |  | 
 | 1617 | Textbox objects | 
 | 1618 | --------------- | 
 | 1619 |  | 
 | 1620 | You can instantiate a :class:`Textbox` object as follows: | 
 | 1621 |  | 
 | 1622 |  | 
 | 1623 | .. class:: Textbox(win) | 
 | 1624 |  | 
 | 1625 |    Return a textbox widget object.  The *win* argument should be a curses | 
 | 1626 |    :class:`WindowObject` in which the textbox is to be contained. The edit cursor | 
 | 1627 |    of the textbox is initially located at the upper left hand corner of the | 
 | 1628 |    containing window, with coordinates ``(0, 0)``. The instance's | 
 | 1629 |    :attr:`stripspaces` flag is initially on. | 
 | 1630 |  | 
| Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 1631 |    :class:`Textbox` objects have the following methods: | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1632 |  | 
 | 1633 |  | 
| Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 1634 |    .. method:: edit([validator]) | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1635 |  | 
| Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 1636 |       This is the entry point you will normally use.  It accepts editing | 
 | 1637 |       keystrokes until one of the termination keystrokes is entered.  If | 
 | 1638 |       *validator* is supplied, it must be a function.  It will be called for | 
 | 1639 |       each keystroke entered with the keystroke as a parameter; command dispatch | 
 | 1640 |       is done on the result. This method returns the window contents as a | 
 | 1641 |       string; whether blanks in the window are included is affected by the | 
| Senthil Kumaran | a6bac95 | 2011-07-04 11:28:30 -0700 | [diff] [blame] | 1642 |       :attr:`stripspaces` attribute. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1643 |  | 
 | 1644 |  | 
| Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 1645 |    .. method:: do_command(ch) | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1646 |  | 
| Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 1647 |       Process a single command keystroke.  Here are the supported special | 
 | 1648 |       keystrokes: | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1649 |  | 
| Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 1650 |       +------------------+-------------------------------------------+ | 
 | 1651 |       | Keystroke        | Action                                    | | 
 | 1652 |       +==================+===========================================+ | 
 | 1653 |       | :kbd:`Control-A` | Go to left edge of window.                | | 
 | 1654 |       +------------------+-------------------------------------------+ | 
 | 1655 |       | :kbd:`Control-B` | Cursor left, wrapping to previous line if | | 
 | 1656 |       |                  | appropriate.                              | | 
 | 1657 |       +------------------+-------------------------------------------+ | 
 | 1658 |       | :kbd:`Control-D` | Delete character under cursor.            | | 
 | 1659 |       +------------------+-------------------------------------------+ | 
 | 1660 |       | :kbd:`Control-E` | Go to right edge (stripspaces off) or end | | 
 | 1661 |       |                  | of line (stripspaces on).                 | | 
 | 1662 |       +------------------+-------------------------------------------+ | 
 | 1663 |       | :kbd:`Control-F` | Cursor right, wrapping to next line when  | | 
 | 1664 |       |                  | appropriate.                              | | 
 | 1665 |       +------------------+-------------------------------------------+ | 
 | 1666 |       | :kbd:`Control-G` | Terminate, returning the window contents. | | 
 | 1667 |       +------------------+-------------------------------------------+ | 
 | 1668 |       | :kbd:`Control-H` | Delete character backward.                | | 
 | 1669 |       +------------------+-------------------------------------------+ | 
 | 1670 |       | :kbd:`Control-J` | Terminate if the window is 1 line,        | | 
 | 1671 |       |                  | otherwise insert newline.                 | | 
 | 1672 |       +------------------+-------------------------------------------+ | 
 | 1673 |       | :kbd:`Control-K` | If line is blank, delete it, otherwise    | | 
 | 1674 |       |                  | clear to end of line.                     | | 
 | 1675 |       +------------------+-------------------------------------------+ | 
 | 1676 |       | :kbd:`Control-L` | Refresh screen.                           | | 
 | 1677 |       +------------------+-------------------------------------------+ | 
 | 1678 |       | :kbd:`Control-N` | Cursor down; move down one line.          | | 
 | 1679 |       +------------------+-------------------------------------------+ | 
 | 1680 |       | :kbd:`Control-O` | Insert a blank line at cursor location.   | | 
 | 1681 |       +------------------+-------------------------------------------+ | 
 | 1682 |       | :kbd:`Control-P` | Cursor up; move up one line.              | | 
 | 1683 |       +------------------+-------------------------------------------+ | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1684 |  | 
| Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 1685 |       Move operations do nothing if the cursor is at an edge where the movement | 
 | 1686 |       is not possible.  The following synonyms are supported where possible: | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1687 |  | 
| Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 1688 |       +------------------------+------------------+ | 
 | 1689 |       | Constant               | Keystroke        | | 
 | 1690 |       +========================+==================+ | 
 | 1691 |       | :const:`KEY_LEFT`      | :kbd:`Control-B` | | 
 | 1692 |       +------------------------+------------------+ | 
 | 1693 |       | :const:`KEY_RIGHT`     | :kbd:`Control-F` | | 
 | 1694 |       +------------------------+------------------+ | 
 | 1695 |       | :const:`KEY_UP`        | :kbd:`Control-P` | | 
 | 1696 |       +------------------------+------------------+ | 
 | 1697 |       | :const:`KEY_DOWN`      | :kbd:`Control-N` | | 
 | 1698 |       +------------------------+------------------+ | 
 | 1699 |       | :const:`KEY_BACKSPACE` | :kbd:`Control-h` | | 
 | 1700 |       +------------------------+------------------+ | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1701 |  | 
| Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 1702 |       All other keystrokes are treated as a command to insert the given | 
 | 1703 |       character and move right (with line wrapping). | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1704 |  | 
 | 1705 |  | 
| Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 1706 |    .. method:: gather() | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1707 |  | 
| Ezio Melotti | b6b7371 | 2011-06-26 13:38:11 +0300 | [diff] [blame] | 1708 |       Return the window contents as a string; whether blanks in the | 
| Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 1709 |       window are included is affected by the :attr:`stripspaces` member. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1710 |  | 
 | 1711 |  | 
| Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 1712 |    .. attribute:: stripspaces | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1713 |  | 
| Senthil Kumaran | a6bac95 | 2011-07-04 11:28:30 -0700 | [diff] [blame] | 1714 |       This attribute is a flag which controls the interpretation of blanks in | 
| Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 1715 |       the window.  When it is on, trailing blanks on each line are ignored; any | 
 | 1716 |       cursor motion that would land the cursor on a trailing blank goes to the | 
 | 1717 |       end of that line instead, and trailing blanks are stripped when the window | 
 | 1718 |       contents are gathered. |