Debian Codegraph @

Doc/library/curses.rst

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