blob: ecdac9a762f8e7115221ad150ecc600cfde1c398 [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
Ezio Melotti46015302011-06-26 13:34:56 +0300302.. function:: is_term_resized(nlines, ncols)
303
304 Return ``True`` if :func:`resize_term` would modify the window structure,
305 ``False`` otherwise.
306
307
Georg Brandl8ec7f652007-08-15 14:28:01 +0000308.. function:: isendwin()
309
Ezio Melotti14989cf2011-06-26 13:33:46 +0300310 Return ``True`` if :func:`endwin` has been called (that is, the curses library has
Georg Brandl8ec7f652007-08-15 14:28:01 +0000311 been deinitialized).
312
313
314.. function:: keyname(k)
315
316 Return the name of the key numbered *k*. The name of a key generating printable
317 ASCII character is the key's character. The name of a control-key combination
318 is a two-character string consisting of a caret followed by the corresponding
319 printable ASCII character. The name of an alt-key combination (128-255) is a
320 string consisting of the prefix 'M-' followed by the name of the corresponding
321 ASCII character.
322
323
324.. function:: killchar()
325
Ezio Melotti14989cf2011-06-26 13:33:46 +0300326 Return the user's current line kill character. Under Unix operating systems
Georg Brandl8ec7f652007-08-15 14:28:01 +0000327 this is a property of the controlling tty of the curses program, and is not set
328 by the curses library itself.
329
330
331.. function:: longname()
332
Ezio Melotti14989cf2011-06-26 13:33:46 +0300333 Return a string containing the terminfo long name field describing the current
Georg Brandl8ec7f652007-08-15 14:28:01 +0000334 terminal. The maximum length of a verbose description is 128 characters. It is
335 defined only after the call to :func:`initscr`.
336
337
338.. function:: meta(yes)
339
340 If *yes* is 1, allow 8-bit characters to be input. If *yes* is 0, allow only
341 7-bit chars.
342
343
344.. function:: mouseinterval(interval)
345
Ezio Melotti14989cf2011-06-26 13:33:46 +0300346 Set the maximum time in milliseconds that can elapse between press and release
347 events in order for them to be recognized as a click, and return the previous
Georg Brandl8ec7f652007-08-15 14:28:01 +0000348 interval value. The default value is 200 msec, or one fifth of a second.
349
350
351.. function:: mousemask(mousemask)
352
Ezio Melotti14989cf2011-06-26 13:33:46 +0300353 Set the mouse events to be reported, and return a tuple ``(availmask,
Georg Brandl8ec7f652007-08-15 14:28:01 +0000354 oldmask)``. *availmask* indicates which of the specified mouse events can be
355 reported; on complete failure it returns 0. *oldmask* is the previous value of
356 the given window's mouse event mask. If this function is never called, no mouse
357 events are ever reported.
358
359
360.. function:: napms(ms)
361
362 Sleep for *ms* milliseconds.
363
364
365.. function:: newpad(nlines, ncols)
366
Ezio Melotti14989cf2011-06-26 13:33:46 +0300367 Create and return a pointer to a new pad data structure with the given number
Georg Brandl8ec7f652007-08-15 14:28:01 +0000368 of lines and columns. A pad is returned as a window object.
369
370 A pad is like a window, except that it is not restricted by the screen size, and
371 is not necessarily associated with a particular part of the screen. Pads can be
372 used when a large window is needed, and only a part of the window will be on the
373 screen at one time. Automatic refreshes of pads (such as from scrolling or
374 echoing of input) do not occur. The :meth:`refresh` and :meth:`noutrefresh`
375 methods of a pad require 6 arguments to specify the part of the pad to be
376 displayed and the location on the screen to be used for the display. The
Ezio Melotti14989cf2011-06-26 13:33:46 +0300377 arguments are *pminrow*, *pmincol*, *sminrow*, *smincol*, *smaxrow*, *smaxcol*; the *p*
Georg Brandl8ec7f652007-08-15 14:28:01 +0000378 arguments refer to the upper left corner of the pad region to be displayed and
Ezio Melotti14989cf2011-06-26 13:33:46 +0300379 the *s* arguments define a clipping box on the screen within which the pad region
Georg Brandl8ec7f652007-08-15 14:28:01 +0000380 is to be displayed.
381
382
383.. function:: newwin([nlines, ncols,] begin_y, begin_x)
384
385 Return a new window, whose left-upper corner is at ``(begin_y, begin_x)``, and
386 whose height/width is *nlines*/*ncols*.
387
388 By default, the window will extend from the specified position to the lower
389 right corner of the screen.
390
391
392.. function:: nl()
393
394 Enter newline mode. This mode translates the return key into newline on input,
395 and translates newline into return and line-feed on output. Newline mode is
396 initially on.
397
398
399.. function:: nocbreak()
400
401 Leave cbreak mode. Return to normal "cooked" mode with line buffering.
402
403
404.. function:: noecho()
405
406 Leave echo mode. Echoing of input characters is turned off.
407
408
409.. function:: nonl()
410
411 Leave newline mode. Disable translation of return into newline on input, and
412 disable low-level translation of newline into newline/return on output (but this
413 does not change the behavior of ``addch('\n')``, which always does the
414 equivalent of return and line feed on the virtual screen). With translation
415 off, curses can sometimes speed up vertical motion a little; also, it will be
416 able to detect the return key on input.
417
418
419.. function:: noqiflush()
420
Ezio Melotti14989cf2011-06-26 13:33:46 +0300421 When the :func:`noqiflush` routine is used, normal flush of input and output queues
Georg Brandl8ec7f652007-08-15 14:28:01 +0000422 associated with the INTR, QUIT and SUSP characters will not be done. You may
423 want to call :func:`noqiflush` in a signal handler if you want output to
424 continue as though the interrupt had not occurred, after the handler exits.
425
426
427.. function:: noraw()
428
429 Leave raw mode. Return to normal "cooked" mode with line buffering.
430
431
432.. function:: pair_content(pair_number)
433
Ezio Melotti14989cf2011-06-26 13:33:46 +0300434 Return a tuple ``(fg, bg)`` containing the colors for the requested color pair.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000435 The value of *pair_number* must be between ``1`` and ``COLOR_PAIRS - 1``.
436
437
438.. function:: pair_number(attr)
439
Ezio Melotti14989cf2011-06-26 13:33:46 +0300440 Return the number of the color-pair set by the attribute value *attr*.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000441 :func:`color_pair` is the counterpart to this function.
442
443
444.. function:: putp(string)
445
Ezio Melotti14989cf2011-06-26 13:33:46 +0300446 Equivalent to ``tputs(str, 1, putchar)``; emit the value of a specified
447 terminfo capability for the current terminal. Note that the output of :func:`putp`
Georg Brandl8ec7f652007-08-15 14:28:01 +0000448 always goes to standard output.
449
450
451.. function:: qiflush( [flag] )
452
Ezio Melotti14989cf2011-06-26 13:33:46 +0300453 If *flag* is ``False``, the effect is the same as calling :func:`noqiflush`. If
454 *flag* is ``True``, or no argument is provided, the queues will be flushed when
Georg Brandl8ec7f652007-08-15 14:28:01 +0000455 these control characters are read.
456
457
458.. function:: raw()
459
460 Enter raw mode. In raw mode, normal line buffering and processing of
461 interrupt, quit, suspend, and flow control keys are turned off; characters are
462 presented to curses input functions one by one.
463
464
465.. function:: reset_prog_mode()
466
Ezio Melotti14989cf2011-06-26 13:33:46 +0300467 Restore the terminal to "program" mode, as previously saved by
Georg Brandl8ec7f652007-08-15 14:28:01 +0000468 :func:`def_prog_mode`.
469
470
471.. function:: reset_shell_mode()
472
Ezio Melotti14989cf2011-06-26 13:33:46 +0300473 Restore the terminal to "shell" mode, as previously saved by
Georg Brandl8ec7f652007-08-15 14:28:01 +0000474 :func:`def_shell_mode`.
475
476
Ezio Melotti46015302011-06-26 13:34:56 +0300477.. function:: resetty()
478
479 Restore the state of the terminal modes to what it was at the last call to
480 :func:`savetty`.
481
482
483.. function:: resize_term(nlines, ncols)
484
485 Backend function used by :func:`resizeterm`, performing most of the work;
486 when resizing the windows, :func:`resize_term` blank-fills the areas that are
487 extended. The calling application should fill in these areas with
488 appropriate data. The :func:`resize_term` function attempts to resize all
489 windows. However, due to the calling convention of pads, it is not possible
490 to resize these without additional interaction with the application.
491
492
493.. function:: resizeterm(nlines, ncols)
494
495 Resize the standard and current windows to the specified dimensions, and
496 adjusts other bookkeeping data used by the curses library that record the
497 window dimensions (in particular the SIGWINCH handler).
498
499
500.. function:: savetty()
501
502 Save the current state of the terminal modes in a buffer, usable by
503 :func:`resetty`.
504
505
Georg Brandl8ec7f652007-08-15 14:28:01 +0000506.. function:: setsyx(y, x)
507
Ezio Melotti14989cf2011-06-26 13:33:46 +0300508 Set the virtual screen cursor to *y*, *x*. If *y* and *x* are both -1, then
Georg Brandl8ec7f652007-08-15 14:28:01 +0000509 leaveok is set.
510
511
512.. function:: setupterm([termstr, fd])
513
Ezio Melotti14989cf2011-06-26 13:33:46 +0300514 Initialize the terminal. *termstr* is a string giving the terminal name; if
515 omitted, the value of the :envvar:`TERM` environment variable will be used. *fd* is the
Georg Brandl8ec7f652007-08-15 14:28:01 +0000516 file descriptor to which any initialization sequences will be sent; if not
517 supplied, the file descriptor for ``sys.stdout`` will be used.
518
519
520.. function:: start_color()
521
522 Must be called if the programmer wants to use colors, and before any other color
523 manipulation routine is called. It is good practice to call this routine right
524 after :func:`initscr`.
525
526 :func:`start_color` initializes eight basic colors (black, red, green, yellow,
527 blue, magenta, cyan, and white), and two global variables in the :mod:`curses`
528 module, :const:`COLORS` and :const:`COLOR_PAIRS`, containing the maximum number
529 of colors and color-pairs the terminal can support. It also restores the colors
530 on the terminal to the values they had when the terminal was just turned on.
531
532
533.. function:: termattrs()
534
Ezio Melotti14989cf2011-06-26 13:33:46 +0300535 Return a logical OR of all video attributes supported by the terminal. This
Georg Brandl8ec7f652007-08-15 14:28:01 +0000536 information is useful when a curses program needs complete control over the
537 appearance of the screen.
538
539
540.. function:: termname()
541
Ezio Melotti14989cf2011-06-26 13:33:46 +0300542 Return the value of the environment variable :envvar:`TERM`, truncated to 14 characters.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000543
544
545.. function:: tigetflag(capname)
546
Ezio Melotti14989cf2011-06-26 13:33:46 +0300547 Return the value of the Boolean capability corresponding to the terminfo
Georg Brandl8ec7f652007-08-15 14:28:01 +0000548 capability name *capname*. The value ``-1`` is returned if *capname* is not a
549 Boolean capability, or ``0`` if it is canceled or absent from the terminal
550 description.
551
552
553.. function:: tigetnum(capname)
554
Ezio Melotti14989cf2011-06-26 13:33:46 +0300555 Return the value of the numeric capability corresponding to the terminfo
Georg Brandl8ec7f652007-08-15 14:28:01 +0000556 capability name *capname*. The value ``-2`` is returned if *capname* is not a
557 numeric capability, or ``-1`` if it is canceled or absent from the terminal
558 description.
559
560
561.. function:: tigetstr(capname)
562
Ezio Melotti14989cf2011-06-26 13:33:46 +0300563 Return the value of the string capability corresponding to the terminfo
Georg Brandl8ec7f652007-08-15 14:28:01 +0000564 capability name *capname*. ``None`` is returned if *capname* is not a string
565 capability, or is canceled or absent from the terminal description.
566
567
568.. function:: tparm(str[,...])
569
Ezio Melotti14989cf2011-06-26 13:33:46 +0300570 Instantiate the string *str* with the supplied parameters, where *str* should
571 be a parameterized string obtained from the terminfo database. E.g.
572 ``tparm(tigetstr("cup"), 5, 3)`` could result in ``'\033[6;4H'``, the exact
Georg Brandl8ec7f652007-08-15 14:28:01 +0000573 result depending on terminal type.
574
575
576.. function:: typeahead(fd)
577
Ezio Melotti14989cf2011-06-26 13:33:46 +0300578 Specify that the file descriptor *fd* be used for typeahead checking. If *fd*
Georg Brandl8ec7f652007-08-15 14:28:01 +0000579 is ``-1``, then no typeahead checking is done.
580
581 The curses library does "line-breakout optimization" by looking for typeahead
582 periodically while updating the screen. If input is found, and it is coming
583 from a tty, the current update is postponed until refresh or doupdate is called
584 again, allowing faster response to commands typed in advance. This function
585 allows specifying a different file descriptor for typeahead checking.
586
587
588.. function:: unctrl(ch)
589
Ezio Melotti14989cf2011-06-26 13:33:46 +0300590 Return a string which is a printable representation of the character *ch*.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000591 Control characters are displayed as a caret followed by the character, for
592 example as ``^C``. Printing characters are left as they are.
593
594
595.. function:: ungetch(ch)
596
597 Push *ch* so the next :meth:`getch` will return it.
598
599 .. note::
600
601 Only one *ch* can be pushed before :meth:`getch` is called.
602
603
604.. function:: ungetmouse(id, x, y, z, bstate)
605
606 Push a :const:`KEY_MOUSE` event onto the input queue, associating the given
607 state data with it.
608
609
610.. function:: use_env(flag)
611
612 If used, this function should be called before :func:`initscr` or newterm are
Ezio Melotti14989cf2011-06-26 13:33:46 +0300613 called. When *flag* is ``False``, the values of lines and columns specified in the
Georg Brandl8ec7f652007-08-15 14:28:01 +0000614 terminfo database will be used, even if environment variables :envvar:`LINES`
615 and :envvar:`COLUMNS` (used by default) are set, or if curses is running in a
616 window (in which case default behavior would be to use the window size if
617 :envvar:`LINES` and :envvar:`COLUMNS` are not set).
618
619
620.. function:: use_default_colors()
621
622 Allow use of default values for colors on terminals supporting this feature. Use
623 this to support transparency in your application. The default color is assigned
624 to the color number -1. After calling this function, ``init_pair(x,
625 curses.COLOR_RED, -1)`` initializes, for instance, color pair *x* to a red
626 foreground color on the default background.
627
628
R David Murray491eb6a2011-06-18 19:31:22 -0400629.. function:: wrapper(func, ...)
630
631 Initialize curses and call another callable object, *func*, which should be the
632 rest of your curses-using application. If the application raises an exception,
633 this function will restore the terminal to a sane state before re-raising the
634 exception and generating a traceback. The callable object *func* is then passed
635 the main window 'stdscr' as its first argument, followed by any other arguments
636 passed to :func:`wrapper`. Before calling *func*, :func:`wrapper` turns on
637 cbreak mode, turns off echo, enables the terminal keypad, and initializes colors
638 if the terminal has color support. On exit (whether normally or by exception)
639 it restores cooked mode, turns on echo, and disables the terminal keypad.
640
641
Georg Brandl8ec7f652007-08-15 14:28:01 +0000642.. _curses-window-objects:
643
644Window Objects
645--------------
646
647Window objects, as returned by :func:`initscr` and :func:`newwin` above, have
648the following methods:
649
650
651.. method:: window.addch([y, x,] ch[, attr])
652
653 .. note::
654
Sandro Tosic67975b2011-08-12 19:31:15 +0200655 A *character* means a C character (an ASCII code), rather than a Python
Georg Brandld7d4fd72009-07-26 14:37:28 +0000656 character (a string of length 1). (This note is true whenever the
657 documentation mentions a character.) The built-in :func:`ord` is handy for
658 conveying strings to codes.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000659
660 Paint character *ch* at ``(y, x)`` with attributes *attr*, overwriting any
661 character previously painter at that location. By default, the character
662 position and attributes are the current settings for the window object.
663
664
665.. method:: window.addnstr([y, x,] str, n[, attr])
666
667 Paint at most *n* characters of the string *str* at ``(y, x)`` with attributes
668 *attr*, overwriting anything previously on the display.
669
670
671.. method:: window.addstr([y, x,] str[, attr])
672
673 Paint the string *str* at ``(y, x)`` with attributes *attr*, overwriting
674 anything previously on the display.
675
676
677.. method:: window.attroff(attr)
678
679 Remove attribute *attr* from the "background" set applied to all writes to the
680 current window.
681
682
683.. method:: window.attron(attr)
684
685 Add attribute *attr* from the "background" set applied to all writes to the
686 current window.
687
688
689.. method:: window.attrset(attr)
690
691 Set the "background" set of attributes to *attr*. This set is initially 0 (no
692 attributes).
693
694
695.. method:: window.bkgd(ch[, attr])
696
Ezio Melotti14989cf2011-06-26 13:33:46 +0300697 Set the background property of the window to the character *ch*, with
Georg Brandl8ec7f652007-08-15 14:28:01 +0000698 attributes *attr*. The change is then applied to every character position in
699 that window:
700
701 * The attribute of every character in the window is changed to the new
702 background attribute.
703
704 * Wherever the former background character appears, it is changed to the new
705 background character.
706
707
708.. method:: window.bkgdset(ch[, attr])
709
Ezio Melotti14989cf2011-06-26 13:33:46 +0300710 Set the window's background. A window's background consists of a character and
Georg Brandl8ec7f652007-08-15 14:28:01 +0000711 any combination of attributes. The attribute part of the background is combined
712 (OR'ed) with all non-blank characters that are written into the window. Both
713 the character and attribute parts of the background are combined with the blank
714 characters. The background becomes a property of the character and moves with
715 the character through any scrolling and insert/delete line/character operations.
716
717
718.. method:: window.border([ls[, rs[, ts[, bs[, tl[, tr[, bl[, br]]]]]]]])
719
720 Draw a border around the edges of the window. Each parameter specifies the
721 character to use for a specific part of the border; see the table below for more
722 details. The characters can be specified as integers or as one-character
723 strings.
724
725 .. note::
726
727 A ``0`` value for any parameter will cause the default character to be used for
728 that parameter. Keyword parameters can *not* be used. The defaults are listed
729 in this table:
730
731 +-----------+---------------------+-----------------------+
732 | Parameter | Description | Default value |
733 +===========+=====================+=======================+
734 | *ls* | Left side | :const:`ACS_VLINE` |
735 +-----------+---------------------+-----------------------+
736 | *rs* | Right side | :const:`ACS_VLINE` |
737 +-----------+---------------------+-----------------------+
738 | *ts* | Top | :const:`ACS_HLINE` |
739 +-----------+---------------------+-----------------------+
740 | *bs* | Bottom | :const:`ACS_HLINE` |
741 +-----------+---------------------+-----------------------+
742 | *tl* | Upper-left corner | :const:`ACS_ULCORNER` |
743 +-----------+---------------------+-----------------------+
744 | *tr* | Upper-right corner | :const:`ACS_URCORNER` |
745 +-----------+---------------------+-----------------------+
746 | *bl* | Bottom-left corner | :const:`ACS_LLCORNER` |
747 +-----------+---------------------+-----------------------+
748 | *br* | Bottom-right corner | :const:`ACS_LRCORNER` |
749 +-----------+---------------------+-----------------------+
750
751
752.. method:: window.box([vertch, horch])
753
754 Similar to :meth:`border`, but both *ls* and *rs* are *vertch* and both *ts* and
Ezio Melotti14989cf2011-06-26 13:33:46 +0300755 *bs* are *horch*. The default corner characters are always used by this function.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000756
757
758.. method:: window.chgat([y, x, ] [num,] attr)
759
Ezio Melotti14989cf2011-06-26 13:33:46 +0300760 Set the attributes of *num* characters at the current cursor position, or at
Georg Brandl8ec7f652007-08-15 14:28:01 +0000761 position ``(y, x)`` if supplied. If no value of *num* is given or *num* = -1,
762 the attribute will be set on all the characters to the end of the line. This
763 function does not move the cursor. The changed line will be touched using the
764 :meth:`touchline` method so that the contents will be redisplayed by the next
765 window refresh.
766
767
768.. method:: window.clear()
769
Ezio Melotti14989cf2011-06-26 13:33:46 +0300770 Like :meth:`erase`, but also cause the whole window to be repainted upon next
Georg Brandl8ec7f652007-08-15 14:28:01 +0000771 call to :meth:`refresh`.
772
773
774.. method:: window.clearok(yes)
775
776 If *yes* is 1, the next call to :meth:`refresh` will clear the window
777 completely.
778
779
780.. method:: window.clrtobot()
781
782 Erase from cursor to the end of the window: all lines below the cursor are
783 deleted, and then the equivalent of :meth:`clrtoeol` is performed.
784
785
786.. method:: window.clrtoeol()
787
788 Erase from cursor to the end of the line.
789
790
791.. method:: window.cursyncup()
792
Ezio Melotti14989cf2011-06-26 13:33:46 +0300793 Update the current cursor position of all the ancestors of the window to
Georg Brandl8ec7f652007-08-15 14:28:01 +0000794 reflect the current cursor position of the window.
795
796
797.. method:: window.delch([y, x])
798
799 Delete any character at ``(y, x)``.
800
801
802.. method:: window.deleteln()
803
Ezio Melotti14989cf2011-06-26 13:33:46 +0300804 Delete the line under the cursor. All following lines are moved up by one line.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000805
806
807.. method:: window.derwin([nlines, ncols,] begin_y, begin_x)
808
809 An abbreviation for "derive window", :meth:`derwin` is the same as calling
810 :meth:`subwin`, except that *begin_y* and *begin_x* are relative to the origin
Ezio Melotti14989cf2011-06-26 13:33:46 +0300811 of the window, rather than relative to the entire screen. Return a window
Georg Brandl8ec7f652007-08-15 14:28:01 +0000812 object for the derived window.
813
814
815.. method:: window.echochar(ch[, attr])
816
817 Add character *ch* with attribute *attr*, and immediately call :meth:`refresh`
818 on the window.
819
820
821.. method:: window.enclose(y, x)
822
Ezio Melotti14989cf2011-06-26 13:33:46 +0300823 Test whether the given pair of screen-relative character-cell coordinates are
824 enclosed by the given window, returning ``True`` or ``False``. It is useful for
Georg Brandl8ec7f652007-08-15 14:28:01 +0000825 determining what subset of the screen windows enclose the location of a mouse
826 event.
827
828
829.. method:: window.erase()
830
831 Clear the window.
832
833
834.. method:: window.getbegyx()
835
836 Return a tuple ``(y, x)`` of co-ordinates of upper-left corner.
837
838
Ezio Melotti46015302011-06-26 13:34:56 +0300839.. method:: window.getbkgd()
840
841 Return the given window's current background character/attribute pair.
842
843
Georg Brandl8ec7f652007-08-15 14:28:01 +0000844.. method:: window.getch([y, x])
845
846 Get a character. Note that the integer returned does *not* have to be in ASCII
847 range: function keys, keypad keys and so on return numbers higher than 256. In
Georg Brandl2fcf3892009-06-17 09:36:21 +0000848 no-delay mode, -1 is returned if there is no input, else :func:`getch` waits
849 until a key is pressed.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000850
851
852.. method:: window.getkey([y, x])
853
854 Get a character, returning a string instead of an integer, as :meth:`getch`
855 does. Function keys, keypad keys and so on return a multibyte string containing
856 the key name. In no-delay mode, an exception is raised if there is no input.
857
858
859.. method:: window.getmaxyx()
860
861 Return a tuple ``(y, x)`` of the height and width of the window.
862
863
864.. method:: window.getparyx()
865
Ezio Melotti14989cf2011-06-26 13:33:46 +0300866 Return the beginning coordinates of this window relative to its parent window
867 into two integer variables y and x. Return ``-1, -1`` if this window has no
Georg Brandl8ec7f652007-08-15 14:28:01 +0000868 parent.
869
870
871.. method:: window.getstr([y, x])
872
873 Read a string from the user, with primitive line editing capacity.
874
875
876.. method:: window.getyx()
877
878 Return a tuple ``(y, x)`` of current cursor position relative to the window's
879 upper-left corner.
880
881
882.. method:: window.hline([y, x,] ch, n)
883
884 Display a horizontal line starting at ``(y, x)`` with length *n* consisting of
885 the character *ch*.
886
887
888.. method:: window.idcok(flag)
889
Ezio Melotti14989cf2011-06-26 13:33:46 +0300890 If *flag* is ``False``, curses no longer considers using the hardware insert/delete
891 character feature of the terminal; if *flag* is ``True``, use of character insertion
Georg Brandl8ec7f652007-08-15 14:28:01 +0000892 and deletion is enabled. When curses is first initialized, use of character
893 insert/delete is enabled by default.
894
895
896.. method:: window.idlok(yes)
897
898 If called with *yes* equal to 1, :mod:`curses` will try and use hardware line
899 editing facilities. Otherwise, line insertion/deletion are disabled.
900
901
902.. method:: window.immedok(flag)
903
Ezio Melotti14989cf2011-06-26 13:33:46 +0300904 If *flag* is ``True``, any change in the window image automatically causes the
Georg Brandl8ec7f652007-08-15 14:28:01 +0000905 window to be refreshed; you no longer have to call :meth:`refresh` yourself.
906 However, it may degrade performance considerably, due to repeated calls to
907 wrefresh. This option is disabled by default.
908
909
910.. method:: window.inch([y, x])
911
912 Return the character at the given position in the window. The bottom 8 bits are
913 the character proper, and upper bits are the attributes.
914
915
916.. method:: window.insch([y, x,] ch[, attr])
917
918 Paint character *ch* at ``(y, x)`` with attributes *attr*, moving the line from
919 position *x* right by one character.
920
921
922.. method:: window.insdelln(nlines)
923
Ezio Melotti14989cf2011-06-26 13:33:46 +0300924 Insert *nlines* lines into the specified window above the current line. The
Georg Brandl8ec7f652007-08-15 14:28:01 +0000925 *nlines* bottom lines are lost. For negative *nlines*, delete *nlines* lines
926 starting with the one under the cursor, and move the remaining lines up. The
927 bottom *nlines* lines are cleared. The current cursor position remains the
928 same.
929
930
931.. method:: window.insertln()
932
Ezio Melotti14989cf2011-06-26 13:33:46 +0300933 Insert a blank line under the cursor. All following lines are moved down by one
Georg Brandl8ec7f652007-08-15 14:28:01 +0000934 line.
935
936
937.. method:: window.insnstr([y, x,] str, n [, attr])
938
939 Insert a character string (as many characters as will fit on the line) before
940 the character under the cursor, up to *n* characters. If *n* is zero or
941 negative, the entire string is inserted. All characters to the right of the
942 cursor are shifted right, with the rightmost characters on the line being lost.
943 The cursor position does not change (after moving to *y*, *x*, if specified).
944
945
946.. method:: window.insstr([y, x, ] str [, attr])
947
948 Insert a character string (as many characters as will fit on the line) before
949 the character under the cursor. All characters to the right of the cursor are
950 shifted right, with the rightmost characters on the line being lost. The cursor
951 position does not change (after moving to *y*, *x*, if specified).
952
953
954.. method:: window.instr([y, x] [, n])
955
Ezio Melotti14989cf2011-06-26 13:33:46 +0300956 Return a string of characters, extracted from the window starting at the
Georg Brandl8ec7f652007-08-15 14:28:01 +0000957 current cursor position, or at *y*, *x* if specified. Attributes are stripped
Ezio Melotti14989cf2011-06-26 13:33:46 +0300958 from the characters. If *n* is specified, :meth:`instr` returns a string
Georg Brandl8ec7f652007-08-15 14:28:01 +0000959 at most *n* characters long (exclusive of the trailing NUL).
960
961
962.. method:: window.is_linetouched(line)
963
Ezio Melotti14989cf2011-06-26 13:33:46 +0300964 Return ``True`` if the specified line was modified since the last call to
965 :meth:`refresh`; otherwise return ``False``. Raise a :exc:`curses.error`
Georg Brandl8ec7f652007-08-15 14:28:01 +0000966 exception if *line* is not valid for the given window.
967
968
969.. method:: window.is_wintouched()
970
Ezio Melotti14989cf2011-06-26 13:33:46 +0300971 Return ``True`` if the specified window was modified since the last call to
972 :meth:`refresh`; otherwise return ``False``.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000973
974
975.. method:: window.keypad(yes)
976
977 If *yes* is 1, escape sequences generated by some keys (keypad, function keys)
978 will be interpreted by :mod:`curses`. If *yes* is 0, escape sequences will be
979 left as is in the input stream.
980
981
982.. method:: window.leaveok(yes)
983
984 If *yes* is 1, cursor is left where it is on update, instead of being at "cursor
985 position." This reduces cursor movement where possible. If possible the cursor
986 will be made invisible.
987
988 If *yes* is 0, cursor will always be at "cursor position" after an update.
989
990
991.. method:: window.move(new_y, new_x)
992
993 Move cursor to ``(new_y, new_x)``.
994
995
996.. method:: window.mvderwin(y, x)
997
Ezio Melotti14989cf2011-06-26 13:33:46 +0300998 Move the window inside its parent window. The screen-relative parameters of
Georg Brandl8ec7f652007-08-15 14:28:01 +0000999 the window are not changed. This routine is used to display different parts of
1000 the parent window at the same physical position on the screen.
1001
1002
1003.. method:: window.mvwin(new_y, new_x)
1004
1005 Move the window so its upper-left corner is at ``(new_y, new_x)``.
1006
1007
1008.. method:: window.nodelay(yes)
1009
1010 If *yes* is ``1``, :meth:`getch` will be non-blocking.
1011
1012
1013.. method:: window.notimeout(yes)
1014
1015 If *yes* is ``1``, escape sequences will not be timed out.
1016
1017 If *yes* is ``0``, after a few milliseconds, an escape sequence will not be
1018 interpreted, and will be left in the input stream as is.
1019
1020
1021.. method:: window.noutrefresh()
1022
1023 Mark for refresh but wait. This function updates the data structure
1024 representing the desired state of the window, but does not force an update of
1025 the physical screen. To accomplish that, call :func:`doupdate`.
1026
1027
1028.. method:: window.overlay(destwin[, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol])
1029
1030 Overlay the window on top of *destwin*. The windows need not be the same size,
1031 only the overlapping region is copied. This copy is non-destructive, which means
1032 that the current background character does not overwrite the old contents of
1033 *destwin*.
1034
1035 To get fine-grained control over the copied region, the second form of
1036 :meth:`overlay` can be used. *sminrow* and *smincol* are the upper-left
1037 coordinates of the source window, and the other variables mark a rectangle in
1038 the destination window.
1039
1040
1041.. method:: window.overwrite(destwin[, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol])
1042
1043 Overwrite the window on top of *destwin*. The windows need not be the same size,
1044 in which case only the overlapping region is copied. This copy is destructive,
1045 which means that the current background character overwrites the old contents of
1046 *destwin*.
1047
1048 To get fine-grained control over the copied region, the second form of
1049 :meth:`overwrite` can be used. *sminrow* and *smincol* are the upper-left
1050 coordinates of the source window, the other variables mark a rectangle in the
1051 destination window.
1052
1053
1054.. method:: window.putwin(file)
1055
Ezio Melotti14989cf2011-06-26 13:33:46 +03001056 Write all data associated with the window into the provided file object. This
Georg Brandl8ec7f652007-08-15 14:28:01 +00001057 information can be later retrieved using the :func:`getwin` function.
1058
1059
1060.. method:: window.redrawln(beg, num)
1061
Ezio Melotti14989cf2011-06-26 13:33:46 +03001062 Indicate that the *num* screen lines, starting at line *beg*, are corrupted and
Georg Brandl8ec7f652007-08-15 14:28:01 +00001063 should be completely redrawn on the next :meth:`refresh` call.
1064
1065
1066.. method:: window.redrawwin()
1067
Ezio Melotti14989cf2011-06-26 13:33:46 +03001068 Touch the entire window, causing it to be completely redrawn on the next
Georg Brandl8ec7f652007-08-15 14:28:01 +00001069 :meth:`refresh` call.
1070
1071
1072.. method:: window.refresh([pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol])
1073
1074 Update the display immediately (sync actual screen with previous
1075 drawing/deleting methods).
1076
1077 The 6 optional arguments can only be specified when the window is a pad created
1078 with :func:`newpad`. The additional parameters are needed to indicate what part
1079 of the pad and screen are involved. *pminrow* and *pmincol* specify the upper
1080 left-hand corner of the rectangle to be displayed in the pad. *sminrow*,
1081 *smincol*, *smaxrow*, and *smaxcol* specify the edges of the rectangle to be
1082 displayed on the screen. The lower right-hand corner of the rectangle to be
1083 displayed in the pad is calculated from the screen coordinates, since the
1084 rectangles must be the same size. Both rectangles must be entirely contained
1085 within their respective structures. Negative values of *pminrow*, *pmincol*,
1086 *sminrow*, or *smincol* are treated as if they were zero.
1087
1088
Ezio Melotti46015302011-06-26 13:34:56 +03001089.. method:: window.resize(nlines, ncols)
1090
1091 Reallocate storage for a curses window to adjust its dimensions to the
1092 specified values. If either dimension is larger than the current values, the
1093 window's data is filled with blanks that have the current background
1094 rendition (as set by :meth:`bkgdset`) merged into them.
1095
1096
Georg Brandl8ec7f652007-08-15 14:28:01 +00001097.. method:: window.scroll([lines=1])
1098
1099 Scroll the screen or scrolling region upward by *lines* lines.
1100
1101
1102.. method:: window.scrollok(flag)
1103
Ezio Melotti14989cf2011-06-26 13:33:46 +03001104 Control what happens when the cursor of a window is moved off the edge of the
Georg Brandl8ec7f652007-08-15 14:28:01 +00001105 window or scrolling region, either as a result of a newline action on the bottom
1106 line, or typing the last character of the last line. If *flag* is false, the
1107 cursor is left on the bottom line. If *flag* is true, the window is scrolled up
1108 one line. Note that in order to get the physical scrolling effect on the
1109 terminal, it is also necessary to call :meth:`idlok`.
1110
1111
1112.. method:: window.setscrreg(top, bottom)
1113
1114 Set the scrolling region from line *top* to line *bottom*. All scrolling actions
1115 will take place in this region.
1116
1117
1118.. method:: window.standend()
1119
1120 Turn off the standout attribute. On some terminals this has the side effect of
1121 turning off all attributes.
1122
1123
1124.. method:: window.standout()
1125
1126 Turn on attribute *A_STANDOUT*.
1127
1128
1129.. method:: window.subpad([nlines, ncols,] begin_y, begin_x)
1130
1131 Return a sub-window, whose upper-left corner is at ``(begin_y, begin_x)``, and
1132 whose width/height is *ncols*/*nlines*.
1133
1134
1135.. method:: window.subwin([nlines, ncols,] begin_y, begin_x)
1136
1137 Return a sub-window, whose upper-left corner is at ``(begin_y, begin_x)``, and
1138 whose width/height is *ncols*/*nlines*.
1139
1140 By default, the sub-window will extend from the specified position to the lower
1141 right corner of the window.
1142
1143
1144.. method:: window.syncdown()
1145
Ezio Melotti14989cf2011-06-26 13:33:46 +03001146 Touch each location in the window that has been touched in any of its ancestor
Georg Brandl8ec7f652007-08-15 14:28:01 +00001147 windows. This routine is called by :meth:`refresh`, so it should almost never
1148 be necessary to call it manually.
1149
1150
1151.. method:: window.syncok(flag)
1152
Ezio Melotti14989cf2011-06-26 13:33:46 +03001153 If called with *flag* set to ``True``, then :meth:`syncup` is called automatically
Georg Brandl8ec7f652007-08-15 14:28:01 +00001154 whenever there is a change in the window.
1155
1156
1157.. method:: window.syncup()
1158
Ezio Melotti14989cf2011-06-26 13:33:46 +03001159 Touch all locations in ancestors of the window that have been changed in the
Georg Brandl8ec7f652007-08-15 14:28:01 +00001160 window.
1161
1162
1163.. method:: window.timeout(delay)
1164
Ezio Melotti14989cf2011-06-26 13:33:46 +03001165 Set blocking or non-blocking read behavior for the window. If *delay* is
Georg Brandl8ec7f652007-08-15 14:28:01 +00001166 negative, blocking read is used (which will wait indefinitely for input). If
1167 *delay* is zero, then non-blocking read is used, and -1 will be returned by
1168 :meth:`getch` if no input is waiting. If *delay* is positive, then
1169 :meth:`getch` will block for *delay* milliseconds, and return -1 if there is
1170 still no input at the end of that time.
1171
1172
1173.. method:: window.touchline(start, count[, changed])
1174
1175 Pretend *count* lines have been changed, starting with line *start*. If
1176 *changed* is supplied, it specifies whether the affected lines are marked as
1177 having been changed (*changed*\ =1) or unchanged (*changed*\ =0).
1178
1179
1180.. method:: window.touchwin()
1181
1182 Pretend the whole window has been changed, for purposes of drawing
1183 optimizations.
1184
1185
1186.. method:: window.untouchwin()
1187
Ezio Melotti14989cf2011-06-26 13:33:46 +03001188 Mark all lines in the window as unchanged since the last call to
Georg Brandl8ec7f652007-08-15 14:28:01 +00001189 :meth:`refresh`.
1190
1191
1192.. method:: window.vline([y, x,] ch, n)
1193
1194 Display a vertical line starting at ``(y, x)`` with length *n* consisting of the
1195 character *ch*.
1196
1197
1198Constants
1199---------
1200
1201The :mod:`curses` module defines the following data members:
1202
1203
1204.. data:: ERR
1205
1206 Some curses routines that return an integer, such as :func:`getch`, return
1207 :const:`ERR` upon failure.
1208
1209
1210.. data:: OK
1211
1212 Some curses routines that return an integer, such as :func:`napms`, return
1213 :const:`OK` upon success.
1214
1215
1216.. data:: version
1217
1218 A string representing the current version of the module. Also available as
1219 :const:`__version__`.
1220
1221Several constants are available to specify character cell attributes:
1222
1223+------------------+-------------------------------+
1224| Attribute | Meaning |
1225+==================+===============================+
1226| ``A_ALTCHARSET`` | Alternate character set mode. |
1227+------------------+-------------------------------+
1228| ``A_BLINK`` | Blink mode. |
1229+------------------+-------------------------------+
1230| ``A_BOLD`` | Bold mode. |
1231+------------------+-------------------------------+
1232| ``A_DIM`` | Dim mode. |
1233+------------------+-------------------------------+
1234| ``A_NORMAL`` | Normal attribute. |
1235+------------------+-------------------------------+
Georg Brandl6076c1b2011-03-06 11:08:35 +01001236| ``A_REVERSE`` | Reverse background and |
1237| | foreground colors. |
1238+------------------+-------------------------------+
Georg Brandl8ec7f652007-08-15 14:28:01 +00001239| ``A_STANDOUT`` | Standout mode. |
1240+------------------+-------------------------------+
1241| ``A_UNDERLINE`` | Underline mode. |
1242+------------------+-------------------------------+
1243
1244Keys are referred to by integer constants with names starting with ``KEY_``.
1245The exact keycaps available are system dependent.
1246
Georg Brandlb19be572007-12-29 10:57:00 +00001247.. XXX this table is far too large! should it be alphabetized?
Georg Brandl8ec7f652007-08-15 14:28:01 +00001248
1249+-------------------+--------------------------------------------+
1250| Key constant | Key |
1251+===================+============================================+
1252| ``KEY_MIN`` | Minimum key value |
1253+-------------------+--------------------------------------------+
1254| ``KEY_BREAK`` | Break key (unreliable) |
1255+-------------------+--------------------------------------------+
1256| ``KEY_DOWN`` | Down-arrow |
1257+-------------------+--------------------------------------------+
1258| ``KEY_UP`` | Up-arrow |
1259+-------------------+--------------------------------------------+
1260| ``KEY_LEFT`` | Left-arrow |
1261+-------------------+--------------------------------------------+
1262| ``KEY_RIGHT`` | Right-arrow |
1263+-------------------+--------------------------------------------+
1264| ``KEY_HOME`` | Home key (upward+left arrow) |
1265+-------------------+--------------------------------------------+
1266| ``KEY_BACKSPACE`` | Backspace (unreliable) |
1267+-------------------+--------------------------------------------+
1268| ``KEY_F0`` | Function keys. Up to 64 function keys are |
1269| | supported. |
1270+-------------------+--------------------------------------------+
1271| ``KEY_Fn`` | Value of function key *n* |
1272+-------------------+--------------------------------------------+
1273| ``KEY_DL`` | Delete line |
1274+-------------------+--------------------------------------------+
1275| ``KEY_IL`` | Insert line |
1276+-------------------+--------------------------------------------+
1277| ``KEY_DC`` | Delete character |
1278+-------------------+--------------------------------------------+
1279| ``KEY_IC`` | Insert char or enter insert mode |
1280+-------------------+--------------------------------------------+
1281| ``KEY_EIC`` | Exit insert char mode |
1282+-------------------+--------------------------------------------+
1283| ``KEY_CLEAR`` | Clear screen |
1284+-------------------+--------------------------------------------+
1285| ``KEY_EOS`` | Clear to end of screen |
1286+-------------------+--------------------------------------------+
1287| ``KEY_EOL`` | Clear to end of line |
1288+-------------------+--------------------------------------------+
1289| ``KEY_SF`` | Scroll 1 line forward |
1290+-------------------+--------------------------------------------+
1291| ``KEY_SR`` | Scroll 1 line backward (reverse) |
1292+-------------------+--------------------------------------------+
1293| ``KEY_NPAGE`` | Next page |
1294+-------------------+--------------------------------------------+
1295| ``KEY_PPAGE`` | Previous page |
1296+-------------------+--------------------------------------------+
1297| ``KEY_STAB`` | Set tab |
1298+-------------------+--------------------------------------------+
1299| ``KEY_CTAB`` | Clear tab |
1300+-------------------+--------------------------------------------+
1301| ``KEY_CATAB`` | Clear all tabs |
1302+-------------------+--------------------------------------------+
1303| ``KEY_ENTER`` | Enter or send (unreliable) |
1304+-------------------+--------------------------------------------+
1305| ``KEY_SRESET`` | Soft (partial) reset (unreliable) |
1306+-------------------+--------------------------------------------+
1307| ``KEY_RESET`` | Reset or hard reset (unreliable) |
1308+-------------------+--------------------------------------------+
1309| ``KEY_PRINT`` | Print |
1310+-------------------+--------------------------------------------+
1311| ``KEY_LL`` | Home down or bottom (lower left) |
1312+-------------------+--------------------------------------------+
1313| ``KEY_A1`` | Upper left of keypad |
1314+-------------------+--------------------------------------------+
1315| ``KEY_A3`` | Upper right of keypad |
1316+-------------------+--------------------------------------------+
1317| ``KEY_B2`` | Center of keypad |
1318+-------------------+--------------------------------------------+
1319| ``KEY_C1`` | Lower left of keypad |
1320+-------------------+--------------------------------------------+
1321| ``KEY_C3`` | Lower right of keypad |
1322+-------------------+--------------------------------------------+
1323| ``KEY_BTAB`` | Back tab |
1324+-------------------+--------------------------------------------+
1325| ``KEY_BEG`` | Beg (beginning) |
1326+-------------------+--------------------------------------------+
1327| ``KEY_CANCEL`` | Cancel |
1328+-------------------+--------------------------------------------+
1329| ``KEY_CLOSE`` | Close |
1330+-------------------+--------------------------------------------+
1331| ``KEY_COMMAND`` | Cmd (command) |
1332+-------------------+--------------------------------------------+
1333| ``KEY_COPY`` | Copy |
1334+-------------------+--------------------------------------------+
1335| ``KEY_CREATE`` | Create |
1336+-------------------+--------------------------------------------+
1337| ``KEY_END`` | End |
1338+-------------------+--------------------------------------------+
1339| ``KEY_EXIT`` | Exit |
1340+-------------------+--------------------------------------------+
1341| ``KEY_FIND`` | Find |
1342+-------------------+--------------------------------------------+
1343| ``KEY_HELP`` | Help |
1344+-------------------+--------------------------------------------+
1345| ``KEY_MARK`` | Mark |
1346+-------------------+--------------------------------------------+
1347| ``KEY_MESSAGE`` | Message |
1348+-------------------+--------------------------------------------+
1349| ``KEY_MOVE`` | Move |
1350+-------------------+--------------------------------------------+
1351| ``KEY_NEXT`` | Next |
1352+-------------------+--------------------------------------------+
1353| ``KEY_OPEN`` | Open |
1354+-------------------+--------------------------------------------+
1355| ``KEY_OPTIONS`` | Options |
1356+-------------------+--------------------------------------------+
1357| ``KEY_PREVIOUS`` | Prev (previous) |
1358+-------------------+--------------------------------------------+
1359| ``KEY_REDO`` | Redo |
1360+-------------------+--------------------------------------------+
1361| ``KEY_REFERENCE`` | Ref (reference) |
1362+-------------------+--------------------------------------------+
1363| ``KEY_REFRESH`` | Refresh |
1364+-------------------+--------------------------------------------+
1365| ``KEY_REPLACE`` | Replace |
1366+-------------------+--------------------------------------------+
1367| ``KEY_RESTART`` | Restart |
1368+-------------------+--------------------------------------------+
1369| ``KEY_RESUME`` | Resume |
1370+-------------------+--------------------------------------------+
1371| ``KEY_SAVE`` | Save |
1372+-------------------+--------------------------------------------+
1373| ``KEY_SBEG`` | Shifted Beg (beginning) |
1374+-------------------+--------------------------------------------+
1375| ``KEY_SCANCEL`` | Shifted Cancel |
1376+-------------------+--------------------------------------------+
1377| ``KEY_SCOMMAND`` | Shifted Command |
1378+-------------------+--------------------------------------------+
1379| ``KEY_SCOPY`` | Shifted Copy |
1380+-------------------+--------------------------------------------+
1381| ``KEY_SCREATE`` | Shifted Create |
1382+-------------------+--------------------------------------------+
1383| ``KEY_SDC`` | Shifted Delete char |
1384+-------------------+--------------------------------------------+
1385| ``KEY_SDL`` | Shifted Delete line |
1386+-------------------+--------------------------------------------+
1387| ``KEY_SELECT`` | Select |
1388+-------------------+--------------------------------------------+
1389| ``KEY_SEND`` | Shifted End |
1390+-------------------+--------------------------------------------+
1391| ``KEY_SEOL`` | Shifted Clear line |
1392+-------------------+--------------------------------------------+
1393| ``KEY_SEXIT`` | Shifted Dxit |
1394+-------------------+--------------------------------------------+
1395| ``KEY_SFIND`` | Shifted Find |
1396+-------------------+--------------------------------------------+
1397| ``KEY_SHELP`` | Shifted Help |
1398+-------------------+--------------------------------------------+
1399| ``KEY_SHOME`` | Shifted Home |
1400+-------------------+--------------------------------------------+
1401| ``KEY_SIC`` | Shifted Input |
1402+-------------------+--------------------------------------------+
1403| ``KEY_SLEFT`` | Shifted Left arrow |
1404+-------------------+--------------------------------------------+
1405| ``KEY_SMESSAGE`` | Shifted Message |
1406+-------------------+--------------------------------------------+
1407| ``KEY_SMOVE`` | Shifted Move |
1408+-------------------+--------------------------------------------+
1409| ``KEY_SNEXT`` | Shifted Next |
1410+-------------------+--------------------------------------------+
1411| ``KEY_SOPTIONS`` | Shifted Options |
1412+-------------------+--------------------------------------------+
1413| ``KEY_SPREVIOUS`` | Shifted Prev |
1414+-------------------+--------------------------------------------+
1415| ``KEY_SPRINT`` | Shifted Print |
1416+-------------------+--------------------------------------------+
1417| ``KEY_SREDO`` | Shifted Redo |
1418+-------------------+--------------------------------------------+
1419| ``KEY_SREPLACE`` | Shifted Replace |
1420+-------------------+--------------------------------------------+
1421| ``KEY_SRIGHT`` | Shifted Right arrow |
1422+-------------------+--------------------------------------------+
1423| ``KEY_SRSUME`` | Shifted Resume |
1424+-------------------+--------------------------------------------+
1425| ``KEY_SSAVE`` | Shifted Save |
1426+-------------------+--------------------------------------------+
1427| ``KEY_SSUSPEND`` | Shifted Suspend |
1428+-------------------+--------------------------------------------+
1429| ``KEY_SUNDO`` | Shifted Undo |
1430+-------------------+--------------------------------------------+
1431| ``KEY_SUSPEND`` | Suspend |
1432+-------------------+--------------------------------------------+
1433| ``KEY_UNDO`` | Undo |
1434+-------------------+--------------------------------------------+
1435| ``KEY_MOUSE`` | Mouse event has occurred |
1436+-------------------+--------------------------------------------+
1437| ``KEY_RESIZE`` | Terminal resize event |
1438+-------------------+--------------------------------------------+
1439| ``KEY_MAX`` | Maximum key value |
1440+-------------------+--------------------------------------------+
1441
1442On VT100s and their software emulations, such as X terminal emulators, there are
1443normally at least four function keys (:const:`KEY_F1`, :const:`KEY_F2`,
1444:const:`KEY_F3`, :const:`KEY_F4`) available, and the arrow keys mapped to
1445:const:`KEY_UP`, :const:`KEY_DOWN`, :const:`KEY_LEFT` and :const:`KEY_RIGHT` in
1446the obvious way. If your machine has a PC keyboard, it is safe to expect arrow
1447keys and twelve function keys (older PC keyboards may have only ten function
1448keys); also, the following keypad mappings are standard:
1449
1450+------------------+-----------+
1451| Keycap | Constant |
1452+==================+===========+
1453| :kbd:`Insert` | KEY_IC |
1454+------------------+-----------+
1455| :kbd:`Delete` | KEY_DC |
1456+------------------+-----------+
1457| :kbd:`Home` | KEY_HOME |
1458+------------------+-----------+
1459| :kbd:`End` | KEY_END |
1460+------------------+-----------+
1461| :kbd:`Page Up` | KEY_NPAGE |
1462+------------------+-----------+
1463| :kbd:`Page Down` | KEY_PPAGE |
1464+------------------+-----------+
1465
1466The following table lists characters from the alternate character set. These are
1467inherited from the VT100 terminal, and will generally be available on software
1468emulations such as X terminals. When there is no graphic available, curses
1469falls back on a crude printable ASCII approximation.
1470
1471.. note::
1472
1473 These are available only after :func:`initscr` has been called.
1474
1475+------------------+------------------------------------------+
1476| ACS code | Meaning |
1477+==================+==========================================+
1478| ``ACS_BBSS`` | alternate name for upper right corner |
1479+------------------+------------------------------------------+
1480| ``ACS_BLOCK`` | solid square block |
1481+------------------+------------------------------------------+
1482| ``ACS_BOARD`` | board of squares |
1483+------------------+------------------------------------------+
1484| ``ACS_BSBS`` | alternate name for horizontal line |
1485+------------------+------------------------------------------+
1486| ``ACS_BSSB`` | alternate name for upper left corner |
1487+------------------+------------------------------------------+
1488| ``ACS_BSSS`` | alternate name for top tee |
1489+------------------+------------------------------------------+
1490| ``ACS_BTEE`` | bottom tee |
1491+------------------+------------------------------------------+
1492| ``ACS_BULLET`` | bullet |
1493+------------------+------------------------------------------+
1494| ``ACS_CKBOARD`` | checker board (stipple) |
1495+------------------+------------------------------------------+
1496| ``ACS_DARROW`` | arrow pointing down |
1497+------------------+------------------------------------------+
1498| ``ACS_DEGREE`` | degree symbol |
1499+------------------+------------------------------------------+
1500| ``ACS_DIAMOND`` | diamond |
1501+------------------+------------------------------------------+
1502| ``ACS_GEQUAL`` | greater-than-or-equal-to |
1503+------------------+------------------------------------------+
1504| ``ACS_HLINE`` | horizontal line |
1505+------------------+------------------------------------------+
1506| ``ACS_LANTERN`` | lantern symbol |
1507+------------------+------------------------------------------+
1508| ``ACS_LARROW`` | left arrow |
1509+------------------+------------------------------------------+
1510| ``ACS_LEQUAL`` | less-than-or-equal-to |
1511+------------------+------------------------------------------+
1512| ``ACS_LLCORNER`` | lower left-hand corner |
1513+------------------+------------------------------------------+
1514| ``ACS_LRCORNER`` | lower right-hand corner |
1515+------------------+------------------------------------------+
1516| ``ACS_LTEE`` | left tee |
1517+------------------+------------------------------------------+
1518| ``ACS_NEQUAL`` | not-equal sign |
1519+------------------+------------------------------------------+
1520| ``ACS_PI`` | letter pi |
1521+------------------+------------------------------------------+
1522| ``ACS_PLMINUS`` | plus-or-minus sign |
1523+------------------+------------------------------------------+
1524| ``ACS_PLUS`` | big plus sign |
1525+------------------+------------------------------------------+
1526| ``ACS_RARROW`` | right arrow |
1527+------------------+------------------------------------------+
1528| ``ACS_RTEE`` | right tee |
1529+------------------+------------------------------------------+
1530| ``ACS_S1`` | scan line 1 |
1531+------------------+------------------------------------------+
1532| ``ACS_S3`` | scan line 3 |
1533+------------------+------------------------------------------+
1534| ``ACS_S7`` | scan line 7 |
1535+------------------+------------------------------------------+
1536| ``ACS_S9`` | scan line 9 |
1537+------------------+------------------------------------------+
1538| ``ACS_SBBS`` | alternate name for lower right corner |
1539+------------------+------------------------------------------+
1540| ``ACS_SBSB`` | alternate name for vertical line |
1541+------------------+------------------------------------------+
1542| ``ACS_SBSS`` | alternate name for right tee |
1543+------------------+------------------------------------------+
1544| ``ACS_SSBB`` | alternate name for lower left corner |
1545+------------------+------------------------------------------+
1546| ``ACS_SSBS`` | alternate name for bottom tee |
1547+------------------+------------------------------------------+
1548| ``ACS_SSSB`` | alternate name for left tee |
1549+------------------+------------------------------------------+
1550| ``ACS_SSSS`` | alternate name for crossover or big plus |
1551+------------------+------------------------------------------+
1552| ``ACS_STERLING`` | pound sterling |
1553+------------------+------------------------------------------+
1554| ``ACS_TTEE`` | top tee |
1555+------------------+------------------------------------------+
1556| ``ACS_UARROW`` | up arrow |
1557+------------------+------------------------------------------+
1558| ``ACS_ULCORNER`` | upper left corner |
1559+------------------+------------------------------------------+
1560| ``ACS_URCORNER`` | upper right corner |
1561+------------------+------------------------------------------+
1562| ``ACS_VLINE`` | vertical line |
1563+------------------+------------------------------------------+
1564
1565The following table lists the predefined colors:
1566
1567+-------------------+----------------------------+
1568| Constant | Color |
1569+===================+============================+
1570| ``COLOR_BLACK`` | Black |
1571+-------------------+----------------------------+
1572| ``COLOR_BLUE`` | Blue |
1573+-------------------+----------------------------+
1574| ``COLOR_CYAN`` | Cyan (light greenish blue) |
1575+-------------------+----------------------------+
1576| ``COLOR_GREEN`` | Green |
1577+-------------------+----------------------------+
1578| ``COLOR_MAGENTA`` | Magenta (purplish red) |
1579+-------------------+----------------------------+
1580| ``COLOR_RED`` | Red |
1581+-------------------+----------------------------+
1582| ``COLOR_WHITE`` | White |
1583+-------------------+----------------------------+
1584| ``COLOR_YELLOW`` | Yellow |
1585+-------------------+----------------------------+
1586
1587
1588:mod:`curses.textpad` --- Text input widget for curses programs
1589===============================================================
1590
1591.. module:: curses.textpad
1592 :synopsis: Emacs-like input editing in a curses window.
1593.. moduleauthor:: Eric Raymond <esr@thyrsus.com>
1594.. sectionauthor:: Eric Raymond <esr@thyrsus.com>
1595
1596
1597.. versionadded:: 1.6
1598
1599The :mod:`curses.textpad` module provides a :class:`Textbox` class that handles
1600elementary text editing in a curses window, supporting a set of keybindings
1601resembling those of Emacs (thus, also of Netscape Navigator, BBedit 6.x,
1602FrameMaker, and many other programs). The module also provides a
1603rectangle-drawing function useful for framing text boxes or for other purposes.
1604
1605The module :mod:`curses.textpad` defines the following function:
1606
1607
1608.. function:: rectangle(win, uly, ulx, lry, lrx)
1609
1610 Draw a rectangle. The first argument must be a window object; the remaining
1611 arguments are coordinates relative to that window. The second and third
1612 arguments are the y and x coordinates of the upper left hand corner of the
1613 rectangle to be drawn; the fourth and fifth arguments are the y and x
1614 coordinates of the lower right hand corner. The rectangle will be drawn using
1615 VT100/IBM PC forms characters on terminals that make this possible (including
1616 xterm and most other software terminal emulators). Otherwise it will be drawn
1617 with ASCII dashes, vertical bars, and plus signs.
1618
1619
1620.. _curses-textpad-objects:
1621
1622Textbox objects
1623---------------
1624
1625You can instantiate a :class:`Textbox` object as follows:
1626
1627
1628.. class:: Textbox(win)
1629
1630 Return a textbox widget object. The *win* argument should be a curses
1631 :class:`WindowObject` in which the textbox is to be contained. The edit cursor
1632 of the textbox is initially located at the upper left hand corner of the
1633 containing window, with coordinates ``(0, 0)``. The instance's
1634 :attr:`stripspaces` flag is initially on.
1635
Benjamin Petersonc7b05922008-04-25 01:29:10 +00001636 :class:`Textbox` objects have the following methods:
Georg Brandl8ec7f652007-08-15 14:28:01 +00001637
1638
Benjamin Petersonc7b05922008-04-25 01:29:10 +00001639 .. method:: edit([validator])
Georg Brandl8ec7f652007-08-15 14:28:01 +00001640
Benjamin Petersonc7b05922008-04-25 01:29:10 +00001641 This is the entry point you will normally use. It accepts editing
1642 keystrokes until one of the termination keystrokes is entered. If
1643 *validator* is supplied, it must be a function. It will be called for
1644 each keystroke entered with the keystroke as a parameter; command dispatch
1645 is done on the result. This method returns the window contents as a
1646 string; whether blanks in the window are included is affected by the
Senthil Kumaran6f18b982011-07-04 12:50:02 -07001647 :attr:`stripspaces` attribute.
Georg Brandl8ec7f652007-08-15 14:28:01 +00001648
1649
Benjamin Petersonc7b05922008-04-25 01:29:10 +00001650 .. method:: do_command(ch)
Georg Brandl8ec7f652007-08-15 14:28:01 +00001651
Benjamin Petersonc7b05922008-04-25 01:29:10 +00001652 Process a single command keystroke. Here are the supported special
1653 keystrokes:
Georg Brandl8ec7f652007-08-15 14:28:01 +00001654
Benjamin Petersonc7b05922008-04-25 01:29:10 +00001655 +------------------+-------------------------------------------+
1656 | Keystroke | Action |
1657 +==================+===========================================+
1658 | :kbd:`Control-A` | Go to left edge of window. |
1659 +------------------+-------------------------------------------+
1660 | :kbd:`Control-B` | Cursor left, wrapping to previous line if |
1661 | | appropriate. |
1662 +------------------+-------------------------------------------+
1663 | :kbd:`Control-D` | Delete character under cursor. |
1664 +------------------+-------------------------------------------+
1665 | :kbd:`Control-E` | Go to right edge (stripspaces off) or end |
1666 | | of line (stripspaces on). |
1667 +------------------+-------------------------------------------+
1668 | :kbd:`Control-F` | Cursor right, wrapping to next line when |
1669 | | appropriate. |
1670 +------------------+-------------------------------------------+
1671 | :kbd:`Control-G` | Terminate, returning the window contents. |
1672 +------------------+-------------------------------------------+
1673 | :kbd:`Control-H` | Delete character backward. |
1674 +------------------+-------------------------------------------+
1675 | :kbd:`Control-J` | Terminate if the window is 1 line, |
1676 | | otherwise insert newline. |
1677 +------------------+-------------------------------------------+
1678 | :kbd:`Control-K` | If line is blank, delete it, otherwise |
1679 | | clear to end of line. |
1680 +------------------+-------------------------------------------+
1681 | :kbd:`Control-L` | Refresh screen. |
1682 +------------------+-------------------------------------------+
1683 | :kbd:`Control-N` | Cursor down; move down one line. |
1684 +------------------+-------------------------------------------+
1685 | :kbd:`Control-O` | Insert a blank line at cursor location. |
1686 +------------------+-------------------------------------------+
1687 | :kbd:`Control-P` | Cursor up; move up one line. |
1688 +------------------+-------------------------------------------+
Georg Brandl8ec7f652007-08-15 14:28:01 +00001689
Benjamin Petersonc7b05922008-04-25 01:29:10 +00001690 Move operations do nothing if the cursor is at an edge where the movement
1691 is not possible. The following synonyms are supported where possible:
Georg Brandl8ec7f652007-08-15 14:28:01 +00001692
Benjamin Petersonc7b05922008-04-25 01:29:10 +00001693 +------------------------+------------------+
1694 | Constant | Keystroke |
1695 +========================+==================+
1696 | :const:`KEY_LEFT` | :kbd:`Control-B` |
1697 +------------------------+------------------+
1698 | :const:`KEY_RIGHT` | :kbd:`Control-F` |
1699 +------------------------+------------------+
1700 | :const:`KEY_UP` | :kbd:`Control-P` |
1701 +------------------------+------------------+
1702 | :const:`KEY_DOWN` | :kbd:`Control-N` |
1703 +------------------------+------------------+
1704 | :const:`KEY_BACKSPACE` | :kbd:`Control-h` |
1705 +------------------------+------------------+
Georg Brandl8ec7f652007-08-15 14:28:01 +00001706
Benjamin Petersonc7b05922008-04-25 01:29:10 +00001707 All other keystrokes are treated as a command to insert the given
1708 character and move right (with line wrapping).
Georg Brandl8ec7f652007-08-15 14:28:01 +00001709
1710
Benjamin Petersonc7b05922008-04-25 01:29:10 +00001711 .. method:: gather()
Georg Brandl8ec7f652007-08-15 14:28:01 +00001712
Ezio Melotti14989cf2011-06-26 13:33:46 +03001713 Return the window contents as a string; whether blanks in the
Benjamin Petersonc7b05922008-04-25 01:29:10 +00001714 window are included is affected by the :attr:`stripspaces` member.
Georg Brandl8ec7f652007-08-15 14:28:01 +00001715
1716
Benjamin Petersonc7b05922008-04-25 01:29:10 +00001717 .. attribute:: stripspaces
Georg Brandl8ec7f652007-08-15 14:28:01 +00001718
Senthil Kumaran6f18b982011-07-04 12:50:02 -07001719 This attribute is a flag which controls the interpretation of blanks in
Benjamin Petersonc7b05922008-04-25 01:29:10 +00001720 the window. When it is on, trailing blanks on each line are ignored; any
1721 cursor motion that would land the cursor on a trailing blank goes to the
1722 end of that line instead, and trailing blanks are stripped when the window
1723 contents are gathered.
Georg Brandl8ec7f652007-08-15 14:28:01 +00001724