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