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