source: vendor/python/2.5/Doc/lib/libcurses.tex

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

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