blob: e9ed7a2d759301a517a90f981674f5dfec0e1741 [file] [log] [blame]
Fred Drakea4070ce1999-06-21 21:13:09 +00001\section{\module{curses} ---
Fred Drakef8ca7d82000-10-10 17:03:45 +00002 Terminal handling for character-cell displays}
Fred Drakea4070ce1999-06-21 21:13:09 +00003
Eric S. Raymond5a007692000-08-04 07:35:41 +00004\declaremodule{standard}{curses}
Fred Drake57657bc2000-12-01 15:25:23 +00005\sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
Eric S. Raymond68996602000-07-24 03:28:40 +00006\sectionauthor{Eric Raymond}{esr@thyrsus.com}
Fred Drakef8ca7d82000-10-10 17:03:45 +00007\modulesynopsis{An interface to the curses library, providing portable
8 terminal handling.}
Fred Drake2e06c202000-10-06 20:01:23 +00009
10\versionchanged[Added support for the \code{ncurses} library and
11 converted to a package]{1.6}
Fred Drakea4070ce1999-06-21 21:13:09 +000012
Fred Draked79c33a2000-09-25 14:14:30 +000013The \module{curses} module provides an interface to the curses
Fred Drakea4070ce1999-06-21 21:13:09 +000014library, the de-facto standard for portable advanced terminal
15handling.
16
17While curses is most widely used in the \UNIX{} environment, versions
Eric S. Raymond68996602000-07-24 03:28:40 +000018are 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
Fred Draked79c33a2000-09-25 14:14:30 +000021\UNIX.
Fred Drakea4070ce1999-06-21 21:13:09 +000022
23\begin{seealso}
Fred Drake5c529d32000-06-28 22:11:40 +000024 \seemodule{curses.ascii}{Utilities for working with \ASCII{}
25 characters, regardless of your locale
26 settings.}
Andrew M. Kuchling5caee402000-12-22 22:06:43 +000027 \seemodule{curses.panel}{A panel stack extension that adds depth to
28 curses windows.}
Eric S. Raymond5a007692000-08-04 07:35:41 +000029 \seemodule{curses.textpad}{Editable text widget for curses supporting
Fred Drakeec4b2af2000-08-09 14:34:48 +000030 \program{Emacs}-like bindings.}
31 \seemodule{curses.wrapper}{Convenience function to ensure proper
32 terminal setup and resetting on
33 application entry and exit.}
Fred Draked79c33a2000-09-25 14:14:30 +000034 \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, is available on the
37 Python Web site.}
Andrew M. Kuchling4fb58822000-12-15 01:03:23 +000038 \seetitle[Demo/curses]{}{Some example programs.}
Fred Drakea4070ce1999-06-21 21:13:09 +000039\end{seealso}
40
41
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000042\subsection{Functions \label{curses-functions}}
Fred Drakea4070ce1999-06-21 21:13:09 +000043
44The module \module{curses} defines the following exception:
Fred Drakeec4b2af2000-08-09 14:34:48 +000045
Fred Drakea4070ce1999-06-21 21:13:09 +000046\begin{excdesc}{error}
Fred Drakeec4b2af2000-08-09 14:34:48 +000047Exception raised when a curses library function returns an error.
Fred Drakea4070ce1999-06-21 21:13:09 +000048\end{excdesc}
49
Fred Drake0bccd731999-06-23 17:28:01 +000050\strong{Note:} Whenever \var{x} or \var{y} arguments to a function
51or a method are optional, they default to the current cursor location.
52Whenever \var{attr} is optional, it defaults to \constant{A_NORMAL}.
53
Fred Drakea4070ce1999-06-21 21:13:09 +000054The module \module{curses} defines the following functions:
55
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000056\begin{funcdesc}{baudrate}{}
Eric S. Raymond68996602000-07-24 03:28:40 +000057Returns the output speed of the terminal in bits per second. On
58software terminal emulators it will have a fixed high value.
59Included for historical reasons; in former times, it was used to
60write output loops for time delays and occasionally to change
61interfaces depending on the line speed.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000062\end{funcdesc}
63
64\begin{funcdesc}{beep}{}
Eric S. Raymond68996602000-07-24 03:28:40 +000065Emit a short attention sound.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000066\end{funcdesc}
67
68\begin{funcdesc}{can_change_color}{}
69Returns true or false, depending on whether the programmer can change
70the colors displayed by the terminal.
71\end{funcdesc}
72
73\begin{funcdesc}{cbreak}{}
Eric S. Raymond68996602000-07-24 03:28:40 +000074Enter cbreak mode. In cbreak mode (sometimes called ``rare'' mode)
75normal tty line buffering is turned off and characters are available
76to be read one by one. However, unlike raw mode, special characters
77(interrupt, quit, suspend, and flow control) retain their effects on
78the tty driver and calling program. Calling first \function{raw()}
79then \function{cbreak()} leaves the terminal in cbreak mode.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000080\end{funcdesc}
81
82\begin{funcdesc}{color_content}{color_number}
83Returns the intensity of the red, green, and blue (RGB) components in
Fred Drakee412e7a2000-12-21 17:04:31 +000084the color \var{color_number}, which must be between \code{0} and
85\constant{COLORS}. A 3-tuple is returned, containing the R,G,B values
86for the given color, which will be between \code{0} (no component) and
87\code{1000} (maximum amount of component).
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000088\end{funcdesc}
89
90\begin{funcdesc}{color_pair}{color_number}
91Returns the attribute value for displaying text in the specified
92color. This attribute value can be combined with
93\constant{A_STANDOUT}, \constant{A_REVERSE}, and the other
Fred Drakee412e7a2000-12-21 17:04:31 +000094\constant{A_*} attributes. \function{pair_number()} is the
95counterpart to this function.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000096\end{funcdesc}
97
98\begin{funcdesc}{curs_set}{visibility}
99Sets the cursor state. \var{visibility} can be set to 0, 1, or 2, for
100invisible, normal, or very visible. If the terminal supports the
101visibility requested, the previous cursor state is returned;
Eric S. Raymond68996602000-07-24 03:28:40 +0000102otherwise, an exception is raised. On many terminals, the ``visible''
103mode is an underline cursor and the ``very visible'' mode is a block cursor.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000104\end{funcdesc}
105
106\begin{funcdesc}{def_prog_mode}{}
107Saves the current terminal mode as the ``program'' mode, the mode when
108the running program is using curses. (Its counterpart is the
109``shell'' mode, for when the program is not in curses.) Subsequent calls
110to \function{reset_prog_mode()} will restore this mode.
111\end{funcdesc}
112
113\begin{funcdesc}{def_shell_mode}{}
114Saves the current terminal mode as the ``shell'' mode, the mode when
115the running program is not using curses. (Its counterpart is the
116``program'' mode, when the program is using curses capabilities.)
117Subsequent calls
118to \function{reset_shell_mode()} will restore this mode.
119\end{funcdesc}
120
121\begin{funcdesc}{delay_output}{ms}
122Inserts an \var{ms} millisecond pause in output.
123\end{funcdesc}
124
125\begin{funcdesc}{doupdate}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000126Update the physical screen. The curses library keeps two data
127structures, one representing the current physical screen contents
128and a virtual screen representing the desired next state. The
129\function{doupdate()} ground updates the physical screen to match the
130virtual screen.
131
132The virtual screen may be updated by a \method{noutrefresh()} call
133after write operations such as \method{addstr()} have been performed
134on a window. The normal \method{refresh()} call is simply
135\method{noutrefresh()} followed by \function{doupdate()}; if you have
136to update multiple windows, you can speed performance and perhaps
137reduce screen flicker by issuing \method{noutrefresh()} calls on
138all windows, followed by a single \function{doupdate()}.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000139\end{funcdesc}
140
141\begin{funcdesc}{echo}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000142Enter echo mode. In echo mode, each character input is echoed to the
143screen as it is entered.
Fred Drakea4070ce1999-06-21 21:13:09 +0000144\end{funcdesc}
145
146\begin{funcdesc}{endwin}{}
147De-initialize the library, and return terminal to normal status.
148\end{funcdesc}
149
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000150\begin{funcdesc}{erasechar}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000151Returns the user's current erase character. Under Unix operating
152systems this is a property of the controlling tty of the curses
153program, and is not set by the curses library itself.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000154\end{funcdesc}
155
156\begin{funcdesc}{filter}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000157The \function{filter()} routine, if used, must be called before
158\function{initscr()} is called. The effect is that, during those
159calls, LINES is set to 1; the capabilities clear, cup, cud, cud1,
160cuu1, cuu, vpa are disabled; and the home string is set to the value of cr.
161The effect is that the cursor is confined to the current line, and so
162are screen updates. This may be used for enabling cgaracter-at-a-time
163line editing without touching the rest of the screen.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000164\end{funcdesc}
165
166\begin{funcdesc}{flash}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000167Flash the screen. That is, change it to reverse-video and then change
168it back in a short interval. Some people prefer such as `visible bell'
169to the audible attention signal produced by \function{beep()}.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000170\end{funcdesc}
171
172\begin{funcdesc}{flushinp}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000173Flush all input buffers. This throws away any typeahead that has
174been typed by the user and has not yet been processed by the program.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000175\end{funcdesc}
176
Andrew M. Kuchlingefc43d42000-06-30 01:05:39 +0000177\begin{funcdesc}{getmouse}{}
178After \method{getch()} returns \constant{KEY_MOUSE} to signal a mouse
179event, this method should be call to retrieve the queued mouse event,
180represented as a 5-tuple
181\code{(\var{id}, \var{x}, \var{y}, \var{z}, \var{bstate})}.
182\var{id} is an ID value used to distinguish multiple devices,
183and \var{x}, \var{y}, \var{z} are the event's coordinates. (\var{z}
184is currently unused.). \var{bstate} is an integer value whose bits
185will be set to indicate the type of event, and will be the bitwise OR
186of one or more of the following constants, where \var{n} is the button
187number from 1 to 4:
188\constant{BUTTON\var{n}_PRESSED},
189\constant{BUTTON\var{n}_RELEASED},
190\constant{BUTTON\var{n}_CLICKED},
191\constant{BUTTON\var{n}_DOUBLE_CLICKED},
192\constant{BUTTON\var{n}_TRIPLE_CLICKED},
193\constant{BUTTON_SHIFT},
194\constant{BUTTON_CTRL},
195\constant{BUTTON_ALT}.
196\end{funcdesc}
197
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000198\begin{funcdesc}{getsyx}{}
199Returns the current coordinates of the virtual screen cursor in y and
200x. If leaveok is currently true, then -1,-1 is returned.
201\end{funcdesc}
202
203\begin{funcdesc}{getwin}{file}
204Reads window related data stored in the file by an earlier
205\function{putwin()} call. The routine then creates and initializes a
206new window using that data, returning the new window object.
207\end{funcdesc}
208
209\begin{funcdesc}{has_colors}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000210Returns true if the terminal can display colors; otherwise, it
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000211returns false.
212\end{funcdesc}
213
214\begin{funcdesc}{has_ic}{}
215Returns true if the terminal has insert- and delete- character
Eric S. Raymond68996602000-07-24 03:28:40 +0000216capabilities. This function is included for historical reasons only,
217as all modern software terminal emulators have such capabilities.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000218\end{funcdesc}
219
220\begin{funcdesc}{has_il}{}
221Returns true if the terminal has insert- and
222delete-line capabilities, or can simulate them using
Eric S. Raymond68996602000-07-24 03:28:40 +0000223scrolling regions. This function is included for historical reasons only,
224as all modern software terminal emulators have such capabilities.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000225\end{funcdesc}
226
227\begin{funcdesc}{has_key}{ch}
228Takes a key value \var{ch}, and returns true if the current terminal
229type recognizes a key with that value.
230\end{funcdesc}
231
232\begin{funcdesc}{halfdelay}{tenths}
233Used for half-delay mode, which is similar to cbreak mode in that
234characters typed by the user are immediately available to the program.
235However, after blocking for \var{tenths} tenths of seconds, an
236exception is raised if nothing has been typed. The value of
Fred Drakee412e7a2000-12-21 17:04:31 +0000237\var{tenths} must be a number between 1 and 255. Use
238\function{nocbreak()} to leave half-delay mode.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000239\end{funcdesc}
240
241\begin{funcdesc}{init_color}{color_number, r, g, b}
242Changes the definition of a color, taking the number of the color to
243be changed followed by three RGB values (for the amounts of red,
244green, and blue components). The value of \var{color_number} must be
Fred Drakee412e7a2000-12-21 17:04:31 +0000245between \code{0} and \constant{COLORS}. Each of \var{r}, \var{g},
246\var{b}, must be a value between \code{0} and \code{1000}. When
247\function{init_color()} is used, all occurrences of that color on the
248screen immediately change to the new definition. This function is a
249no-op on most terminals; it is active only if
250\function{can_change_color()} returns \code{1}.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000251\end{funcdesc}
252
253\begin{funcdesc}{init_pair}{pair_number, fg, bg}
254Changes the definition of a color-pair. It takes three arguments: the
255number of the color-pair to be changed, the foreground color number,
256and the background color number. The value of \var{pair_number} must
Fred Drakee412e7a2000-12-21 17:04:31 +0000257be between \code{1} and \code{COLOR_PAIRS - 1} (the \code{0} color
258pair is wired to white on black and cannot be changed). The value of
259\var{fg} and \var{bg} arguments must be between \code{0} and
260\constant{COLORS}. If the color-pair was previously initialized, the
261screen is refreshed and all occurrences of that color-pair are changed
262to the new definition.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000263\end{funcdesc}
264
265\begin{funcdesc}{initscr}{}
266Initialize the library. Returns a \class{WindowObject} which represents
267the whole screen.
268\end{funcdesc}
269
Fred Drakea4070ce1999-06-21 21:13:09 +0000270\begin{funcdesc}{isendwin}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000271Returns true if \function{endwin()} has been called (that is, the
272curses library has been deinitialized).
Fred Drakea4070ce1999-06-21 21:13:09 +0000273\end{funcdesc}
274
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000275\begin{funcdesc}{keyname}{k}
Eric S. Raymond68996602000-07-24 03:28:40 +0000276Return the name of the key numbered \var{k}. The name of a key
277generating printable ASCII character is the key's character. The name
278of a control-key combination is a two-character string consisting of a
279caret followed by the corresponding printable ASCII character. The
280name of an alt-key combination (128-255) is a string consisting of the
281prefix `M-' followed by the name of the corresponding ASCII character.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000282\end{funcdesc}
283
284\begin{funcdesc}{killchar}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000285Returns the user's current line kill character. Under Unix operating
286systems this is a property of the controlling tty of the curses
287program, and is not set by the curses library itself.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000288\end{funcdesc}
289
290\begin{funcdesc}{longname}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000291Returns a string containing the terminfo long name field describing the current
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000292terminal. The maximum length of a verbose description is 128
293characters. It is defined only after the call to
294\function{initscr()}.
295\end{funcdesc}
296
297\begin{funcdesc}{meta}{yes}
Eric S. Raymond68996602000-07-24 03:28:40 +0000298If \var{yes} is 1, allow 8-bit characters to be input. If \var{yes} is 0,
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000299allow only 7-bit chars.
300\end{funcdesc}
301
Andrew M. Kuchlingefc43d42000-06-30 01:05:39 +0000302\begin{funcdesc}{mouseinterval}{interval}
Thomas Woutersf8316632000-07-16 19:01:10 +0000303Sets the maximum time in milliseconds that can elapse between press and
Andrew M. Kuchlingefc43d42000-06-30 01:05:39 +0000304release events in order for them to be recognized as a click, and
305returns the previous interval value. The default value is 200 msec,
306or one fifth of a second.
307\end{funcdesc}
308
309\begin{funcdesc}{mousemask}{mousemask}
310Sets the mouse events to be reported, and returns a tuple
311\code{(\var{availmask}, \var{oldmask})}.
312\var{availmask} indicates which of the
313specified mouse events can be reported; on complete failure it returns
3140. \var{oldmask} is the previous value of the given window's mouse
315event mask. If this function is never called, no mouse events are
316ever reported.
317\end{funcdesc}
318
Andrew M. Kuchling4fb58822000-12-15 01:03:23 +0000319\begin{funcdesc}{napms}{ms}
320Sleep for \var{ms} milliseconds.
321\end{funcdesc}
322
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000323\begin{funcdesc}{newpad}{nlines, ncols}
324Creates and returns a pointer to a new pad data structure with the
325given number of lines and columns. A pad is returned as a
326window object.
327
Eric S. Raymond68996602000-07-24 03:28:40 +0000328A pad is like a window, except that it is not restricted by the screen
329size, and is not necessarily associated with a particular part of the
330screen. Pads can be used when a large window is needed, and only a
331part of the window will be on the screen at one time. Automatic
332refreshes of pads (e.g., from scrolling or echoing of input) do not
333occur. The \method{refresh()} and \method{noutrefresh()} methods of a
334pad require 6 arguments to specify the part of the pad to be
335displayed and the location on the screen to be used for the display.
336The arguments are pminrow, pmincol, sminrow, smincol, smaxrow,
337smaxcol; the p arguments refer to the upper left corner of the the pad
338region to be displayed and the s arguments define a clipping box on
339the screen within which the pad region is to be displayed.
Fred Drakea4070ce1999-06-21 21:13:09 +0000340\end{funcdesc}
341
342\begin{funcdesc}{newwin}{\optional{nlines, ncols,} begin_y, begin_x}
343Return a new window, whose left-upper corner is at
344\code{(\var{begin_y}, \var{begin_x})}, and whose height/width is
Fred Drake0bccd731999-06-23 17:28:01 +0000345\var{nlines}/\var{ncols}.
346
347By default, the window will extend from the
Fred Drakea4070ce1999-06-21 21:13:09 +0000348specified position to the lower right corner of the screen.
349\end{funcdesc}
350
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000351\begin{funcdesc}{nl}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000352Enter newline mode. This mode translates the return key into newline
353on input, and translates newline into return and line-feed on output.
354Newline mode is initially on.
Fred Drakea4070ce1999-06-21 21:13:09 +0000355\end{funcdesc}
356
357\begin{funcdesc}{nocbreak}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000358Leave cbreak mode. Return to normal ``cooked'' mode with line buffering.
Fred Drakea4070ce1999-06-21 21:13:09 +0000359\end{funcdesc}
360
Fred Drakea4070ce1999-06-21 21:13:09 +0000361\begin{funcdesc}{noecho}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000362Leave echo mode. Echoing of input characters is turned off,
Fred Drakea4070ce1999-06-21 21:13:09 +0000363\end{funcdesc}
364
Fred Drakea4070ce1999-06-21 21:13:09 +0000365\begin{funcdesc}{nonl}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000366Leave newline mode. Disable translation of return into newline on
367input, and disable low-level translation of newline into
368newline/return on output (but this does not change the behavior of
Fred Drakee1b304d2000-07-24 19:35:52 +0000369\code{addch('\e n')}, which always does the equivalent of return and
370line feed on the virtual screen). With translation off, curses can
371sometimes speed up vertical motion a little; also, it will be able to
372detect the return key on input.
Fred Drakea4070ce1999-06-21 21:13:09 +0000373\end{funcdesc}
374
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000375\begin{funcdesc}{noqiflush}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000376When the noqiflush routine is used, normal flush of input and
377output queues associated with the INTR, QUIT and SUSP
378characters will not be done. You may want to call
379\function{noqiflush()} in a signal handler if you want output
380to continue as though the interrupt had not occurred, after the
381handler exits.
Fred Drakea4070ce1999-06-21 21:13:09 +0000382\end{funcdesc}
383
384\begin{funcdesc}{noraw}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000385Leave raw mode. Return to normal ``cooked'' mode with line buffering.
Fred Drakea4070ce1999-06-21 21:13:09 +0000386\end{funcdesc}
387
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000388\begin{funcdesc}{pair_content}{pair_number}
389Returns a tuple \var{(fg,bg)} containing the colors for the requested
390color pair. The value of \var{pair_number} must be between 0 and
391COLOR_PAIRS-1.
Fred Drakea4070ce1999-06-21 21:13:09 +0000392\end{funcdesc}
393
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000394\begin{funcdesc}{pair_number}{attr}
395Returns the number of the color-pair set by the attribute value \var{attr}.
396\function{color_pair()} is the counterpart to this function.
Fred Drakea4070ce1999-06-21 21:13:09 +0000397\end{funcdesc}
398
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000399\begin{funcdesc}{putp}{string}
Eric S. Raymond68996602000-07-24 03:28:40 +0000400Equivalent to \code{tputs(str, 1, putchar)}; emits the value of a
401specified terminfo capability for the current terminal. Note that the
402output of putp always goes to standard output.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000403\end{funcdesc}
404
405\begin{funcdesc}{qiflush}{ \optional{flag} }
406If \var{flag} is false, the effect is the same as calling
407\function{noqiflush()}. If \var{flag} is true, or no argument is
408provided, the queues will be flushed when these control characters are
409read.
410\end{funcdesc}
411
412\begin{funcdesc}{raw}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000413Enter raw mode. In raw mode, normal line buffering and
414processing of interrupt, quit, suspend, and flow control keys are
415turned off; characters are presented to curses input functions one
416by one.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000417\end{funcdesc}
418
419\begin{funcdesc}{reset_prog_mode}{}
420Restores the terminal to ``program'' mode, as previously saved
421by \function{def_prog_mode()}.
422\end{funcdesc}
423
424\begin{funcdesc}{reset_shell_mode}{}
425Restores the terminal to ``shell'' mode, as previously saved
426by \function{def_shell_mode()}.
427\end{funcdesc}
428
429\begin{funcdesc}{setsyx}{y, x}
430Sets the virtual screen cursor to \var{y}, \var{x}.
431If \var{y} and \var{x} are both -1, then leaveok is set.
432\end{funcdesc}
433
Andrew M. Kuchling620ec9d2000-11-18 17:57:33 +0000434\begin{funcdesc}{setupterm}{\optional{termstr, fd}}
435Initializes the terminal. \var{termstr} is a string giving the
436terminal name; if omitted, the value of the TERM environment variable
Fred Drakee412e7a2000-12-21 17:04:31 +0000437will be used. \var{fd} is the file descriptor to which any
438initialization sequences will be sent; if not supplied, the file
439descriptor for \code{sys.stdout} will be used.
Andrew M. Kuchling620ec9d2000-11-18 17:57:33 +0000440\end{funcdesc}
441
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000442\begin{funcdesc}{start_color}{}
443Must be called if the programmer wants to use colors, and before any
444other color manipulation routine is called. It is good
445practice to call this routine right after \function{initscr()}.
446
447\function{start_color()} initializes eight basic colors (black, red,
448green, yellow, blue, magenta, cyan, and white), and two global
Fred Drakee412e7a2000-12-21 17:04:31 +0000449variables in the \module{curses} module, \constant{COLORS} and
450\constant{COLOR_PAIRS}, containing the maximum number of colors and
451color-pairs the terminal can support. It also restores the colors on
452the terminal to the values they had when the terminal was just turned
453on.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000454\end{funcdesc}
455
456\begin{funcdesc}{termattrs}{}
457Returns a logical OR of all video attributes supported by the
458terminal. This information is useful when a curses program needs
459complete control over the appearance of the screen.
460\end{funcdesc}
461
462\begin{funcdesc}{termname}{}
463Returns the value of the environment variable TERM, truncated to 14
464characters.
465\end{funcdesc}
466
Andrew M. Kuchling1962fb52000-07-26 02:59:13 +0000467\begin{funcdesc}{tigetflag}{capname}
468Returns the value of the Boolean capability corresponding to the
Fred Drakee412e7a2000-12-21 17:04:31 +0000469terminfo capability name \var{capname}. The value \code{-1} is
470returned if \var{capname} is not a Boolean capability, or \code{0} if
471it is canceled or absent from the terminal description.
Andrew M. Kuchling1962fb52000-07-26 02:59:13 +0000472\end{funcdesc}
473
474\begin{funcdesc}{tigetnum}{capname}
475Returns the value of the numeric capability corresponding to the
Fred Drakee412e7a2000-12-21 17:04:31 +0000476terminfo capability name \var{capname}. The value \code{-2} is
477returned if \var{capname} is not a numeric capability, or \code{-1} if
478it is canceled or absent from the terminal description.
Andrew M. Kuchling1962fb52000-07-26 02:59:13 +0000479\end{funcdesc}
480
481\begin{funcdesc}{tigetstr}{capname}
482Returns the value of the string capability corresponding to the
483terminfo capability name \var{capname}. \code{None} is returned if
484\var{capname} is not a string capability, or is canceled or absent
485from the terminal description.
486\end{funcdesc}
487
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +0000488\begin{funcdesc}{tparm}{str\optional{,...}}
489Instantiates the string \var{str} with the supplied parameters, where
490\var{str} should be a parameterized string obtained from the terminfo
Fred Drakee412e7a2000-12-21 17:04:31 +0000491database. E.g. \code{tparm(tigetstr("cup"), 5, 3)} could result in
492\code{'\e{}033[6;4H'}, the exact result depending on terminal type.
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +0000493\end{funcdesc}
494
Andrew M. Kuchlingd24ff442000-06-21 01:42:51 +0000495\begin{funcdesc}{typeahead}{fd}
496Specifies that the file descriptor \var{fd} be used for typeahead
Fred Drakee412e7a2000-12-21 17:04:31 +0000497checking. If \var{fd} is \code{-1}, then no typeahead checking is
498done.
Andrew M. Kuchlingd24ff442000-06-21 01:42:51 +0000499
500The curses library does ``line-breakout optimization'' by looking for
501typeahead periodically while updating the screen. If input is found,
502and it is coming from a tty, the current update is postponed until
503refresh or doupdate is called again, allowing faster response to
504commands typed in advance. This function allows specifying a different
505file descriptor for typeahead checking.
506\end{funcdesc}
507
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000508\begin{funcdesc}{unctrl}{ch}
509Returns a string which is a printable representation of the character
510\var{ch}. Control characters are displayed as a caret followed by the
511character, for example as \verb|^C|. Printing characters are left as they
512are.
513\end{funcdesc}
514
515\begin{funcdesc}{ungetch}{ch}
516Push \var{ch} so the next \method{getch()} will return it.
517\strong{Note:} only one \var{ch} can be pushed before \method{getch()}
518is called.
519\end{funcdesc}
520
Andrew M. Kuchlingefc43d42000-06-30 01:05:39 +0000521\begin{funcdesc}{ungetmouse}{id, x, y, z, bstate}
522Push a \constant{KEY_MOUSE} event onto the input queue, associating
523the given state data with it.
524\end{funcdesc}
525
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000526\begin{funcdesc}{use_env}{flag}
Fred Drakee412e7a2000-12-21 17:04:31 +0000527If used, this function should be called before \function{initscr()} or
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000528newterm are called. When \var{flag} is false, the values of
529lines and columns specified in the terminfo database will be
Fred Drakee412e7a2000-12-21 17:04:31 +0000530used, even if environment variables \envvar{LINES} and
531\envvar{COLUMNS} (used by default) are set, or if curses is running in
532a window (in which case default behavior would be to use the window
533size if \envvar{LINES} and \envvar{COLUMNS} are not set).
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000534\end{funcdesc}
Fred Drakea4070ce1999-06-21 21:13:09 +0000535
536\subsection{Window Objects \label{curses-window-objects}}
537
538Window objects, as returned by \function{initscr()} and
539\function{newwin()} above, have the
540following methods:
541
Fred Drakea4070ce1999-06-21 21:13:09 +0000542\begin{methoddesc}{addch}{\optional{y, x,} ch\optional{, attr}}
543\strong{Note:} A \emph{character} means a C character (i.e., an
544\ASCII{} code), rather then a Python character (a string of length 1).
545(This note is true whenever the documentation mentions a character.)
Eric S. Raymond68996602000-07-24 03:28:40 +0000546The builtin \function{ord()} is handy for conveying strings to codes.
Fred Drakea4070ce1999-06-21 21:13:09 +0000547
548Paint character \var{ch} at \code{(\var{y}, \var{x})} with attributes
549\var{attr}, overwriting any character previously painter at that
550location. By default, the character position and attributes are the
551current settings for the window object.
552\end{methoddesc}
553
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000554\begin{methoddesc}{addnstr}{\optional{y, x,} str, n\optional{, attr}}
555Paint at most \var{n} characters of the
556string \var{str} at \code{(\var{y}, \var{x})} with attributes
Fred Drake0bccd731999-06-23 17:28:01 +0000557\var{attr}, overwriting anything previously on the display.
Fred Drakea4070ce1999-06-21 21:13:09 +0000558\end{methoddesc}
559
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000560\begin{methoddesc}{addstr}{\optional{y, x,} str\optional{, attr}}
561Paint the string \var{str} at \code{(\var{y}, \var{x})} with attributes
562\var{attr}, overwriting anything previously on the display.
Fred Drakea4070ce1999-06-21 21:13:09 +0000563\end{methoddesc}
564
565\begin{methoddesc}{attroff}{attr}
Eric S. Raymond68996602000-07-24 03:28:40 +0000566Remove attribute \var{attr} from the ``background'' set applied to all
567writes to the current window.
Fred Drakea4070ce1999-06-21 21:13:09 +0000568\end{methoddesc}
569
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000570\begin{methoddesc}{attron}{attr}
Eric S. Raymond68996602000-07-24 03:28:40 +0000571Add attribute \var{attr} from the ``background'' set applied to all
572writes to the current window.
Fred Drakea4070ce1999-06-21 21:13:09 +0000573\end{methoddesc}
574
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000575\begin{methoddesc}{attrset}{attr}
Eric S. Raymond68996602000-07-24 03:28:40 +0000576Set the ``background'' set of attributes to \var{attr}. This set is
577initially 0 (no attributes).
Fred Drakea4070ce1999-06-21 21:13:09 +0000578\end{methoddesc}
579
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000580\begin{methoddesc}{bkgd}{ch\optional{, attr}}
581Sets the background property of the window to the character \var{ch},
582with attributes \var{attr}. The change is then applied to every
583character position in that window:
584\begin{itemize}
Eric S. Raymondb924bd42000-07-27 21:10:02 +0000585\item
586The attribute of every character in the window is
587changed to the new background attribute.
588\item
589Wherever the former background character appears,
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000590it is changed to the new background character.
591\end{itemize}
592
593\end{methoddesc}
594
595\begin{methoddesc}{bkgdset}{ch\optional{, attr}}
596Sets the window's background. A window's background consists of a
597character and any combination of attributes. The attribute part of
598the background is combined (OR'ed) with all non-blank characters that
599are written into the window. Both the character and attribute parts
600of the background are combined with the blank characters. The
601background becomes a property of the character and moves with the
602character through any scrolling and insert/delete line/character
603operations.
Fred Drakea4070ce1999-06-21 21:13:09 +0000604\end{methoddesc}
605
Fred Drake0bccd731999-06-23 17:28:01 +0000606\begin{methoddesc}{border}{\optional{ls\optional{, rs\optional{, ts\optional{,
607 bs\optional{, tl\optional{, tr\optional{,
608 bl\optional{, br}}}}}}}}}
609Draw a border around the edges of the window. Each parameter specifies
610the character to use for a specific part of the border; see the table
611below for more details. The characters must be specified as integers;
612using one-character strings will cause \exception{TypeError} to be
613raised.
614
615\strong{Note:} A \code{0} value for any parameter will cause the
616default character to be used for that parameter. Keyword parameters
617can \emph{not} be used. The defaults are listed in this table:
618
619\begin{tableiii}{l|l|l}{var}{Parameter}{Description}{Default value}
620 \lineiii{ls}{Left side}{\constant{ACS_VLINE}}
621 \lineiii{rs}{Right side}{\constant{ACS_VLINE}}
622 \lineiii{ts}{Top}{\constant{ACS_HLINE}}
623 \lineiii{bs}{Bottom}{\constant{ACS_HLINE}}
624 \lineiii{tl}{Upper-left corner}{\constant{ACS_ULCORNER}}
625 \lineiii{tr}{Upper-right corner}{\constant{ACS_URCORNER}}
626 \lineiii{bl}{Bottom-left corner}{\constant{ACS_BLCORNER}}
627 \lineiii{br}{Bottom-right corner}{\constant{ACS_BRCORNER}}
628\end{tableiii}
Fred Drakea4070ce1999-06-21 21:13:09 +0000629\end{methoddesc}
630
Fred Drake0bccd731999-06-23 17:28:01 +0000631\begin{methoddesc}{box}{\optional{vertch, horch}}
632Similar to \method{border()}, but both \var{ls} and \var{rs} are
633\var{vertch} and both \var{ts} and {bs} are \var{horch}. The default
634corner characters are always used by this function.
Fred Drakea4070ce1999-06-21 21:13:09 +0000635\end{methoddesc}
636
Fred Drakea4070ce1999-06-21 21:13:09 +0000637\begin{methoddesc}{clear}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000638Like \method{erase()}, but also causes the whole window to be repainted
Fred Drakea4070ce1999-06-21 21:13:09 +0000639upon next call to \method{refresh()}.
640\end{methoddesc}
641
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000642\begin{methoddesc}{clearok}{yes}
643If \var{yes} is 1, the next call to \method{refresh()}
Eric S. Raymond68996602000-07-24 03:28:40 +0000644will clear the window completely.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000645\end{methoddesc}
646
Fred Drakea4070ce1999-06-21 21:13:09 +0000647\begin{methoddesc}{clrtobot}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000648Erase from cursor to the end of the window: all lines below the cursor
Fred Drakea4070ce1999-06-21 21:13:09 +0000649are deleted, and then the equivalent of \method{clrtoeol()} is performed.
650\end{methoddesc}
651
652\begin{methoddesc}{clrtoeol}{}
653Erase from cursor to the end of the line.
654\end{methoddesc}
655
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000656\begin{methoddesc}{cursyncup}{}
657Updates the current cursor position of all the ancestors of the window
658to reflect the current cursor position of the window.
Fred Drakea4070ce1999-06-21 21:13:09 +0000659\end{methoddesc}
660
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000661\begin{methoddesc}{delch}{\optional{x, y}}
662Delete any character at \code{(\var{y}, \var{x})}.
Fred Drakea4070ce1999-06-21 21:13:09 +0000663\end{methoddesc}
664
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000665\begin{methoddesc}{deleteln}{}
666Delete the line under the cursor. All following lines are moved up
667by 1 line.
668\end{methoddesc}
669
670\begin{methoddesc}{derwin}{\optional{nlines, ncols,} begin_y, begin_y}
671An abbreviation for ``derive window'', \method{derwin()} is the same
672as calling \method{subwin()}, except that \var{begin_y} and
673\var{begin_x} are relative to the origin of the window, rather than
674relative to the entire screen. Returns a window object for the
675derived window.
676\end{methoddesc}
677
678\begin{methoddesc}{echochar}{ch\optional{, attr}}
679Add character \var{ch} with attribute \var{attr}, and immediately
Fred Drakee412e7a2000-12-21 17:04:31 +0000680call \method{refresh()} on the window.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000681\end{methoddesc}
682
Andrew M. Kuchlingefc43d42000-06-30 01:05:39 +0000683\begin{methoddesc}{enclose}{y, x}
684Tests whether the given pair of screen-relative character-cell
685coordinates are enclosed by the given window, returning true or
686false. It is useful for determining what subset of the screen
687windows enclose the location of a mouse event.
688\end{methoddesc}
689
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000690\begin{methoddesc}{erase}{}
691Clear the window.
692\end{methoddesc}
693
694\begin{methoddesc}{getbegyx}{}
695Return a tuple \code{(\var{y}, \var{x})} of co-ordinates of upper-left
696corner.
Fred Drakea4070ce1999-06-21 21:13:09 +0000697\end{methoddesc}
698
699\begin{methoddesc}{getch}{\optional{x, y}}
700Get a character. Note that the integer returned does \emph{not} have to
701be in \ASCII{} range: function keys, keypad keys and so on return numbers
Fred Drakee412e7a2000-12-21 17:04:31 +0000702higher than 256. In no-delay mode, an exception is raised if there is
Fred Drakea4070ce1999-06-21 21:13:09 +0000703no input.
704\end{methoddesc}
705
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000706\begin{methoddesc}{getkey}{\optional{x, y}}
707Get a character, returning a string instead of an integer, as
708\method{getch()} does. Function keys, keypad keys and so on return a
709multibyte string containing the key name. In no-delay mode, an
710exception is raised if there is no input.
711\end{methoddesc}
712
713\begin{methoddesc}{getmaxyx}{}
714Return a tuple \code{(\var{y}, \var{x})} of the height and width of
715the window.
716\end{methoddesc}
717
718\begin{methoddesc}{getparyx}{}
719Returns the beginning coordinates of this window relative to its
720parent window into two integer variables y and x. Returns
721\code{-1,-1} if this window has no parent.
722\end{methoddesc}
723
Fred Drakea4070ce1999-06-21 21:13:09 +0000724\begin{methoddesc}{getstr}{\optional{x, y}}
725Read a string from the user, with primitive line editing capacity.
726\end{methoddesc}
727
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000728\begin{methoddesc}{getyx}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000729Return a tuple \code{(\var{y}, \var{x})} of current cursor position
730relative to the window's upper-left corner.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000731\end{methoddesc}
732
733\begin{methoddesc}{hline}{\optional{y, x,} ch, n}
734Display a horizontal line starting at \code{(\var{y}, \var{x})} with
735length \var{n} consisting of the character \var{ch}.
736\end{methoddesc}
737
738\begin{methoddesc}{idcok}{flag}
739If \var{flag} is false, curses no longer considers using the hardware
740insert/delete character feature of the terminal; if \var{flag} is
741true, use of character insertion and deletion is enabled. When curses
742is first initialized, use of character insert/delete is enabled by
743default.
744\end{methoddesc}
745
746\begin{methoddesc}{idlok}{yes}
747If called with \var{yes} equal to 1, \module{curses} will try and use
748hardware line editing facilities. Otherwise, line insertion/deletion
749are disabled.
750\end{methoddesc}
751
752\begin{methoddesc}{immedok}{flag}
753If \var{flag} is true, any change in the window image
754automatically causes the window to be refreshed; you no longer
755have to call \method{refresh()} yourself. However, it may
756degrade performance considerably, due to repeated calls to
757wrefresh. This option is disabled by default.
758\end{methoddesc}
759
Fred Drakea4070ce1999-06-21 21:13:09 +0000760\begin{methoddesc}{inch}{\optional{x, y}}
761Return the character at the given position in the window. The bottom
7628 bits are the character proper, and upper bits are the attributes.
763\end{methoddesc}
764
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000765\begin{methoddesc}{insch}{\optional{y, x,} ch\optional{, attr}}
766Paint character \var{ch} at \code{(\var{y}, \var{x})} with attributes
767\var{attr}, moving the line from position \var{x} right by one
768character.
Fred Drakea4070ce1999-06-21 21:13:09 +0000769\end{methoddesc}
770
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000771\begin{methoddesc}{insdelln}{nlines}
772Inserts \var{nlines} lines into the specified window above the current
773line. The \var{nlines} bottom lines are lost. For negative
774\var{nlines}, delete \var{nlines} lines starting with the one under
775the cursor, and move the remaining lines up. The bottom \var{nlines}
776lines are cleared. The current cursor position remains the same.
777\end{methoddesc}
778
779\begin{methoddesc}{insertln}{}
780Insert a blank line under the cursor. All following lines are moved
781down by 1 line.
782\end{methoddesc}
783
784\begin{methoddesc}{insnstr}{\optional{y, x, } str, n \optional{, attr}}
785Insert a character string (as many characters as will fit on the line)
786before the character under the cursor, up to \var{n} characters.
787If \var{n} is zero or negative,
788the entire string is inserted.
789All characters to the right of
790the cursor are shifted right, with the the rightmost characters on the
791line being lost. The cursor position does not change (after moving to
792\var{y}, \var{x}, if specified).
793\end{methoddesc}
794
795\begin{methoddesc}{insstr}{\optional{y, x, } str \optional{, attr}}
796Insert a character string (as many characters as will fit on the line)
797before the character under the cursor. All characters to the right of
798the cursor are shifted right, with the the rightmost characters on the
799line being lost. The cursor position does not change (after moving to
800\var{y}, \var{x}, if specified).
801\end{methoddesc}
802
803\begin{methoddesc}{instr}{\optional{y, x} \optional{, n}}
804Returns a string of characters, extracted from the window starting at
805the current cursor position, or at \var{y}, \var{x} if specified.
806Attributes are stripped from the characters. If \var{n} is specified,
807\method{instr()} returns return a string at most \var{n} characters
808long (exclusive of the trailing NUL).
809\end{methoddesc}
810
811\begin{methoddesc}{is_linetouched}{\var{line}}
812Returns true if the specified line was modified since the last call to
813\method{refresh()}; otherwise returns false. Raises a
814\exception{curses.error} exception if \var{line} is not valid
815for the given window.
816\end{methoddesc}
817
818\begin{methoddesc}{is_wintouched}{}
819Returns true if the specified window was modified since the last call to
820\method{refresh()}; otherwise returns false.
821\end{methoddesc}
822
823\begin{methoddesc}{keypad}{yes}
824If \var{yes} is 1, escape sequences generated by some keys (keypad,
825function keys) will be interpreted by \module{curses}.
826If \var{yes} is 0, escape sequences will be left as is in the input
827stream.
Fred Drakea4070ce1999-06-21 21:13:09 +0000828\end{methoddesc}
829
830\begin{methoddesc}{leaveok}{yes}
Eric S. Raymond68996602000-07-24 03:28:40 +0000831If \var{yes} is 1, cursor is left where it is on update, instead of
832being at ``cursor position.'' This reduces cursor movement where
833possible. If possible the cursor will be made invisible.
Fred Drakea4070ce1999-06-21 21:13:09 +0000834
Eric S. Raymond68996602000-07-24 03:28:40 +0000835If \var{yes} is 0, cursor will always be at ``cursor position'' after
836an update.
Fred Drakea4070ce1999-06-21 21:13:09 +0000837\end{methoddesc}
838
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000839\begin{methoddesc}{move}{new_y, new_x}
840Move cursor to \code{(\var{new_y}, \var{new_x})}.
Fred Drakea4070ce1999-06-21 21:13:09 +0000841\end{methoddesc}
842
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000843\begin{methoddesc}{mvderwin}{y, x}
844Moves the window inside its parent window. The screen-relative
845parameters of the window are not changed. This routine is used to
846display different parts of the parent window at the same physical
847position on the screen.
848\end{methoddesc}
Fred Drakea4070ce1999-06-21 21:13:09 +0000849
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000850\begin{methoddesc}{mvwin}{new_y, new_x}
Fred Drakee412e7a2000-12-21 17:04:31 +0000851Move the window so its upper-left corner is at
852\code{(\var{new_y}, \var{new_x})}.
Fred Drakea4070ce1999-06-21 21:13:09 +0000853\end{methoddesc}
854
855\begin{methoddesc}{nodelay}{yes}
Fred Drakee412e7a2000-12-21 17:04:31 +0000856If \var{yes} is \code{1}, \method{getch()} will be non-blocking.
Fred Drakea4070ce1999-06-21 21:13:09 +0000857\end{methoddesc}
858
859\begin{methoddesc}{notimeout}{yes}
Fred Drakee412e7a2000-12-21 17:04:31 +0000860If \var{yes} is \code{1}, escape sequences will not be timed out.
Fred Drakea4070ce1999-06-21 21:13:09 +0000861
Fred Drakee412e7a2000-12-21 17:04:31 +0000862If \var{yes} is \code{0}, after a few milliseconds, an escape sequence
863will not be interpreted, and will be left in the input stream as is.
Fred Drakea4070ce1999-06-21 21:13:09 +0000864\end{methoddesc}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000865
866\begin{methoddesc}{noutrefresh}{}
Eric S. Raymond65983372000-08-09 21:49:31 +0000867Mark for refresh but wait. This function updates the data structure
868representing the desired state of the window, but does not force
869an update of the physical screen.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000870\end{methoddesc}
871
Andrew M. Kuchling68a6f5a2000-12-21 16:25:44 +0000872\begin{methoddesc}{overlay}{destwin\optional{, sminrow, smincol,
Fred Drakee412e7a2000-12-21 17:04:31 +0000873 dminrow, dmincol, dmaxrow, dmaxcol}}
Andrew M. Kuchling68a6f5a2000-12-21 16:25:44 +0000874Overlay the window on top of \var{destwin}. The windows need not be
875the same size, only the overlapping region is copied. This copy is
876non-destructive, which means that the current background character
877does not overwrite the old contents of \var{destwin}.
878
879To get fine-grained control over the copied region, the second form
Fred Drakee412e7a2000-12-21 17:04:31 +0000880of \method{overlay()} can be used. \var{sminrow} and \var{smincol} are
Andrew M. Kuchling68a6f5a2000-12-21 16:25:44 +0000881the upper-left coordinates of the source window, and the other variables
882mark a rectangle in the destination window.
883\end{methoddesc}
884
885\begin{methoddesc}{overwrite}{destwin\optional{, sminrow, smincol,
Fred Drakee412e7a2000-12-21 17:04:31 +0000886 dminrow, dmincol, dmaxrow, dmaxcol}}
Andrew M. Kuchling68a6f5a2000-12-21 16:25:44 +0000887Overwrite the window on top of \var{destwin}. The windows need not be
Fred Drakee412e7a2000-12-21 17:04:31 +0000888the same size, in which case only the overlapping region is
889copied. This copy is destructive, which means that the current
890background character overwrites the old contents of \var{destwin}.
Andrew M. Kuchling68a6f5a2000-12-21 16:25:44 +0000891
892To get fine-grained control over the copied region, the second form
Fred Drakee412e7a2000-12-21 17:04:31 +0000893of \method{overwrite()} can be used. \var{sminrow} and \var{smincol} are
Andrew M. Kuchling68a6f5a2000-12-21 16:25:44 +0000894the upper-left coordinates of the source window, the other variables
895mark a rectangle in the destination window.
896\end{methoddesc}
897
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000898\begin{methoddesc}{putwin}{file}
899Writes all data associated with the window into the provided file
900object. This information can be later retrieved using the
901\function{getwin()} function.
902
903\end{methoddesc}
904
905\begin{methoddesc}{redrawln}{beg, num}
906Indicates that the \var{num} screen lines, starting at line \var{beg},
907are corrupted and should be completely redrawn on the next
908\method{refresh()} call.
909\end{methoddesc}
910
911\begin{methoddesc}{redrawwin}{}
912Touches the entire window, causing it to be completely redrawn on the
913next \method{refresh()} call.
914\end{methoddesc}
915
Fred Drakee412e7a2000-12-21 17:04:31 +0000916\begin{methoddesc}{refresh}{\optional{pminrow, pmincol, sminrow,
917 smincol, smaxrow, smaxcol}}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000918Update the display immediately (sync actual screen with previous
919drawing/deleting methods).
920
921The 6 optional arguments can only be specified when the window is a
922pad created with \function{newpad()}. The additional parameters are
923needed to indicate what part of the pad and screen are involved.
924\var{pminrow} and \var{pmincol} specify the upper left-hand corner of the
925rectangle to be displayed in the pad. \var{sminrow}, \var{smincol},
Fred Drakee412e7a2000-12-21 17:04:31 +0000926\var{smaxrow}, and \var{smaxcol} specify the edges of the rectangle to
927be displayed on the screen. The lower right-hand corner of the
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000928rectangle to be displayed in the pad is calculated from the screen
929coordinates, since the rectangles must be the same size. Both
930rectangles must be entirely contained within their respective
931structures. Negative values of \var{pminrow}, \var{pmincol},
932\var{sminrow}, or \var{smincol} are treated as if they were zero.
933\end{methoddesc}
934
935\begin{methoddesc}{scroll}{\optional{lines\code{ = 1}}}
936Scroll the screen upward by \var{lines} lines.
937\end{methoddesc}
938
939\begin{methoddesc}{scrollok}{flag}
940Controls what happens when the cursor of a window is moved off the
Eric S. Raymond68996602000-07-24 03:28:40 +0000941edge of the window or scrolling region, either as a result of a
942newline action on the bottom line, or typing the last character
943of the last line. If \var{flag} is false, the cursor is left
944on the bottom line. If \var{flag} is true, the window is
945scrolled up one line. Note that in order to get the physical
946scrolling effect on the terminal, it is also necessary to call
947\method{idlok()}.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000948\end{methoddesc}
949
950\begin{methoddesc}{setscrreg}{top, bottom}
951Set the scrolling region from line \var{top} to line \var{bottom}. All
952scrolling actions will take place in this region.
953\end{methoddesc}
954
955\begin{methoddesc}{standend}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000956Turn off the standout attribute. On some terminals this has the
957side effect of turning off all attributes.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000958\end{methoddesc}
959
960\begin{methoddesc}{standout}{}
961Turn on attribute \var{A_STANDOUT}.
962\end{methoddesc}
963
964\begin{methoddesc}{subpad}{\optional{nlines, ncols,} begin_y, begin_y}
965Return a sub-window, whose upper-left corner is at
966\code{(\var{begin_y}, \var{begin_x})}, and whose width/height is
967\var{ncols}/\var{nlines}.
968\end{methoddesc}
969
970\begin{methoddesc}{subwin}{\optional{nlines, ncols,} begin_y, begin_y}
971Return a sub-window, whose upper-left corner is at
972\code{(\var{begin_y}, \var{begin_x})}, and whose width/height is
973\var{ncols}/\var{nlines}.
974
975By default, the sub-window will extend from the
976specified position to the lower right corner of the window.
977\end{methoddesc}
978
979\begin{methoddesc}{syncdown}{}
980Touches each location in the window that has been touched in any of
981its ancestor windows. This routine is called by \method{refresh()},
982so it should almost never be necessary to call it manually.
983\end{methoddesc}
984
985\begin{methoddesc}{syncok}{flag}
986If called with \var{flag} set to true, then \method{syncup()} is
987called automatically whenever there is a change in the window.
988\end{methoddesc}
989
990\begin{methoddesc}{syncup}{}
991Touches all locations in ancestors of the window that have been changed in
992the window.
993\end{methoddesc}
994
Andrew M. Kuchlingd24ff442000-06-21 01:42:51 +0000995\begin{methoddesc}{timeout}{delay}
Thomas Woutersf8316632000-07-16 19:01:10 +0000996Sets blocking or non-blocking read behavior for the window. If
Andrew M. Kuchlingd24ff442000-06-21 01:42:51 +0000997\var{delay} is negative, blocking read is used, which will wait
998indefinitely for input). If \var{delay} is zero, then non-blocking
999read is used, and -1 will be returned by \method{getch()} if no input
1000is waiting. If \var{delay} is positive, then \method{getch()} will
1001block for \var{delay} milliseconds, and return -1 if there is still no
1002input at the end of that time.
1003\end{methoddesc}
1004
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001005\begin{methoddesc}{touchline}{start, count}
1006Pretend \var{count} lines have been changed, starting with line
1007\var{start}.
1008\end{methoddesc}
1009
1010\begin{methoddesc}{touchwin}{}
1011Pretend the whole window has been changed, for purposes of drawing
1012optimizations.
1013\end{methoddesc}
1014
1015\begin{methoddesc}{untouchwin}{}
1016Marks all lines in the window as unchanged since the last call to
1017\method{refresh()}.
1018\end{methoddesc}
1019
1020\begin{methoddesc}{vline}{\optional{y, x,} ch, n}
1021Display a vertical line starting at \code{(\var{y}, \var{x})} with
1022length \var{n} consisting of the character \var{ch}.
1023\end{methoddesc}
1024
1025\subsection{Constants}
1026
1027The \module{curses} module defines the following data members:
1028
Andrew M. Kuchlinge6bf8582000-12-26 15:58:27 +00001029\begin{datadesc}{ERR}
1030Some curses routines that return an integer, such as
Fred Drake22e9a5e2001-01-04 05:14:45 +00001031\function{getch()}, return \constant{ERR} upon failure.
Andrew M. Kuchlinge6bf8582000-12-26 15:58:27 +00001032\end{datadesc}
1033
1034\begin{datadesc}{OK}
1035Some curses routines that return an integer, such as
Fred Drake22e9a5e2001-01-04 05:14:45 +00001036\function{napms()}, return \constant{OK} upon success.
Andrew M. Kuchlinge6bf8582000-12-26 15:58:27 +00001037\end{datadesc}
1038
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001039\begin{datadesc}{version}
1040A string representing the current version of the module.
1041Also available as \constant{__version__}.
1042\end{datadesc}
1043
Fred Drakeec4b2af2000-08-09 14:34:48 +00001044Several constants are available to specify character cell attributes:
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001045
Fred Drakeec4b2af2000-08-09 14:34:48 +00001046\begin{tableii}{l|l}{code}{Attribute}{Meaning}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001047 \lineii{A_ALTCHARSET}{Alternate character set mode.}
1048 \lineii{A_BLINK}{Blink mode.}
1049 \lineii{A_BOLD}{Bold mode.}
1050 \lineii{A_DIM}{Dim mode.}
1051 \lineii{A_NORMAL}{Normal attribute.}
1052 \lineii{A_STANDOUT}{Standout mode.}
1053 \lineii{A_UNDERLINE}{Underline mode.}
1054\end{tableii}
1055
1056Keys are referred to by integer constants with names starting with
Fred Drakeec4b2af2000-08-09 14:34:48 +00001057\samp{KEY_}. The exact keycaps available are system dependent.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001058
1059% XXX this table is far too large!
1060% XXX should this table be alphabetized?
1061
Fred Drake1bf4e932000-09-21 16:04:08 +00001062\begin{longtableii}{l|l}{code}{Key constant}{Key}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001063 \lineii{KEY_MIN}{Minimum key value}
1064 \lineii{KEY_BREAK}{ Break key (unreliable) }
1065 \lineii{KEY_DOWN}{ Down-arrow }
1066 \lineii{KEY_UP}{ Up-arrow }
1067 \lineii{KEY_LEFT}{ Left-arrow }
1068 \lineii{KEY_RIGHT}{ Right-arrow }
1069 \lineii{KEY_HOME}{ Home key (upward+left arrow) }
1070 \lineii{KEY_BACKSPACE}{ Backspace (unreliable) }
1071 \lineii{KEY_F0}{ Function keys. Up to 64 function keys are supported. }
1072 \lineii{KEY_F\var{n}}{ Value of function key \var{n} }
1073 \lineii{KEY_DL}{ Delete line }
1074 \lineii{KEY_IL}{ Insert line }
1075 \lineii{KEY_DC}{ Delete character }
1076 \lineii{KEY_IC}{ Insert char or enter insert mode }
1077 \lineii{KEY_EIC}{ Exit insert char mode }
1078 \lineii{KEY_CLEAR}{ Clear screen }
1079 \lineii{KEY_EOS}{ Clear to end of screen }
1080 \lineii{KEY_EOL}{ Clear to end of line }
1081 \lineii{KEY_SF}{ Scroll 1 line forward }
1082 \lineii{KEY_SR}{ Scroll 1 line backward (reverse) }
1083 \lineii{KEY_NPAGE}{ Next page }
1084 \lineii{KEY_PPAGE}{ Previous page }
1085 \lineii{KEY_STAB}{ Set tab }
1086 \lineii{KEY_CTAB}{ Clear tab }
1087 \lineii{KEY_CATAB}{ Clear all tabs }
1088 \lineii{KEY_ENTER}{ Enter or send (unreliable) }
1089 \lineii{KEY_SRESET}{ Soft (partial) reset (unreliable) }
1090 \lineii{KEY_RESET}{ Reset or hard reset (unreliable) }
1091 \lineii{KEY_PRINT}{ Print }
1092 \lineii{KEY_LL}{ Home down or bottom (lower left) }
1093 \lineii{KEY_A1}{ Upper left of keypad }
1094 \lineii{KEY_A3}{ Upper right of keypad }
1095 \lineii{KEY_B2}{ Center of keypad }
1096 \lineii{KEY_C1}{ Lower left of keypad }
1097 \lineii{KEY_C3}{ Lower right of keypad }
1098 \lineii{KEY_BTAB}{ Back tab }
1099 \lineii{KEY_BEG}{ Beg (beginning) }
1100 \lineii{KEY_CANCEL}{ Cancel }
1101 \lineii{KEY_CLOSE}{ Close }
1102 \lineii{KEY_COMMAND}{ Cmd (command) }
1103 \lineii{KEY_COPY}{ Copy }
1104 \lineii{KEY_CREATE}{ Create }
1105 \lineii{KEY_END}{ End }
1106 \lineii{KEY_EXIT}{ Exit }
1107 \lineii{KEY_FIND}{ Find }
1108 \lineii{KEY_HELP}{ Help }
1109 \lineii{KEY_MARK}{ Mark }
1110 \lineii{KEY_MESSAGE}{ Message }
1111 \lineii{KEY_MOVE}{ Move }
1112 \lineii{KEY_NEXT}{ Next }
1113 \lineii{KEY_OPEN}{ Open }
1114 \lineii{KEY_OPTIONS}{ Options }
1115 \lineii{KEY_PREVIOUS}{ Prev (previous) }
1116 \lineii{KEY_REDO}{ Redo }
1117 \lineii{KEY_REFERENCE}{ Ref (reference) }
1118 \lineii{KEY_REFRESH}{ Refresh }
1119 \lineii{KEY_REPLACE}{ Replace }
1120 \lineii{KEY_RESTART}{ Restart }
1121 \lineii{KEY_RESUME}{ Resume }
1122 \lineii{KEY_SAVE}{ Save }
1123 \lineii{KEY_SBEG}{ Shifted Beg (beginning) }
1124 \lineii{KEY_SCANCEL}{ Shifted Cancel }
1125 \lineii{KEY_SCOMMAND}{ Shifted Command }
1126 \lineii{KEY_SCOPY}{ Shifted Copy }
1127 \lineii{KEY_SCREATE}{ Shifted Create }
1128 \lineii{KEY_SDC}{ Shifted Delete char }
1129 \lineii{KEY_SDL}{ Shifted Delete line }
1130 \lineii{KEY_SELECT}{ Select }
1131 \lineii{KEY_SEND}{ Shifted End }
1132 \lineii{KEY_SEOL}{ Shifted Clear line }
1133 \lineii{KEY_SEXIT}{ Shifted Dxit }
1134 \lineii{KEY_SFIND}{ Shifted Find }
1135 \lineii{KEY_SHELP}{ Shifted Help }
1136 \lineii{KEY_SHOME}{ Shifted Home }
1137 \lineii{KEY_SIC}{ Shifted Input }
1138 \lineii{KEY_SLEFT}{ Shifted Left arrow }
1139 \lineii{KEY_SMESSAGE}{ Shifted Message }
1140 \lineii{KEY_SMOVE}{ Shifted Move }
1141 \lineii{KEY_SNEXT}{ Shifted Next }
1142 \lineii{KEY_SOPTIONS}{ Shifted Options }
1143 \lineii{KEY_SPREVIOUS}{ Shifted Prev }
1144 \lineii{KEY_SPRINT}{ Shifted Print }
1145 \lineii{KEY_SREDO}{ Shifted Redo }
1146 \lineii{KEY_SREPLACE}{ Shifted Replace }
1147 \lineii{KEY_SRIGHT}{ Shifted Right arrow }
1148 \lineii{KEY_SRSUME}{ Shifted Resume }
1149 \lineii{KEY_SSAVE}{ Shifted Save }
1150 \lineii{KEY_SSUSPEND}{ Shifted Suspend }
1151 \lineii{KEY_SUNDO}{ Shifted Undo }
1152 \lineii{KEY_SUSPEND}{ Suspend }
1153 \lineii{KEY_UNDO}{ Undo }
1154 \lineii{KEY_MOUSE}{ Mouse event has occurred }
1155 \lineii{KEY_RESIZE}{ Terminal resize event }
1156 \lineii{KEY_MAX}{Maximum key value}
Fred Drake1bf4e932000-09-21 16:04:08 +00001157\end{longtableii}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001158
Fred Drakeec4b2af2000-08-09 14:34:48 +00001159On VT100s and their software emulations, such as X terminal emulators,
1160there are normally at least four function keys (\constant{KEY_F1},
1161\constant{KEY_F2}, \constant{KEY_F3}, \constant{KEY_F4}) available,
1162and the arrow keys mapped to \constant{KEY_UP}, \constant{KEY_DOWN},
1163\constant{KEY_LEFT} and \constant{KEY_RIGHT} in the obvious way. If
1164your machine has a PC keybboard, it is safe to expect arrow keys and
1165twelve function keys (older PC keyboards may have only ten function
1166keys); also, the following keypad mappings are standard:
Eric S. Raymondb924bd42000-07-27 21:10:02 +00001167
Fred Drakeec4b2af2000-08-09 14:34:48 +00001168\begin{tableii}{l|l}{kbd}{Keycap}{Constant}
Eric S. Raymondb924bd42000-07-27 21:10:02 +00001169 \lineii{Insert}{KEY_IC}
1170 \lineii{Delete}{KEY_DC}
1171 \lineii{Home}{KEY_HOME}
1172 \lineii{End}{KEY_END}
1173 \lineii{Page Up}{KEY_NPAGE}
1174 \lineii{Page Down}{KEY_PPAGE}
1175\end{tableii}
1176
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001177The following table lists characters from the alternate character set.
Eric S. Raymondb924bd42000-07-27 21:10:02 +00001178These are inherited from the VT100 terminal, and will generally be
1179available on software emulations such as X terminals. When there
1180is no graphic available, curses falls back on a crude printable ASCII
1181approximation.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001182\strong{Note:} These are available only after \function{initscr()} has
1183been called.
1184
Fred Drake1bf4e932000-09-21 16:04:08 +00001185\begin{longtableii}{l|l}{code}{ACS code}{Meaning}
Eric S. Raymondb924bd42000-07-27 21:10:02 +00001186 \lineii{ACS_BBSS}{alternate name for upper right corner}
Eric S. Raymond68996602000-07-24 03:28:40 +00001187 \lineii{ACS_BLOCK}{solid square block}
1188 \lineii{ACS_BOARD}{board of squares}
Eric S. Raymondb924bd42000-07-27 21:10:02 +00001189 \lineii{ACS_BSBS}{alternate name for horizontal line}
1190 \lineii{ACS_BSSB}{alternate name for upper left corner}
1191 \lineii{ACS_BSSS}{alternate name for top tee}
Eric S. Raymond68996602000-07-24 03:28:40 +00001192 \lineii{ACS_BTEE}{bottom tee}
1193 \lineii{ACS_BULLET}{bullet}
1194 \lineii{ACS_CKBOARD}{checker board (stipple)}
1195 \lineii{ACS_DARROW}{arrow pointing down}
1196 \lineii{ACS_DEGREE}{degree symbol}
1197 \lineii{ACS_DIAMOND}{diamond}
1198 \lineii{ACS_GEQUAL}{greater-than-or-equal-to}
1199 \lineii{ACS_HLINE}{horizontal line}
1200 \lineii{ACS_LANTERN}{lantern symbol}
1201 \lineii{ACS_LARROW}{left arrow}
1202 \lineii{ACS_LEQUAL}{less-than-or-equal-to}
1203 \lineii{ACS_LLCORNER}{lower left-hand corner}
1204 \lineii{ACS_LRCORNER}{lower right-hand corner}
1205 \lineii{ACS_LTEE}{left tee}
1206 \lineii{ACS_NEQUAL}{not-equal sign}
1207 \lineii{ACS_PI}{letter pi}
1208 \lineii{ACS_PLMINUS}{plus-or-minus sign}
Eric S. Raymondb924bd42000-07-27 21:10:02 +00001209 \lineii{ACS_PLUS}{big plus sign}
Eric S. Raymond68996602000-07-24 03:28:40 +00001210 \lineii{ACS_RARROW}{right arrow}
1211 \lineii{ACS_RTEE}{right tee}
1212 \lineii{ACS_S1}{scan line 1}
1213 \lineii{ACS_S3}{scan line 3}
1214 \lineii{ACS_S7}{scan line 7}
1215 \lineii{ACS_S9}{scan line 9}
Eric S. Raymondb924bd42000-07-27 21:10:02 +00001216 \lineii{ACS_SBBS}{alternate name for lower right corner}
1217 \lineii{ACS_SBSB}{alternate name for vertical line}
1218 \lineii{ACS_SBSS}{alternate name for right tee}
1219 \lineii{ACS_SSBB}{alternate name for lower left corner}
1220 \lineii{ACS_SSBS}{alternate name for bottom tee}
1221 \lineii{ACS_SSSB}{alternate name for left tee}
1222 \lineii{ACS_SSSS}{alternate name for crossover or big plus}
Eric S. Raymond68996602000-07-24 03:28:40 +00001223 \lineii{ACS_STERLING}{pound sterling}
1224 \lineii{ACS_TTEE}{top tee}
1225 \lineii{ACS_UARROW}{up arrow}
1226 \lineii{ACS_ULCORNER}{upper left corner}
1227 \lineii{ACS_URCORNER}{upper right corner}
1228 \lineii{ACS_VLINE}{vertical line}
Fred Drake1bf4e932000-09-21 16:04:08 +00001229\end{longtableii}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001230
1231The following table lists the predefined colors:
1232
Fred Drakeec4b2af2000-08-09 14:34:48 +00001233\begin{tableii}{l|l}{code}{Constant}{Color}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001234 \lineii{COLOR_BLACK}{Black}
1235 \lineii{COLOR_BLUE}{Blue}
1236 \lineii{COLOR_CYAN}{Cyan (light greenish blue)}
1237 \lineii{COLOR_GREEN}{Green}
1238 \lineii{COLOR_MAGENTA}{Magenta (purplish red)}
1239 \lineii{COLOR_RED}{Red}
1240 \lineii{COLOR_WHITE}{White}
1241 \lineii{COLOR_YELLOW}{Yellow}
1242\end{tableii}
1243
Eric S. Raymond5a007692000-08-04 07:35:41 +00001244\section{\module{curses.textpad} ---
1245 Text input widget for curses programs}
1246
1247\declaremodule{standard}{curses.textpad}
1248\sectionauthor{Eric Raymond}{esr@thyrsus.com}
1249\moduleauthor{Eric Raymond}{esr@thyrsus.com}
1250\modulesynopsis{Emacs-like input editing in a curses window.}
1251\versionadded{1.6}
1252
1253The \module{curses.textpad} module provides a \class{Textbox} class
1254that handles elementary text editing in a curses window, supporting a
1255set of keybindings resembling those of Emacs (thus, also of Netscape
1256Navigator, BBedit 6.x, FrameMaker, and many other programs). The
1257module also provides a rectangle-drawing function useful for framing
1258text boxes or for other purposes.
1259
Fred Drakeec4b2af2000-08-09 14:34:48 +00001260The module \module{curses.textpad} defines the following function:
Eric S. Raymond5a007692000-08-04 07:35:41 +00001261
1262\begin{funcdesc}{rectangle}{win, uly, ulx, lry, lrx}
1263Draw a rectangle. The first argument must be a window object; the
1264remaining arguments are coordinates relative to that window. The
1265second and third arguments are the y and x coordinates of the upper
1266left hand corner of the rectangle To be drawn; the fourth and fifth
1267arguments are the y and x coordinates of the lower right hand corner.
1268The rectangle will be drawn using VT100/IBM PC forms characters on
1269terminals that make this possible (including xterm and most other
1270software terminal emulators). Otherwise it will be drawn with ASCII
1271dashes, vertical bars, and plus signs.
1272\end{funcdesc}
1273
Fred Drakeec4b2af2000-08-09 14:34:48 +00001274
Eric S. Raymond5a007692000-08-04 07:35:41 +00001275\subsection{Textbox objects \label{curses-textpad-objects}}
1276
1277You can instantiate a \class{Textbox} object as follows:
1278
Fred Drakeec4b2af2000-08-09 14:34:48 +00001279\begin{classdesc}{Textbox}{win}
1280Return a textbox widget object. The \var{win} argument should be a
1281curses \class{WindowObject} in which the textbox is to be contained.
1282The edit cursor of the textbox is initially located at the upper left
1283hand corner of the containin window, with coordinates \code{(0, 0)}.
1284The instance's \member{stripspaces} flag is initially on.
Eric S. Raymond5a007692000-08-04 07:35:41 +00001285\end{classdesc}
1286
Fred Drakeec4b2af2000-08-09 14:34:48 +00001287\class{Textbox} objects have the following methods:
Eric S. Raymond5a007692000-08-04 07:35:41 +00001288
Fred Drakeec4b2af2000-08-09 14:34:48 +00001289\begin{methoddesc}{edit}{\optional{validator}}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001290This is the entry point you will normally use. It accepts editing
Fred Drakeec4b2af2000-08-09 14:34:48 +00001291keystrokes until one of the termination keystrokes is entered. If
1292\var{validator} is supplied, it must be a function. It will be called
1293for each keystroke entered with the keystroke as a parameter; command
1294dispatch is done on the result. This method returns the window
1295contents as a string; whether blanks in the window are included is
1296affected by the \member{stripspaces} member.
Eric S. Raymond5a007692000-08-04 07:35:41 +00001297\end{methoddesc}
1298
1299\begin{methoddesc}{do_command}{ch}
1300Process a single command keystroke. Here are the supported special
1301keystrokes:
1302
Fred Drakeec4b2af2000-08-09 14:34:48 +00001303\begin{tableii}{l|l}{kbd}{Keystroke}{Action}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001304 \lineii{Ctrl-A}{Go to left edge of window.}
1305 \lineii{Ctrl-B}{Cursor left, wrapping to previous line if appropriate.}
1306 \lineii{Ctrl-D}{Delete character under cursor.}
Fred Drakee412e7a2000-12-21 17:04:31 +00001307 \lineii{Ctrl-E}{Go to right edge (stripspaces off) or end of line
1308 (stripspaces on).}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001309 \lineii{Ctrl-F}{Cursor right, wrapping to next line when appropriate.}
1310 \lineii{Ctrl-G}{Terminate, returning the window contents.}
1311 \lineii{Ctrl-H}{Delete character backward.}
1312 \lineii{Ctrl-J}{Terminate if the window is 1 line, otherwise insert newline.}
1313 \lineii{Ctrl-K}{If line is blank, delete it, otherwise clear to end of line.}
1314 \lineii{Ctrl-L}{Refresh screen.}
1315 \lineii{Ctrl-N}{Cursor down; move down one line.}
1316 \lineii{Ctrl-O}{Insert a blank line at cursor location.}
1317 \lineii{Ctrl-P}{Cursor up; move up one line.}
1318\end{tableii}
1319
1320Move operations do nothing if the cursor is at an edge where the
1321movement is not possible. The following synonyms are supported where
Fred Drakeec4b2af2000-08-09 14:34:48 +00001322possible:
1323
1324\begin{tableii}{l|l}{constant}{Constant}{Keystroke}
1325 \lineii{KEY_LEFT}{\kbd{Ctrl-B}}
1326 \lineii{KEY_RIGHT}{\kbd{Ctrl-F}}
1327 \lineii{KEY_UP}{\kbd{Ctrl-P}}
1328 \lineii{KEY_DOWN}{\kbd{Ctrl-N}}
1329 \lineii{KEY_BACKSPACE}{\kbd{Ctrl-h}}
1330\end{tableii}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001331
1332All other keystrokes are treated as a command to insert the given
1333character and move right (with line wrapping).
1334\end{methoddesc}
1335
1336\begin{methoddesc}{gather}{}
1337This method returns the window contents as a string; whether blanks in
1338the window are included is affected by the \member{stripspaces}
1339member.
1340\end{methoddesc}
1341
Fred Drakeec4b2af2000-08-09 14:34:48 +00001342\begin{memberdesc}{stripspaces}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001343This data member is a flag which controls the interpretation of blanks in
1344the window. When it is on, trailing blanks on each line are ignored;
1345any cursor motion that would land the cursor on a trailing blank goes
1346to the end of that line instead, and trailing blanks are stripped when
1347the window contents is gathered.
Fred Drakeec4b2af2000-08-09 14:34:48 +00001348\end{memberdesc}
1349
Eric S. Raymond5a007692000-08-04 07:35:41 +00001350
1351\section{\module{curses.wrapper} ---
Fred Drakeec4b2af2000-08-09 14:34:48 +00001352 Terminal handler for curses programs}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001353
1354\declaremodule{standard}{curses.wrapper}
1355\sectionauthor{Eric Raymond}{esr@thyrsus.com}
1356\moduleauthor{Eric Raymond}{esr@thyrsus.com}
Fred Drakeec4b2af2000-08-09 14:34:48 +00001357\modulesynopsis{Terminal configuration wrapper for curses programs.}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001358\versionadded{1.6}
1359
1360This module supplies one function, \function{wrapper()}, which runs
1361another function which should be the rest of your curses-using
1362application. If the application raises an exception,
1363\function{wrapper()} will restore the terminal to a sane state before
1364passing it further up the stack and generating a traceback.
1365
Fred Drakeec4b2af2000-08-09 14:34:48 +00001366\begin{funcdesc}{wrapper}{func, \moreargs}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001367Wrapper function that initializes curses and calls another function,
Fred Drakeec4b2af2000-08-09 14:34:48 +00001368\var{func}, restoring normal keyboard/screen behavior on error.
1369The callable object \var{func} is then passed the main window 'stdscr'
Eric S. Raymond5a007692000-08-04 07:35:41 +00001370as its first argument, followed by any other arguments passed to
1371\function{wrapper()}.
1372\end{funcdesc}
1373
Eric S. Raymond1ebd3f62000-08-09 21:11:07 +00001374Before calling the hook function, \function{wrapper()} turns on cbreak
1375mode, turns off echo, enables the terminal keypad, and initializes
1376colors if the terminal has color support. On exit (whether normally
1377or by exception) it restores cooked mode, turns on echo, and disables
1378the terminal keypad.
Eric S. Raymond5a007692000-08-04 07:35:41 +00001379