blob: 4ff170c13cd430a3151159f5f86368d6e117fb62 [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 Drakecfac6d22001-04-10 18:49:09 +000030 \program{Emacs}-like bindings.}
Fred Drakeec4b2af2000-08-09 14:34:48 +000031 \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
Fred Drakecfac6d22001-04-10 18:49:09 +000036 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.}
Fred Drakea4070ce1999-06-21 21:13:09 +000041\end{seealso}
42
43
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000044\subsection{Functions \label{curses-functions}}
Fred Drakea4070ce1999-06-21 21:13:09 +000045
46The module \module{curses} defines the following exception:
Fred Drakeec4b2af2000-08-09 14:34:48 +000047
Fred Drakea4070ce1999-06-21 21:13:09 +000048\begin{excdesc}{error}
Fred Drakeec4b2af2000-08-09 14:34:48 +000049Exception raised when a curses library function returns an error.
Fred Drakea4070ce1999-06-21 21:13:09 +000050\end{excdesc}
51
Fred Drake0aa811c2001-10-20 04:24:09 +000052\note{Whenever \var{x} or \var{y} arguments to a function
Fred Drake0bccd731999-06-23 17:28:01 +000053or a method are optional, they default to the current cursor location.
Fred Drake0aa811c2001-10-20 04:24:09 +000054Whenever \var{attr} is optional, it defaults to \constant{A_NORMAL}.}
Fred Drake0bccd731999-06-23 17:28:01 +000055
Fred Drakea4070ce1999-06-21 21:13:09 +000056The module \module{curses} defines the following functions:
57
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000058\begin{funcdesc}{baudrate}{}
Eric S. Raymond68996602000-07-24 03:28:40 +000059Returns 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.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000064\end{funcdesc}
65
66\begin{funcdesc}{beep}{}
Eric S. Raymond68996602000-07-24 03:28:40 +000067Emit a short attention sound.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000068\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}{}
Eric S. Raymond68996602000-07-24 03:28:40 +000076Enter 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.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000082\end{funcdesc}
83
84\begin{funcdesc}{color_content}{color_number}
85Returns the intensity of the red, green, and blue (RGB) components in
Fred Drakee412e7a2000-12-21 17:04:31 +000086the 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).
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000090\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
Fred Drakee412e7a2000-12-21 17:04:31 +000096\constant{A_*} attributes. \function{pair_number()} is the
97counterpart to this function.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000098\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;
Eric S. Raymond68996602000-07-24 03:28:40 +0000104otherwise, an exception is raised. On many terminals, the ``visible''
105mode is an underline cursor and the ``very visible'' mode is a block cursor.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000106\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}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000128Update 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()}.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000141\end{funcdesc}
142
143\begin{funcdesc}{echo}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000144Enter echo mode. In echo mode, each character input is echoed to the
145screen as it is entered.
Fred Drakea4070ce1999-06-21 21:13:09 +0000146\end{funcdesc}
147
148\begin{funcdesc}{endwin}{}
149De-initialize the library, and return terminal to normal status.
150\end{funcdesc}
151
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000152\begin{funcdesc}{erasechar}{}
Fred Drakec37b65e2001-11-28 07:26:15 +0000153Returns the user's current erase character. Under \UNIX{} operating
Eric S. Raymond68996602000-07-24 03:28:40 +0000154systems this is a property of the controlling tty of the curses
155program, and is not set by the curses library itself.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000156\end{funcdesc}
157
158\begin{funcdesc}{filter}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000159The \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 cgaracter-at-a-time
165line editing without touching the rest of the screen.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000166\end{funcdesc}
167
168\begin{funcdesc}{flash}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000169Flash 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()}.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000172\end{funcdesc}
173
174\begin{funcdesc}{flushinp}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000175Flush all input buffers. This throws away any typeahead that has
176been typed by the user and has not yet been processed by the program.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000177\end{funcdesc}
178
Andrew M. Kuchlingefc43d42000-06-30 01:05:39 +0000179\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
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000200\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}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000212Returns true if the terminal can display colors; otherwise, it
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000213returns false.
214\end{funcdesc}
215
216\begin{funcdesc}{has_ic}{}
217Returns true if the terminal has insert- and delete- character
Eric S. Raymond68996602000-07-24 03:28:40 +0000218capabilities. This function is included for historical reasons only,
219as all modern software terminal emulators have such capabilities.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000220\end{funcdesc}
221
222\begin{funcdesc}{has_il}{}
223Returns true if the terminal has insert- and
224delete-line capabilities, or can simulate them using
Eric S. Raymond68996602000-07-24 03:28:40 +0000225scrolling regions. This function is included for historical reasons only,
226as all modern software terminal emulators have such capabilities.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000227\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
Fred Drakee412e7a2000-12-21 17:04:31 +0000239\var{tenths} must be a number between 1 and 255. Use
240\function{nocbreak()} to leave half-delay mode.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000241\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
Fred Drakee412e7a2000-12-21 17:04:31 +0000247between \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}.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000253\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
Fred Drakee412e7a2000-12-21 17:04:31 +0000259be 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.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000265\end{funcdesc}
266
267\begin{funcdesc}{initscr}{}
268Initialize the library. Returns a \class{WindowObject} which represents
269the whole screen.
270\end{funcdesc}
271
Fred Drakea4070ce1999-06-21 21:13:09 +0000272\begin{funcdesc}{isendwin}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000273Returns true if \function{endwin()} has been called (that is, the
274curses library has been deinitialized).
Fred Drakea4070ce1999-06-21 21:13:09 +0000275\end{funcdesc}
276
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000277\begin{funcdesc}{keyname}{k}
Eric S. Raymond68996602000-07-24 03:28:40 +0000278Return the name of the key numbered \var{k}. The name of a key
279generating printable ASCII character is the key's character. The name
280of a control-key combination is a two-character string consisting of a
281caret followed by the corresponding printable ASCII character. The
282name of an alt-key combination (128-255) is a string consisting of the
283prefix `M-' followed by the name of the corresponding ASCII character.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000284\end{funcdesc}
285
286\begin{funcdesc}{killchar}{}
Fred Drakec37b65e2001-11-28 07:26:15 +0000287Returns the user's current line kill character. Under \UNIX{} operating
Eric S. Raymond68996602000-07-24 03:28:40 +0000288systems this is a property of the controlling tty of the curses
289program, and is not set by the curses library itself.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000290\end{funcdesc}
291
292\begin{funcdesc}{longname}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000293Returns a string containing the terminfo long name field describing the current
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000294terminal. The maximum length of a verbose description is 128
295characters. It is defined only after the call to
296\function{initscr()}.
297\end{funcdesc}
298
299\begin{funcdesc}{meta}{yes}
Eric S. Raymond68996602000-07-24 03:28:40 +0000300If \var{yes} is 1, allow 8-bit characters to be input. If \var{yes} is 0,
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000301allow only 7-bit chars.
302\end{funcdesc}
303
Andrew M. Kuchlingefc43d42000-06-30 01:05:39 +0000304\begin{funcdesc}{mouseinterval}{interval}
Thomas Woutersf8316632000-07-16 19:01:10 +0000305Sets the maximum time in milliseconds that can elapse between press and
Andrew M. Kuchlingefc43d42000-06-30 01:05:39 +0000306release events in order for them to be recognized as a click, and
307returns the previous interval value. The default value is 200 msec,
308or one fifth of a second.
309\end{funcdesc}
310
311\begin{funcdesc}{mousemask}{mousemask}
312Sets the mouse events to be reported, and returns a tuple
313\code{(\var{availmask}, \var{oldmask})}.
314\var{availmask} indicates which of the
315specified mouse events can be reported; on complete failure it returns
3160. \var{oldmask} is the previous value of the given window's mouse
317event mask. If this function is never called, no mouse events are
318ever reported.
319\end{funcdesc}
320
Andrew M. Kuchling4fb58822000-12-15 01:03:23 +0000321\begin{funcdesc}{napms}{ms}
322Sleep for \var{ms} milliseconds.
323\end{funcdesc}
324
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000325\begin{funcdesc}{newpad}{nlines, ncols}
326Creates and returns a pointer to a new pad data structure with the
327given number of lines and columns. A pad is returned as a
328window object.
329
Eric S. Raymond68996602000-07-24 03:28:40 +0000330A pad is like a window, except that it is not restricted by the screen
331size, and is not necessarily associated with a particular part of the
332screen. Pads can be used when a large window is needed, and only a
333part of the window will be on the screen at one time. Automatic
Fred Drake91f2f262001-07-06 19:28:48 +0000334refreshes of pads (such as from scrolling or echoing of input) do not
Eric S. Raymond68996602000-07-24 03:28:40 +0000335occur. The \method{refresh()} and \method{noutrefresh()} methods of a
336pad require 6 arguments to specify the part of the pad to be
337displayed and the location on the screen to be used for the display.
338The arguments are pminrow, pmincol, sminrow, smincol, smaxrow,
339smaxcol; the p arguments refer to the upper left corner of the the pad
340region to be displayed and the s arguments define a clipping box on
341the screen within which the pad region is to be displayed.
Fred Drakea4070ce1999-06-21 21:13:09 +0000342\end{funcdesc}
343
344\begin{funcdesc}{newwin}{\optional{nlines, ncols,} begin_y, begin_x}
345Return a new window, whose left-upper corner is at
346\code{(\var{begin_y}, \var{begin_x})}, and whose height/width is
Fred Drake0bccd731999-06-23 17:28:01 +0000347\var{nlines}/\var{ncols}.
348
349By default, the window will extend from the
Fred Drakea4070ce1999-06-21 21:13:09 +0000350specified position to the lower right corner of the screen.
351\end{funcdesc}
352
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000353\begin{funcdesc}{nl}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000354Enter newline mode. This mode translates the return key into newline
355on input, and translates newline into return and line-feed on output.
356Newline mode is initially on.
Fred Drakea4070ce1999-06-21 21:13:09 +0000357\end{funcdesc}
358
359\begin{funcdesc}{nocbreak}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000360Leave cbreak mode. Return to normal ``cooked'' mode with line buffering.
Fred Drakea4070ce1999-06-21 21:13:09 +0000361\end{funcdesc}
362
Fred Drakea4070ce1999-06-21 21:13:09 +0000363\begin{funcdesc}{noecho}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000364Leave echo mode. Echoing of input characters is turned off,
Fred Drakea4070ce1999-06-21 21:13:09 +0000365\end{funcdesc}
366
Fred Drakea4070ce1999-06-21 21:13:09 +0000367\begin{funcdesc}{nonl}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000368Leave newline mode. Disable translation of return into newline on
369input, and disable low-level translation of newline into
370newline/return on output (but this does not change the behavior of
Fred Drakee1b304d2000-07-24 19:35:52 +0000371\code{addch('\e n')}, which always does the equivalent of return and
372line feed on the virtual screen). With translation off, curses can
373sometimes speed up vertical motion a little; also, it will be able to
374detect the return key on input.
Fred Drakea4070ce1999-06-21 21:13:09 +0000375\end{funcdesc}
376
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000377\begin{funcdesc}{noqiflush}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000378When the noqiflush routine is used, normal flush of input and
379output queues associated with the INTR, QUIT and SUSP
380characters will not be done. You may want to call
381\function{noqiflush()} in a signal handler if you want output
382to continue as though the interrupt had not occurred, after the
383handler exits.
Fred Drakea4070ce1999-06-21 21:13:09 +0000384\end{funcdesc}
385
386\begin{funcdesc}{noraw}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000387Leave raw mode. Return to normal ``cooked'' mode with line buffering.
Fred Drakea4070ce1999-06-21 21:13:09 +0000388\end{funcdesc}
389
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000390\begin{funcdesc}{pair_content}{pair_number}
391Returns a tuple \var{(fg,bg)} containing the colors for the requested
392color pair. The value of \var{pair_number} must be between 0 and
393COLOR_PAIRS-1.
Fred Drakea4070ce1999-06-21 21:13:09 +0000394\end{funcdesc}
395
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000396\begin{funcdesc}{pair_number}{attr}
397Returns the number of the color-pair set by the attribute value \var{attr}.
398\function{color_pair()} is the counterpart to this function.
Fred Drakea4070ce1999-06-21 21:13:09 +0000399\end{funcdesc}
400
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000401\begin{funcdesc}{putp}{string}
Eric S. Raymond68996602000-07-24 03:28:40 +0000402Equivalent to \code{tputs(str, 1, putchar)}; emits the value of a
403specified terminfo capability for the current terminal. Note that the
404output of putp always goes to standard output.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000405\end{funcdesc}
406
407\begin{funcdesc}{qiflush}{ \optional{flag} }
408If \var{flag} is false, the effect is the same as calling
409\function{noqiflush()}. If \var{flag} is true, or no argument is
410provided, the queues will be flushed when these control characters are
411read.
412\end{funcdesc}
413
414\begin{funcdesc}{raw}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000415Enter raw mode. In raw mode, normal line buffering and
416processing of interrupt, quit, suspend, and flow control keys are
417turned off; characters are presented to curses input functions one
418by one.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000419\end{funcdesc}
420
421\begin{funcdesc}{reset_prog_mode}{}
422Restores the terminal to ``program'' mode, as previously saved
423by \function{def_prog_mode()}.
424\end{funcdesc}
425
426\begin{funcdesc}{reset_shell_mode}{}
427Restores the terminal to ``shell'' mode, as previously saved
428by \function{def_shell_mode()}.
429\end{funcdesc}
430
431\begin{funcdesc}{setsyx}{y, x}
432Sets the virtual screen cursor to \var{y}, \var{x}.
433If \var{y} and \var{x} are both -1, then leaveok is set.
434\end{funcdesc}
435
Andrew M. Kuchling620ec9d2000-11-18 17:57:33 +0000436\begin{funcdesc}{setupterm}{\optional{termstr, fd}}
437Initializes the terminal. \var{termstr} is a string giving the
438terminal name; if omitted, the value of the TERM environment variable
Fred Drakee412e7a2000-12-21 17:04:31 +0000439will be used. \var{fd} is the file descriptor to which any
440initialization sequences will be sent; if not supplied, the file
441descriptor for \code{sys.stdout} will be used.
Andrew M. Kuchling620ec9d2000-11-18 17:57:33 +0000442\end{funcdesc}
443
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000444\begin{funcdesc}{start_color}{}
445Must be called if the programmer wants to use colors, and before any
446other color manipulation routine is called. It is good
447practice to call this routine right after \function{initscr()}.
448
449\function{start_color()} initializes eight basic colors (black, red,
450green, yellow, blue, magenta, cyan, and white), and two global
Fred Drakee412e7a2000-12-21 17:04:31 +0000451variables in the \module{curses} module, \constant{COLORS} and
452\constant{COLOR_PAIRS}, containing the maximum number of colors and
453color-pairs the terminal can support. It also restores the colors on
454the terminal to the values they had when the terminal was just turned
455on.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000456\end{funcdesc}
457
458\begin{funcdesc}{termattrs}{}
459Returns a logical OR of all video attributes supported by the
460terminal. This information is useful when a curses program needs
461complete control over the appearance of the screen.
462\end{funcdesc}
463
464\begin{funcdesc}{termname}{}
465Returns the value of the environment variable TERM, truncated to 14
466characters.
467\end{funcdesc}
468
Andrew M. Kuchling1962fb52000-07-26 02:59:13 +0000469\begin{funcdesc}{tigetflag}{capname}
470Returns the value of the Boolean capability corresponding to the
Fred Drakee412e7a2000-12-21 17:04:31 +0000471terminfo capability name \var{capname}. The value \code{-1} is
472returned if \var{capname} is not a Boolean capability, or \code{0} if
473it is canceled or absent from the terminal description.
Andrew M. Kuchling1962fb52000-07-26 02:59:13 +0000474\end{funcdesc}
475
476\begin{funcdesc}{tigetnum}{capname}
477Returns the value of the numeric capability corresponding to the
Fred Drakee412e7a2000-12-21 17:04:31 +0000478terminfo capability name \var{capname}. The value \code{-2} is
479returned if \var{capname} is not a numeric capability, or \code{-1} if
480it is canceled or absent from the terminal description.
Andrew M. Kuchling1962fb52000-07-26 02:59:13 +0000481\end{funcdesc}
482
483\begin{funcdesc}{tigetstr}{capname}
484Returns the value of the string capability corresponding to the
485terminfo capability name \var{capname}. \code{None} is returned if
486\var{capname} is not a string capability, or is canceled or absent
487from the terminal description.
488\end{funcdesc}
489
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +0000490\begin{funcdesc}{tparm}{str\optional{,...}}
491Instantiates the string \var{str} with the supplied parameters, where
492\var{str} should be a parameterized string obtained from the terminfo
Fred Drakee412e7a2000-12-21 17:04:31 +0000493database. E.g. \code{tparm(tigetstr("cup"), 5, 3)} could result in
494\code{'\e{}033[6;4H'}, the exact result depending on terminal type.
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +0000495\end{funcdesc}
496
Andrew M. Kuchlingd24ff442000-06-21 01:42:51 +0000497\begin{funcdesc}{typeahead}{fd}
498Specifies that the file descriptor \var{fd} be used for typeahead
Fred Drakee412e7a2000-12-21 17:04:31 +0000499checking. If \var{fd} is \code{-1}, then no typeahead checking is
500done.
Andrew M. Kuchlingd24ff442000-06-21 01:42:51 +0000501
502The curses library does ``line-breakout optimization'' by looking for
503typeahead periodically while updating the screen. If input is found,
504and it is coming from a tty, the current update is postponed until
505refresh or doupdate is called again, allowing faster response to
506commands typed in advance. This function allows specifying a different
507file descriptor for typeahead checking.
508\end{funcdesc}
509
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000510\begin{funcdesc}{unctrl}{ch}
511Returns a string which is a printable representation of the character
512\var{ch}. Control characters are displayed as a caret followed by the
Fred Drake4cacec52001-04-21 05:56:06 +0000513character, for example as \code{\textasciicircum C}. Printing
514characters are left as they are.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000515\end{funcdesc}
516
517\begin{funcdesc}{ungetch}{ch}
518Push \var{ch} so the next \method{getch()} will return it.
Fred Drake0aa811c2001-10-20 04:24:09 +0000519\note{Only one \var{ch} can be pushed before \method{getch()}
520is called.}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000521\end{funcdesc}
522
Andrew M. Kuchlingefc43d42000-06-30 01:05:39 +0000523\begin{funcdesc}{ungetmouse}{id, x, y, z, bstate}
524Push a \constant{KEY_MOUSE} event onto the input queue, associating
525the given state data with it.
526\end{funcdesc}
527
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000528\begin{funcdesc}{use_env}{flag}
Fred Drakee412e7a2000-12-21 17:04:31 +0000529If used, this function should be called before \function{initscr()} or
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000530newterm are called. When \var{flag} is false, the values of
531lines and columns specified in the terminfo database will be
Fred Drakee412e7a2000-12-21 17:04:31 +0000532used, even if environment variables \envvar{LINES} and
533\envvar{COLUMNS} (used by default) are set, or if curses is running in
534a window (in which case default behavior would be to use the window
535size if \envvar{LINES} and \envvar{COLUMNS} are not set).
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000536\end{funcdesc}
Fred Drakea4070ce1999-06-21 21:13:09 +0000537
538\subsection{Window Objects \label{curses-window-objects}}
539
540Window objects, as returned by \function{initscr()} and
541\function{newwin()} above, have the
542following methods:
543
Fred Drakefd7f1152001-12-26 22:08:44 +0000544\begin{methoddesc}[window]{addch}{\optional{y, x,} ch\optional{, attr}}
Fred Drake0aa811c2001-10-20 04:24:09 +0000545\note{A \emph{character} means a C character (an
Fred Drakea4070ce1999-06-21 21:13:09 +0000546\ASCII{} code), rather then a Python character (a string of length 1).
547(This note is true whenever the documentation mentions a character.)
Fred Drake0aa811c2001-10-20 04:24:09 +0000548The builtin \function{ord()} is handy for conveying strings to codes.}
Fred Drakea4070ce1999-06-21 21:13:09 +0000549
550Paint character \var{ch} at \code{(\var{y}, \var{x})} with attributes
551\var{attr}, overwriting any character previously painter at that
552location. By default, the character position and attributes are the
553current settings for the window object.
554\end{methoddesc}
555
Fred Drakefd7f1152001-12-26 22:08:44 +0000556\begin{methoddesc}[window]{addnstr}{\optional{y, x,} str, n\optional{, attr}}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000557Paint at most \var{n} characters of the
558string \var{str} at \code{(\var{y}, \var{x})} with attributes
Fred Drake0bccd731999-06-23 17:28:01 +0000559\var{attr}, overwriting anything previously on the display.
Fred Drakea4070ce1999-06-21 21:13:09 +0000560\end{methoddesc}
561
Fred Drakefd7f1152001-12-26 22:08:44 +0000562\begin{methoddesc}[window]{addstr}{\optional{y, x,} str\optional{, attr}}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000563Paint the string \var{str} at \code{(\var{y}, \var{x})} with attributes
564\var{attr}, overwriting anything previously on the display.
Fred Drakea4070ce1999-06-21 21:13:09 +0000565\end{methoddesc}
566
Fred Drakefd7f1152001-12-26 22:08:44 +0000567\begin{methoddesc}[window]{attroff}{attr}
Eric S. Raymond68996602000-07-24 03:28:40 +0000568Remove attribute \var{attr} from the ``background'' set applied to all
569writes to the current window.
Fred Drakea4070ce1999-06-21 21:13:09 +0000570\end{methoddesc}
571
Fred Drakefd7f1152001-12-26 22:08:44 +0000572\begin{methoddesc}[window]{attron}{attr}
Eric S. Raymond68996602000-07-24 03:28:40 +0000573Add attribute \var{attr} from the ``background'' set applied to all
574writes to the current window.
Fred Drakea4070ce1999-06-21 21:13:09 +0000575\end{methoddesc}
576
Fred Drakefd7f1152001-12-26 22:08:44 +0000577\begin{methoddesc}[window]{attrset}{attr}
Eric S. Raymond68996602000-07-24 03:28:40 +0000578Set the ``background'' set of attributes to \var{attr}. This set is
579initially 0 (no attributes).
Fred Drakea4070ce1999-06-21 21:13:09 +0000580\end{methoddesc}
581
Fred Drakefd7f1152001-12-26 22:08:44 +0000582\begin{methoddesc}[window]{bkgd}{ch\optional{, attr}}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000583Sets the background property of the window to the character \var{ch},
584with attributes \var{attr}. The change is then applied to every
585character position in that window:
586\begin{itemize}
Eric S. Raymondb924bd42000-07-27 21:10:02 +0000587\item
588The attribute of every character in the window is
589changed to the new background attribute.
590\item
591Wherever the former background character appears,
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000592it is changed to the new background character.
593\end{itemize}
594
595\end{methoddesc}
596
Fred Drakefd7f1152001-12-26 22:08:44 +0000597\begin{methoddesc}[window]{bkgdset}{ch\optional{, attr}}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000598Sets the window's background. A window's background consists of a
599character and any combination of attributes. The attribute part of
600the background is combined (OR'ed) with all non-blank characters that
601are written into the window. Both the character and attribute parts
602of the background are combined with the blank characters. The
603background becomes a property of the character and moves with the
604character through any scrolling and insert/delete line/character
605operations.
Fred Drakea4070ce1999-06-21 21:13:09 +0000606\end{methoddesc}
607
Fred Drakefd7f1152001-12-26 22:08:44 +0000608\begin{methoddesc}[window]{border}{\optional{ls\optional{, rs\optional{,
609 ts\optional{, bs\optional{, tl\optional{,
610 tr\optional{, bl\optional{, br}}}}}}}}}
Fred Drake0bccd731999-06-23 17:28:01 +0000611Draw a border around the edges of the window. Each parameter specifies
612the character to use for a specific part of the border; see the table
Andrew M. Kuchling9dbc0bc2001-10-20 16:07:41 +0000613below for more details. The characters can be specified as integers
614or as one-character strings.
Fred Drake0bccd731999-06-23 17:28:01 +0000615
Fred Drake0aa811c2001-10-20 04:24:09 +0000616\note{A \code{0} value for any parameter will cause the
Fred Drake0bccd731999-06-23 17:28:01 +0000617default character to be used for that parameter. Keyword parameters
Fred Drake0aa811c2001-10-20 04:24:09 +0000618can \emph{not} be used. The defaults are listed in this table:}
Fred Drake0bccd731999-06-23 17:28:01 +0000619
620\begin{tableiii}{l|l|l}{var}{Parameter}{Description}{Default value}
621 \lineiii{ls}{Left side}{\constant{ACS_VLINE}}
622 \lineiii{rs}{Right side}{\constant{ACS_VLINE}}
623 \lineiii{ts}{Top}{\constant{ACS_HLINE}}
624 \lineiii{bs}{Bottom}{\constant{ACS_HLINE}}
625 \lineiii{tl}{Upper-left corner}{\constant{ACS_ULCORNER}}
626 \lineiii{tr}{Upper-right corner}{\constant{ACS_URCORNER}}
627 \lineiii{bl}{Bottom-left corner}{\constant{ACS_BLCORNER}}
628 \lineiii{br}{Bottom-right corner}{\constant{ACS_BRCORNER}}
629\end{tableiii}
Fred Drakea4070ce1999-06-21 21:13:09 +0000630\end{methoddesc}
631
Fred Drakefd7f1152001-12-26 22:08:44 +0000632\begin{methoddesc}[window]{box}{\optional{vertch, horch}}
Fred Drake0bccd731999-06-23 17:28:01 +0000633Similar to \method{border()}, but both \var{ls} and \var{rs} are
634\var{vertch} and both \var{ts} and {bs} are \var{horch}. The default
635corner characters are always used by this function.
Fred Drakea4070ce1999-06-21 21:13:09 +0000636\end{methoddesc}
637
Fred Drakefd7f1152001-12-26 22:08:44 +0000638\begin{methoddesc}[window]{clear}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000639Like \method{erase()}, but also causes the whole window to be repainted
Fred Drakea4070ce1999-06-21 21:13:09 +0000640upon next call to \method{refresh()}.
641\end{methoddesc}
642
Fred Drakefd7f1152001-12-26 22:08:44 +0000643\begin{methoddesc}[window]{clearok}{yes}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000644If \var{yes} is 1, the next call to \method{refresh()}
Eric S. Raymond68996602000-07-24 03:28:40 +0000645will clear the window completely.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000646\end{methoddesc}
647
Fred Drakefd7f1152001-12-26 22:08:44 +0000648\begin{methoddesc}[window]{clrtobot}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000649Erase from cursor to the end of the window: all lines below the cursor
Fred Drakea4070ce1999-06-21 21:13:09 +0000650are deleted, and then the equivalent of \method{clrtoeol()} is performed.
651\end{methoddesc}
652
Fred Drakefd7f1152001-12-26 22:08:44 +0000653\begin{methoddesc}[window]{clrtoeol}{}
Fred Drakea4070ce1999-06-21 21:13:09 +0000654Erase from cursor to the end of the line.
655\end{methoddesc}
656
Fred Drakefd7f1152001-12-26 22:08:44 +0000657\begin{methoddesc}[window]{cursyncup}{}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000658Updates the current cursor position of all the ancestors of the window
659to reflect the current cursor position of the window.
Fred Drakea4070ce1999-06-21 21:13:09 +0000660\end{methoddesc}
661
Fred Drakefd7f1152001-12-26 22:08:44 +0000662\begin{methoddesc}[window]{delch}{\optional{x, y}}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000663Delete any character at \code{(\var{y}, \var{x})}.
Fred Drakea4070ce1999-06-21 21:13:09 +0000664\end{methoddesc}
665
Fred Drakefd7f1152001-12-26 22:08:44 +0000666\begin{methoddesc}[window]{deleteln}{}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000667Delete the line under the cursor. All following lines are moved up
668by 1 line.
669\end{methoddesc}
670
Fred Drakefd7f1152001-12-26 22:08:44 +0000671\begin{methoddesc}[window]{derwin}{\optional{nlines, ncols,} begin_y, begin_x}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000672An abbreviation for ``derive window'', \method{derwin()} is the same
673as calling \method{subwin()}, except that \var{begin_y} and
674\var{begin_x} are relative to the origin of the window, rather than
675relative to the entire screen. Returns a window object for the
676derived window.
677\end{methoddesc}
678
Fred Drakefd7f1152001-12-26 22:08:44 +0000679\begin{methoddesc}[window]{echochar}{ch\optional{, attr}}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000680Add character \var{ch} with attribute \var{attr}, and immediately
Fred Drakee412e7a2000-12-21 17:04:31 +0000681call \method{refresh()} on the window.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000682\end{methoddesc}
683
Fred Drakefd7f1152001-12-26 22:08:44 +0000684\begin{methoddesc}[window]{enclose}{y, x}
Andrew M. Kuchlingefc43d42000-06-30 01:05:39 +0000685Tests whether the given pair of screen-relative character-cell
686coordinates are enclosed by the given window, returning true or
687false. It is useful for determining what subset of the screen
688windows enclose the location of a mouse event.
689\end{methoddesc}
690
Fred Drakefd7f1152001-12-26 22:08:44 +0000691\begin{methoddesc}[window]{erase}{}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000692Clear the window.
693\end{methoddesc}
694
Fred Drakefd7f1152001-12-26 22:08:44 +0000695\begin{methoddesc}[window]{getbegyx}{}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000696Return a tuple \code{(\var{y}, \var{x})} of co-ordinates of upper-left
697corner.
Fred Drakea4070ce1999-06-21 21:13:09 +0000698\end{methoddesc}
699
Fred Drakefd7f1152001-12-26 22:08:44 +0000700\begin{methoddesc}[window]{getch}{\optional{x, y}}
Fred Drakea4070ce1999-06-21 21:13:09 +0000701Get a character. Note that the integer returned does \emph{not} have to
702be in \ASCII{} range: function keys, keypad keys and so on return numbers
Fred Drakee412e7a2000-12-21 17:04:31 +0000703higher than 256. In no-delay mode, an exception is raised if there is
Fred Drakea4070ce1999-06-21 21:13:09 +0000704no input.
705\end{methoddesc}
706
Fred Drakefd7f1152001-12-26 22:08:44 +0000707\begin{methoddesc}[window]{getkey}{\optional{x, y}}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000708Get a character, returning a string instead of an integer, as
709\method{getch()} does. Function keys, keypad keys and so on return a
710multibyte string containing the key name. In no-delay mode, an
711exception is raised if there is no input.
712\end{methoddesc}
713
Fred Drakefd7f1152001-12-26 22:08:44 +0000714\begin{methoddesc}[window]{getmaxyx}{}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000715Return a tuple \code{(\var{y}, \var{x})} of the height and width of
716the window.
717\end{methoddesc}
718
Fred Drakefd7f1152001-12-26 22:08:44 +0000719\begin{methoddesc}[window]{getparyx}{}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000720Returns the beginning coordinates of this window relative to its
721parent window into two integer variables y and x. Returns
722\code{-1,-1} if this window has no parent.
723\end{methoddesc}
724
Fred Drakefd7f1152001-12-26 22:08:44 +0000725\begin{methoddesc}[window]{getstr}{\optional{x, y}}
Fred Drakea4070ce1999-06-21 21:13:09 +0000726Read a string from the user, with primitive line editing capacity.
727\end{methoddesc}
728
Fred Drakefd7f1152001-12-26 22:08:44 +0000729\begin{methoddesc}[window]{getyx}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000730Return a tuple \code{(\var{y}, \var{x})} of current cursor position
731relative to the window's upper-left corner.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000732\end{methoddesc}
733
Fred Drakefd7f1152001-12-26 22:08:44 +0000734\begin{methoddesc}[window]{hline}{\optional{y, x,} ch, n}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000735Display a horizontal line starting at \code{(\var{y}, \var{x})} with
736length \var{n} consisting of the character \var{ch}.
737\end{methoddesc}
738
Fred Drakefd7f1152001-12-26 22:08:44 +0000739\begin{methoddesc}[window]{idcok}{flag}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000740If \var{flag} is false, curses no longer considers using the hardware
741insert/delete character feature of the terminal; if \var{flag} is
742true, use of character insertion and deletion is enabled. When curses
743is first initialized, use of character insert/delete is enabled by
744default.
745\end{methoddesc}
746
Fred Drakefd7f1152001-12-26 22:08:44 +0000747\begin{methoddesc}[window]{idlok}{yes}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000748If called with \var{yes} equal to 1, \module{curses} will try and use
749hardware line editing facilities. Otherwise, line insertion/deletion
750are disabled.
751\end{methoddesc}
752
Fred Drakefd7f1152001-12-26 22:08:44 +0000753\begin{methoddesc}[window]{immedok}{flag}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000754If \var{flag} is true, any change in the window image
755automatically causes the window to be refreshed; you no longer
756have to call \method{refresh()} yourself. However, it may
757degrade performance considerably, due to repeated calls to
758wrefresh. This option is disabled by default.
759\end{methoddesc}
760
Fred Drakefd7f1152001-12-26 22:08:44 +0000761\begin{methoddesc}[window]{inch}{\optional{x, y}}
Fred Drakea4070ce1999-06-21 21:13:09 +0000762Return the character at the given position in the window. The bottom
7638 bits are the character proper, and upper bits are the attributes.
764\end{methoddesc}
765
Fred Drakefd7f1152001-12-26 22:08:44 +0000766\begin{methoddesc}[window]{insch}{\optional{y, x,} ch\optional{, attr}}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000767Paint character \var{ch} at \code{(\var{y}, \var{x})} with attributes
768\var{attr}, moving the line from position \var{x} right by one
769character.
Fred Drakea4070ce1999-06-21 21:13:09 +0000770\end{methoddesc}
771
Fred Drakefd7f1152001-12-26 22:08:44 +0000772\begin{methoddesc}[window]{insdelln}{nlines}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000773Inserts \var{nlines} lines into the specified window above the current
774line. The \var{nlines} bottom lines are lost. For negative
775\var{nlines}, delete \var{nlines} lines starting with the one under
776the cursor, and move the remaining lines up. The bottom \var{nlines}
777lines are cleared. The current cursor position remains the same.
778\end{methoddesc}
779
Fred Drakefd7f1152001-12-26 22:08:44 +0000780\begin{methoddesc}[window]{insertln}{}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000781Insert a blank line under the cursor. All following lines are moved
782down by 1 line.
783\end{methoddesc}
784
Fred Drakefd7f1152001-12-26 22:08:44 +0000785\begin{methoddesc}[window]{insnstr}{\optional{y, x,} str, n \optional{, attr}}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000786Insert a character string (as many characters as will fit on the line)
787before the character under the cursor, up to \var{n} characters.
788If \var{n} is zero or negative,
789the entire string is inserted.
790All characters to the right of
791the cursor are shifted right, with the the rightmost characters on the
792line being lost. The cursor position does not change (after moving to
793\var{y}, \var{x}, if specified).
794\end{methoddesc}
795
Fred Drakefd7f1152001-12-26 22:08:44 +0000796\begin{methoddesc}[window]{insstr}{\optional{y, x, } str \optional{, attr}}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000797Insert a character string (as many characters as will fit on the line)
798before the character under the cursor. All characters to the right of
799the cursor are shifted right, with the the rightmost characters on the
800line being lost. The cursor position does not change (after moving to
801\var{y}, \var{x}, if specified).
802\end{methoddesc}
803
Fred Drakefd7f1152001-12-26 22:08:44 +0000804\begin{methoddesc}[window]{instr}{\optional{y, x} \optional{, n}}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000805Returns a string of characters, extracted from the window starting at
806the current cursor position, or at \var{y}, \var{x} if specified.
807Attributes are stripped from the characters. If \var{n} is specified,
808\method{instr()} returns return a string at most \var{n} characters
809long (exclusive of the trailing NUL).
810\end{methoddesc}
811
Fred Drakefd7f1152001-12-26 22:08:44 +0000812\begin{methoddesc}[window]{is_linetouched}{\var{line}}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000813Returns true if the specified line was modified since the last call to
814\method{refresh()}; otherwise returns false. Raises a
815\exception{curses.error} exception if \var{line} is not valid
816for the given window.
817\end{methoddesc}
818
Fred Drakefd7f1152001-12-26 22:08:44 +0000819\begin{methoddesc}[window]{is_wintouched}{}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000820Returns true if the specified window was modified since the last call to
821\method{refresh()}; otherwise returns false.
822\end{methoddesc}
823
Fred Drakefd7f1152001-12-26 22:08:44 +0000824\begin{methoddesc}[window]{keypad}{yes}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000825If \var{yes} is 1, escape sequences generated by some keys (keypad,
826function keys) will be interpreted by \module{curses}.
827If \var{yes} is 0, escape sequences will be left as is in the input
828stream.
Fred Drakea4070ce1999-06-21 21:13:09 +0000829\end{methoddesc}
830
Fred Drakefd7f1152001-12-26 22:08:44 +0000831\begin{methoddesc}[window]{leaveok}{yes}
Eric S. Raymond68996602000-07-24 03:28:40 +0000832If \var{yes} is 1, cursor is left where it is on update, instead of
833being at ``cursor position.'' This reduces cursor movement where
834possible. If possible the cursor will be made invisible.
Fred Drakea4070ce1999-06-21 21:13:09 +0000835
Eric S. Raymond68996602000-07-24 03:28:40 +0000836If \var{yes} is 0, cursor will always be at ``cursor position'' after
837an update.
Fred Drakea4070ce1999-06-21 21:13:09 +0000838\end{methoddesc}
839
Fred Drakefd7f1152001-12-26 22:08:44 +0000840\begin{methoddesc}[window]{move}{new_y, new_x}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000841Move cursor to \code{(\var{new_y}, \var{new_x})}.
Fred Drakea4070ce1999-06-21 21:13:09 +0000842\end{methoddesc}
843
Fred Drakefd7f1152001-12-26 22:08:44 +0000844\begin{methoddesc}[window]{mvderwin}{y, x}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000845Moves the window inside its parent window. The screen-relative
846parameters of the window are not changed. This routine is used to
847display different parts of the parent window at the same physical
848position on the screen.
849\end{methoddesc}
Fred Drakea4070ce1999-06-21 21:13:09 +0000850
Fred Drakefd7f1152001-12-26 22:08:44 +0000851\begin{methoddesc}[window]{mvwin}{new_y, new_x}
Fred Drakee412e7a2000-12-21 17:04:31 +0000852Move the window so its upper-left corner is at
853\code{(\var{new_y}, \var{new_x})}.
Fred Drakea4070ce1999-06-21 21:13:09 +0000854\end{methoddesc}
855
Fred Drakefd7f1152001-12-26 22:08:44 +0000856\begin{methoddesc}[window]{nodelay}{yes}
Fred Drakee412e7a2000-12-21 17:04:31 +0000857If \var{yes} is \code{1}, \method{getch()} will be non-blocking.
Fred Drakea4070ce1999-06-21 21:13:09 +0000858\end{methoddesc}
859
Fred Drakefd7f1152001-12-26 22:08:44 +0000860\begin{methoddesc}[window]{notimeout}{yes}
Fred Drakee412e7a2000-12-21 17:04:31 +0000861If \var{yes} is \code{1}, escape sequences will not be timed out.
Fred Drakea4070ce1999-06-21 21:13:09 +0000862
Fred Drakee412e7a2000-12-21 17:04:31 +0000863If \var{yes} is \code{0}, after a few milliseconds, an escape sequence
864will not be interpreted, and will be left in the input stream as is.
Fred Drakea4070ce1999-06-21 21:13:09 +0000865\end{methoddesc}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000866
Fred Drakefd7f1152001-12-26 22:08:44 +0000867\begin{methoddesc}[window]{noutrefresh}{}
Eric S. Raymond65983372000-08-09 21:49:31 +0000868Mark for refresh but wait. This function updates the data structure
869representing the desired state of the window, but does not force
Eric S. Raymond3229b852001-01-29 06:39:33 +0000870an update of the physical screen. To accomplish that, call
871\function{doupdate()}.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000872\end{methoddesc}
873
Fred Drakefd7f1152001-12-26 22:08:44 +0000874\begin{methoddesc}[window]{overlay}{destwin\optional{, sminrow, smincol,
875 dminrow, dmincol, dmaxrow, dmaxcol}}
Andrew M. Kuchling68a6f5a2000-12-21 16:25:44 +0000876Overlay the window on top of \var{destwin}. The windows need not be
877the same size, only the overlapping region is copied. This copy is
878non-destructive, which means that the current background character
879does not overwrite the old contents of \var{destwin}.
880
881To get fine-grained control over the copied region, the second form
Fred Drakee412e7a2000-12-21 17:04:31 +0000882of \method{overlay()} can be used. \var{sminrow} and \var{smincol} are
Andrew M. Kuchling68a6f5a2000-12-21 16:25:44 +0000883the upper-left coordinates of the source window, and the other variables
884mark a rectangle in the destination window.
885\end{methoddesc}
886
Fred Drakefd7f1152001-12-26 22:08:44 +0000887\begin{methoddesc}[window]{overwrite}{destwin\optional{, sminrow, smincol,
888 dminrow, dmincol, dmaxrow, dmaxcol}}
Andrew M. Kuchling68a6f5a2000-12-21 16:25:44 +0000889Overwrite the window on top of \var{destwin}. The windows need not be
Fred Drakee412e7a2000-12-21 17:04:31 +0000890the same size, in which case only the overlapping region is
891copied. This copy is destructive, which means that the current
892background character overwrites the old contents of \var{destwin}.
Andrew M. Kuchling68a6f5a2000-12-21 16:25:44 +0000893
894To get fine-grained control over the copied region, the second form
Fred Drakee412e7a2000-12-21 17:04:31 +0000895of \method{overwrite()} can be used. \var{sminrow} and \var{smincol} are
Andrew M. Kuchling68a6f5a2000-12-21 16:25:44 +0000896the upper-left coordinates of the source window, the other variables
897mark a rectangle in the destination window.
898\end{methoddesc}
899
Fred Drakefd7f1152001-12-26 22:08:44 +0000900\begin{methoddesc}[window]{putwin}{file}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000901Writes all data associated with the window into the provided file
902object. This information can be later retrieved using the
903\function{getwin()} function.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000904\end{methoddesc}
905
Fred Drakefd7f1152001-12-26 22:08:44 +0000906\begin{methoddesc}[window]{redrawln}{beg, num}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000907Indicates that the \var{num} screen lines, starting at line \var{beg},
908are corrupted and should be completely redrawn on the next
909\method{refresh()} call.
910\end{methoddesc}
911
Fred Drakefd7f1152001-12-26 22:08:44 +0000912\begin{methoddesc}[window]{redrawwin}{}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000913Touches the entire window, causing it to be completely redrawn on the
914next \method{refresh()} call.
915\end{methoddesc}
916
Fred Drakefd7f1152001-12-26 22:08:44 +0000917\begin{methoddesc}[window]{refresh}{\optional{pminrow, pmincol, sminrow,
918 smincol, smaxrow, smaxcol}}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000919Update the display immediately (sync actual screen with previous
920drawing/deleting methods).
921
922The 6 optional arguments can only be specified when the window is a
923pad created with \function{newpad()}. The additional parameters are
924needed to indicate what part of the pad and screen are involved.
925\var{pminrow} and \var{pmincol} specify the upper left-hand corner of the
926rectangle to be displayed in the pad. \var{sminrow}, \var{smincol},
Fred Drakee412e7a2000-12-21 17:04:31 +0000927\var{smaxrow}, and \var{smaxcol} specify the edges of the rectangle to
928be displayed on the screen. The lower right-hand corner of the
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000929rectangle to be displayed in the pad is calculated from the screen
930coordinates, since the rectangles must be the same size. Both
931rectangles must be entirely contained within their respective
932structures. Negative values of \var{pminrow}, \var{pmincol},
933\var{sminrow}, or \var{smincol} are treated as if they were zero.
934\end{methoddesc}
935
Fred Drakefd7f1152001-12-26 22:08:44 +0000936\begin{methoddesc}[window]{scroll}{\optional{lines\code{ = 1}}}
Eric S. Raymond3229b852001-01-29 06:39:33 +0000937Scroll the screen or scrolling region upward by \var{lines} lines.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000938\end{methoddesc}
939
Fred Drakefd7f1152001-12-26 22:08:44 +0000940\begin{methoddesc}[window]{scrollok}{flag}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000941Controls what happens when the cursor of a window is moved off the
Eric S. Raymond68996602000-07-24 03:28:40 +0000942edge of the window or scrolling region, either as a result of a
943newline action on the bottom line, or typing the last character
944of the last line. If \var{flag} is false, the cursor is left
945on the bottom line. If \var{flag} is true, the window is
946scrolled up one line. Note that in order to get the physical
947scrolling effect on the terminal, it is also necessary to call
948\method{idlok()}.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000949\end{methoddesc}
950
Fred Drakefd7f1152001-12-26 22:08:44 +0000951\begin{methoddesc}[window]{setscrreg}{top, bottom}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000952Set the scrolling region from line \var{top} to line \var{bottom}. All
953scrolling actions will take place in this region.
954\end{methoddesc}
955
Fred Drakefd7f1152001-12-26 22:08:44 +0000956\begin{methoddesc}[window]{standend}{}
Eric S. Raymond68996602000-07-24 03:28:40 +0000957Turn off the standout attribute. On some terminals this has the
958side effect of turning off all attributes.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000959\end{methoddesc}
960
Fred Drakefd7f1152001-12-26 22:08:44 +0000961\begin{methoddesc}[window]{standout}{}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000962Turn on attribute \var{A_STANDOUT}.
963\end{methoddesc}
964
Fred Drakefd7f1152001-12-26 22:08:44 +0000965\begin{methoddesc}[window]{subpad}{\optional{nlines, ncols,} begin_y, begin_x}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000966Return a sub-window, whose upper-left corner is at
967\code{(\var{begin_y}, \var{begin_x})}, and whose width/height is
968\var{ncols}/\var{nlines}.
969\end{methoddesc}
970
Fred Drakefd7f1152001-12-26 22:08:44 +0000971\begin{methoddesc}[window]{subwin}{\optional{nlines, ncols,} begin_y, begin_x}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000972Return a sub-window, whose upper-left corner is at
973\code{(\var{begin_y}, \var{begin_x})}, and whose width/height is
974\var{ncols}/\var{nlines}.
975
976By default, the sub-window will extend from the
977specified position to the lower right corner of the window.
978\end{methoddesc}
979
Fred Drakefd7f1152001-12-26 22:08:44 +0000980\begin{methoddesc}[window]{syncdown}{}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000981Touches each location in the window that has been touched in any of
982its ancestor windows. This routine is called by \method{refresh()},
983so it should almost never be necessary to call it manually.
984\end{methoddesc}
985
Fred Drakefd7f1152001-12-26 22:08:44 +0000986\begin{methoddesc}[window]{syncok}{flag}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000987If called with \var{flag} set to true, then \method{syncup()} is
988called automatically whenever there is a change in the window.
989\end{methoddesc}
990
Fred Drakefd7f1152001-12-26 22:08:44 +0000991\begin{methoddesc}[window]{syncup}{}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000992Touches all locations in ancestors of the window that have been changed in
993the window.
994\end{methoddesc}
995
Fred Drakefd7f1152001-12-26 22:08:44 +0000996\begin{methoddesc}[window]{timeout}{delay}
Thomas Woutersf8316632000-07-16 19:01:10 +0000997Sets blocking or non-blocking read behavior for the window. If
Andrew M. Kuchlingd24ff442000-06-21 01:42:51 +0000998\var{delay} is negative, blocking read is used, which will wait
999indefinitely for input). If \var{delay} is zero, then non-blocking
1000read is used, and -1 will be returned by \method{getch()} if no input
1001is waiting. If \var{delay} is positive, then \method{getch()} will
1002block for \var{delay} milliseconds, and return -1 if there is still no
1003input at the end of that time.
1004\end{methoddesc}
1005
Fred Drakefd7f1152001-12-26 22:08:44 +00001006\begin{methoddesc}[window]{touchline}{start, count}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001007Pretend \var{count} lines have been changed, starting with line
1008\var{start}.
1009\end{methoddesc}
1010
Fred Drakefd7f1152001-12-26 22:08:44 +00001011\begin{methoddesc}[window]{touchwin}{}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001012Pretend the whole window has been changed, for purposes of drawing
1013optimizations.
1014\end{methoddesc}
1015
Fred Drakefd7f1152001-12-26 22:08:44 +00001016\begin{methoddesc}[window]{untouchwin}{}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001017Marks all lines in the window as unchanged since the last call to
1018\method{refresh()}.
1019\end{methoddesc}
1020
Fred Drakefd7f1152001-12-26 22:08:44 +00001021\begin{methoddesc}[window]{vline}{\optional{y, x,} ch, n}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001022Display a vertical line starting at \code{(\var{y}, \var{x})} with
1023length \var{n} consisting of the character \var{ch}.
1024\end{methoddesc}
1025
1026\subsection{Constants}
1027
1028The \module{curses} module defines the following data members:
1029
Andrew M. Kuchlinge6bf8582000-12-26 15:58:27 +00001030\begin{datadesc}{ERR}
1031Some curses routines that return an integer, such as
Fred Drake22e9a5e2001-01-04 05:14:45 +00001032\function{getch()}, return \constant{ERR} upon failure.
Andrew M. Kuchlinge6bf8582000-12-26 15:58:27 +00001033\end{datadesc}
1034
1035\begin{datadesc}{OK}
1036Some curses routines that return an integer, such as
Fred Drake22e9a5e2001-01-04 05:14:45 +00001037\function{napms()}, return \constant{OK} upon success.
Andrew M. Kuchlinge6bf8582000-12-26 15:58:27 +00001038\end{datadesc}
1039
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001040\begin{datadesc}{version}
1041A string representing the current version of the module.
1042Also available as \constant{__version__}.
1043\end{datadesc}
1044
Fred Drakeec4b2af2000-08-09 14:34:48 +00001045Several constants are available to specify character cell attributes:
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001046
Fred Drakeec4b2af2000-08-09 14:34:48 +00001047\begin{tableii}{l|l}{code}{Attribute}{Meaning}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001048 \lineii{A_ALTCHARSET}{Alternate character set mode.}
1049 \lineii{A_BLINK}{Blink mode.}
1050 \lineii{A_BOLD}{Bold mode.}
1051 \lineii{A_DIM}{Dim mode.}
1052 \lineii{A_NORMAL}{Normal attribute.}
1053 \lineii{A_STANDOUT}{Standout mode.}
1054 \lineii{A_UNDERLINE}{Underline mode.}
1055\end{tableii}
1056
1057Keys are referred to by integer constants with names starting with
Fred Drakeec4b2af2000-08-09 14:34:48 +00001058\samp{KEY_}. The exact keycaps available are system dependent.
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001059
1060% XXX this table is far too large!
1061% XXX should this table be alphabetized?
1062
Fred Drake1bf4e932000-09-21 16:04:08 +00001063\begin{longtableii}{l|l}{code}{Key constant}{Key}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001064 \lineii{KEY_MIN}{Minimum key value}
1065 \lineii{KEY_BREAK}{ Break key (unreliable) }
1066 \lineii{KEY_DOWN}{ Down-arrow }
1067 \lineii{KEY_UP}{ Up-arrow }
1068 \lineii{KEY_LEFT}{ Left-arrow }
1069 \lineii{KEY_RIGHT}{ Right-arrow }
1070 \lineii{KEY_HOME}{ Home key (upward+left arrow) }
1071 \lineii{KEY_BACKSPACE}{ Backspace (unreliable) }
1072 \lineii{KEY_F0}{ Function keys. Up to 64 function keys are supported. }
1073 \lineii{KEY_F\var{n}}{ Value of function key \var{n} }
1074 \lineii{KEY_DL}{ Delete line }
1075 \lineii{KEY_IL}{ Insert line }
1076 \lineii{KEY_DC}{ Delete character }
1077 \lineii{KEY_IC}{ Insert char or enter insert mode }
1078 \lineii{KEY_EIC}{ Exit insert char mode }
1079 \lineii{KEY_CLEAR}{ Clear screen }
1080 \lineii{KEY_EOS}{ Clear to end of screen }
1081 \lineii{KEY_EOL}{ Clear to end of line }
1082 \lineii{KEY_SF}{ Scroll 1 line forward }
1083 \lineii{KEY_SR}{ Scroll 1 line backward (reverse) }
1084 \lineii{KEY_NPAGE}{ Next page }
1085 \lineii{KEY_PPAGE}{ Previous page }
1086 \lineii{KEY_STAB}{ Set tab }
1087 \lineii{KEY_CTAB}{ Clear tab }
1088 \lineii{KEY_CATAB}{ Clear all tabs }
1089 \lineii{KEY_ENTER}{ Enter or send (unreliable) }
1090 \lineii{KEY_SRESET}{ Soft (partial) reset (unreliable) }
1091 \lineii{KEY_RESET}{ Reset or hard reset (unreliable) }
1092 \lineii{KEY_PRINT}{ Print }
1093 \lineii{KEY_LL}{ Home down or bottom (lower left) }
1094 \lineii{KEY_A1}{ Upper left of keypad }
1095 \lineii{KEY_A3}{ Upper right of keypad }
1096 \lineii{KEY_B2}{ Center of keypad }
1097 \lineii{KEY_C1}{ Lower left of keypad }
1098 \lineii{KEY_C3}{ Lower right of keypad }
1099 \lineii{KEY_BTAB}{ Back tab }
1100 \lineii{KEY_BEG}{ Beg (beginning) }
1101 \lineii{KEY_CANCEL}{ Cancel }
1102 \lineii{KEY_CLOSE}{ Close }
1103 \lineii{KEY_COMMAND}{ Cmd (command) }
1104 \lineii{KEY_COPY}{ Copy }
1105 \lineii{KEY_CREATE}{ Create }
1106 \lineii{KEY_END}{ End }
1107 \lineii{KEY_EXIT}{ Exit }
1108 \lineii{KEY_FIND}{ Find }
1109 \lineii{KEY_HELP}{ Help }
1110 \lineii{KEY_MARK}{ Mark }
1111 \lineii{KEY_MESSAGE}{ Message }
1112 \lineii{KEY_MOVE}{ Move }
1113 \lineii{KEY_NEXT}{ Next }
1114 \lineii{KEY_OPEN}{ Open }
1115 \lineii{KEY_OPTIONS}{ Options }
1116 \lineii{KEY_PREVIOUS}{ Prev (previous) }
1117 \lineii{KEY_REDO}{ Redo }
1118 \lineii{KEY_REFERENCE}{ Ref (reference) }
1119 \lineii{KEY_REFRESH}{ Refresh }
1120 \lineii{KEY_REPLACE}{ Replace }
1121 \lineii{KEY_RESTART}{ Restart }
1122 \lineii{KEY_RESUME}{ Resume }
1123 \lineii{KEY_SAVE}{ Save }
1124 \lineii{KEY_SBEG}{ Shifted Beg (beginning) }
1125 \lineii{KEY_SCANCEL}{ Shifted Cancel }
1126 \lineii{KEY_SCOMMAND}{ Shifted Command }
1127 \lineii{KEY_SCOPY}{ Shifted Copy }
1128 \lineii{KEY_SCREATE}{ Shifted Create }
1129 \lineii{KEY_SDC}{ Shifted Delete char }
1130 \lineii{KEY_SDL}{ Shifted Delete line }
1131 \lineii{KEY_SELECT}{ Select }
1132 \lineii{KEY_SEND}{ Shifted End }
1133 \lineii{KEY_SEOL}{ Shifted Clear line }
1134 \lineii{KEY_SEXIT}{ Shifted Dxit }
1135 \lineii{KEY_SFIND}{ Shifted Find }
1136 \lineii{KEY_SHELP}{ Shifted Help }
1137 \lineii{KEY_SHOME}{ Shifted Home }
1138 \lineii{KEY_SIC}{ Shifted Input }
1139 \lineii{KEY_SLEFT}{ Shifted Left arrow }
1140 \lineii{KEY_SMESSAGE}{ Shifted Message }
1141 \lineii{KEY_SMOVE}{ Shifted Move }
1142 \lineii{KEY_SNEXT}{ Shifted Next }
1143 \lineii{KEY_SOPTIONS}{ Shifted Options }
1144 \lineii{KEY_SPREVIOUS}{ Shifted Prev }
1145 \lineii{KEY_SPRINT}{ Shifted Print }
1146 \lineii{KEY_SREDO}{ Shifted Redo }
1147 \lineii{KEY_SREPLACE}{ Shifted Replace }
1148 \lineii{KEY_SRIGHT}{ Shifted Right arrow }
1149 \lineii{KEY_SRSUME}{ Shifted Resume }
1150 \lineii{KEY_SSAVE}{ Shifted Save }
1151 \lineii{KEY_SSUSPEND}{ Shifted Suspend }
1152 \lineii{KEY_SUNDO}{ Shifted Undo }
1153 \lineii{KEY_SUSPEND}{ Suspend }
1154 \lineii{KEY_UNDO}{ Undo }
1155 \lineii{KEY_MOUSE}{ Mouse event has occurred }
1156 \lineii{KEY_RESIZE}{ Terminal resize event }
1157 \lineii{KEY_MAX}{Maximum key value}
Fred Drake1bf4e932000-09-21 16:04:08 +00001158\end{longtableii}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001159
Fred Drakeec4b2af2000-08-09 14:34:48 +00001160On VT100s and their software emulations, such as X terminal emulators,
1161there are normally at least four function keys (\constant{KEY_F1},
1162\constant{KEY_F2}, \constant{KEY_F3}, \constant{KEY_F4}) available,
1163and the arrow keys mapped to \constant{KEY_UP}, \constant{KEY_DOWN},
1164\constant{KEY_LEFT} and \constant{KEY_RIGHT} in the obvious way. If
1165your machine has a PC keybboard, it is safe to expect arrow keys and
1166twelve function keys (older PC keyboards may have only ten function
1167keys); also, the following keypad mappings are standard:
Eric S. Raymondb924bd42000-07-27 21:10:02 +00001168
Fred Drakeec4b2af2000-08-09 14:34:48 +00001169\begin{tableii}{l|l}{kbd}{Keycap}{Constant}
Eric S. Raymondb924bd42000-07-27 21:10:02 +00001170 \lineii{Insert}{KEY_IC}
1171 \lineii{Delete}{KEY_DC}
1172 \lineii{Home}{KEY_HOME}
1173 \lineii{End}{KEY_END}
1174 \lineii{Page Up}{KEY_NPAGE}
1175 \lineii{Page Down}{KEY_PPAGE}
1176\end{tableii}
1177
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001178The following table lists characters from the alternate character set.
Eric S. Raymondb924bd42000-07-27 21:10:02 +00001179These are inherited from the VT100 terminal, and will generally be
1180available on software emulations such as X terminals. When there
1181is no graphic available, curses falls back on a crude printable ASCII
1182approximation.
Fred Drake0aa811c2001-10-20 04:24:09 +00001183\note{These are available only after \function{initscr()} has
1184been called.}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001185
Fred Drake1bf4e932000-09-21 16:04:08 +00001186\begin{longtableii}{l|l}{code}{ACS code}{Meaning}
Eric S. Raymondb924bd42000-07-27 21:10:02 +00001187 \lineii{ACS_BBSS}{alternate name for upper right corner}
Eric S. Raymond68996602000-07-24 03:28:40 +00001188 \lineii{ACS_BLOCK}{solid square block}
1189 \lineii{ACS_BOARD}{board of squares}
Eric S. Raymondb924bd42000-07-27 21:10:02 +00001190 \lineii{ACS_BSBS}{alternate name for horizontal line}
1191 \lineii{ACS_BSSB}{alternate name for upper left corner}
1192 \lineii{ACS_BSSS}{alternate name for top tee}
Eric S. Raymond68996602000-07-24 03:28:40 +00001193 \lineii{ACS_BTEE}{bottom tee}
1194 \lineii{ACS_BULLET}{bullet}
1195 \lineii{ACS_CKBOARD}{checker board (stipple)}
1196 \lineii{ACS_DARROW}{arrow pointing down}
1197 \lineii{ACS_DEGREE}{degree symbol}
1198 \lineii{ACS_DIAMOND}{diamond}
1199 \lineii{ACS_GEQUAL}{greater-than-or-equal-to}
1200 \lineii{ACS_HLINE}{horizontal line}
1201 \lineii{ACS_LANTERN}{lantern symbol}
1202 \lineii{ACS_LARROW}{left arrow}
1203 \lineii{ACS_LEQUAL}{less-than-or-equal-to}
1204 \lineii{ACS_LLCORNER}{lower left-hand corner}
1205 \lineii{ACS_LRCORNER}{lower right-hand corner}
1206 \lineii{ACS_LTEE}{left tee}
1207 \lineii{ACS_NEQUAL}{not-equal sign}
1208 \lineii{ACS_PI}{letter pi}
1209 \lineii{ACS_PLMINUS}{plus-or-minus sign}
Eric S. Raymondb924bd42000-07-27 21:10:02 +00001210 \lineii{ACS_PLUS}{big plus sign}
Eric S. Raymond68996602000-07-24 03:28:40 +00001211 \lineii{ACS_RARROW}{right arrow}
1212 \lineii{ACS_RTEE}{right tee}
1213 \lineii{ACS_S1}{scan line 1}
1214 \lineii{ACS_S3}{scan line 3}
1215 \lineii{ACS_S7}{scan line 7}
1216 \lineii{ACS_S9}{scan line 9}
Eric S. Raymondb924bd42000-07-27 21:10:02 +00001217 \lineii{ACS_SBBS}{alternate name for lower right corner}
1218 \lineii{ACS_SBSB}{alternate name for vertical line}
1219 \lineii{ACS_SBSS}{alternate name for right tee}
1220 \lineii{ACS_SSBB}{alternate name for lower left corner}
1221 \lineii{ACS_SSBS}{alternate name for bottom tee}
1222 \lineii{ACS_SSSB}{alternate name for left tee}
1223 \lineii{ACS_SSSS}{alternate name for crossover or big plus}
Eric S. Raymond68996602000-07-24 03:28:40 +00001224 \lineii{ACS_STERLING}{pound sterling}
1225 \lineii{ACS_TTEE}{top tee}
1226 \lineii{ACS_UARROW}{up arrow}
1227 \lineii{ACS_ULCORNER}{upper left corner}
1228 \lineii{ACS_URCORNER}{upper right corner}
1229 \lineii{ACS_VLINE}{vertical line}
Fred Drake1bf4e932000-09-21 16:04:08 +00001230\end{longtableii}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001231
1232The following table lists the predefined colors:
1233
Fred Drakeec4b2af2000-08-09 14:34:48 +00001234\begin{tableii}{l|l}{code}{Constant}{Color}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +00001235 \lineii{COLOR_BLACK}{Black}
1236 \lineii{COLOR_BLUE}{Blue}
1237 \lineii{COLOR_CYAN}{Cyan (light greenish blue)}
1238 \lineii{COLOR_GREEN}{Green}
1239 \lineii{COLOR_MAGENTA}{Magenta (purplish red)}
1240 \lineii{COLOR_RED}{Red}
1241 \lineii{COLOR_WHITE}{White}
1242 \lineii{COLOR_YELLOW}{Yellow}
1243\end{tableii}
1244
Eric S. Raymond5a007692000-08-04 07:35:41 +00001245\section{\module{curses.textpad} ---
1246 Text input widget for curses programs}
1247
1248\declaremodule{standard}{curses.textpad}
1249\sectionauthor{Eric Raymond}{esr@thyrsus.com}
1250\moduleauthor{Eric Raymond}{esr@thyrsus.com}
1251\modulesynopsis{Emacs-like input editing in a curses window.}
1252\versionadded{1.6}
1253
1254The \module{curses.textpad} module provides a \class{Textbox} class
1255that handles elementary text editing in a curses window, supporting a
1256set of keybindings resembling those of Emacs (thus, also of Netscape
1257Navigator, BBedit 6.x, FrameMaker, and many other programs). The
1258module also provides a rectangle-drawing function useful for framing
1259text boxes or for other purposes.
1260
Fred Drakeec4b2af2000-08-09 14:34:48 +00001261The module \module{curses.textpad} defines the following function:
Eric S. Raymond5a007692000-08-04 07:35:41 +00001262
1263\begin{funcdesc}{rectangle}{win, uly, ulx, lry, lrx}
1264Draw a rectangle. The first argument must be a window object; the
1265remaining arguments are coordinates relative to that window. The
1266second and third arguments are the y and x coordinates of the upper
1267left hand corner of the rectangle To be drawn; the fourth and fifth
1268arguments are the y and x coordinates of the lower right hand corner.
1269The rectangle will be drawn using VT100/IBM PC forms characters on
1270terminals that make this possible (including xterm and most other
1271software terminal emulators). Otherwise it will be drawn with ASCII
1272dashes, vertical bars, and plus signs.
1273\end{funcdesc}
1274
Fred Drakeec4b2af2000-08-09 14:34:48 +00001275
Eric S. Raymond5a007692000-08-04 07:35:41 +00001276\subsection{Textbox objects \label{curses-textpad-objects}}
1277
1278You can instantiate a \class{Textbox} object as follows:
1279
Fred Drakeec4b2af2000-08-09 14:34:48 +00001280\begin{classdesc}{Textbox}{win}
1281Return a textbox widget object. The \var{win} argument should be a
1282curses \class{WindowObject} in which the textbox is to be contained.
1283The edit cursor of the textbox is initially located at the upper left
1284hand corner of the containin window, with coordinates \code{(0, 0)}.
1285The instance's \member{stripspaces} flag is initially on.
Eric S. Raymond5a007692000-08-04 07:35:41 +00001286\end{classdesc}
1287
Fred Drakeec4b2af2000-08-09 14:34:48 +00001288\class{Textbox} objects have the following methods:
Eric S. Raymond5a007692000-08-04 07:35:41 +00001289
Fred Drakeec4b2af2000-08-09 14:34:48 +00001290\begin{methoddesc}{edit}{\optional{validator}}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001291This is the entry point you will normally use. It accepts editing
Fred Drakeec4b2af2000-08-09 14:34:48 +00001292keystrokes until one of the termination keystrokes is entered. If
1293\var{validator} is supplied, it must be a function. It will be called
1294for each keystroke entered with the keystroke as a parameter; command
1295dispatch is done on the result. This method returns the window
1296contents as a string; whether blanks in the window are included is
1297affected by the \member{stripspaces} member.
Eric S. Raymond5a007692000-08-04 07:35:41 +00001298\end{methoddesc}
1299
1300\begin{methoddesc}{do_command}{ch}
1301Process a single command keystroke. Here are the supported special
1302keystrokes:
1303
Fred Drakeec4b2af2000-08-09 14:34:48 +00001304\begin{tableii}{l|l}{kbd}{Keystroke}{Action}
Fred Drake682d5f32001-07-12 02:09:51 +00001305 \lineii{Control-A}{Go to left edge of window.}
1306 \lineii{Control-B}{Cursor left, wrapping to previous line if appropriate.}
1307 \lineii{Control-D}{Delete character under cursor.}
1308 \lineii{Control-E}{Go to right edge (stripspaces off) or end of line
Fred Drakee412e7a2000-12-21 17:04:31 +00001309 (stripspaces on).}
Fred Drake682d5f32001-07-12 02:09:51 +00001310 \lineii{Control-F}{Cursor right, wrapping to next line when appropriate.}
1311 \lineii{Control-G}{Terminate, returning the window contents.}
1312 \lineii{Control-H}{Delete character backward.}
1313 \lineii{Control-J}{Terminate if the window is 1 line, otherwise
1314 insert newline.}
1315 \lineii{Control-K}{If line is blank, delete it, otherwise clear to
1316 end of line.}
1317 \lineii{Control-L}{Refresh screen.}
1318 \lineii{Control-N}{Cursor down; move down one line.}
1319 \lineii{Control-O}{Insert a blank line at cursor location.}
1320 \lineii{Control-P}{Cursor up; move up one line.}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001321\end{tableii}
1322
1323Move operations do nothing if the cursor is at an edge where the
1324movement is not possible. The following synonyms are supported where
Fred Drakeec4b2af2000-08-09 14:34:48 +00001325possible:
1326
1327\begin{tableii}{l|l}{constant}{Constant}{Keystroke}
Fred Drake682d5f32001-07-12 02:09:51 +00001328 \lineii{KEY_LEFT}{\kbd{Control-B}}
1329 \lineii{KEY_RIGHT}{\kbd{Control-F}}
1330 \lineii{KEY_UP}{\kbd{Control-P}}
1331 \lineii{KEY_DOWN}{\kbd{Control-N}}
1332 \lineii{KEY_BACKSPACE}{\kbd{Control-h}}
Fred Drakeec4b2af2000-08-09 14:34:48 +00001333\end{tableii}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001334
1335All other keystrokes are treated as a command to insert the given
1336character and move right (with line wrapping).
1337\end{methoddesc}
1338
1339\begin{methoddesc}{gather}{}
1340This method returns the window contents as a string; whether blanks in
1341the window are included is affected by the \member{stripspaces}
1342member.
1343\end{methoddesc}
1344
Fred Drakeec4b2af2000-08-09 14:34:48 +00001345\begin{memberdesc}{stripspaces}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001346This data member is a flag which controls the interpretation of blanks in
1347the window. When it is on, trailing blanks on each line are ignored;
1348any cursor motion that would land the cursor on a trailing blank goes
1349to the end of that line instead, and trailing blanks are stripped when
1350the window contents is gathered.
Fred Drakeec4b2af2000-08-09 14:34:48 +00001351\end{memberdesc}
1352
Eric S. Raymond5a007692000-08-04 07:35:41 +00001353
1354\section{\module{curses.wrapper} ---
Fred Drakeec4b2af2000-08-09 14:34:48 +00001355 Terminal handler for curses programs}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001356
1357\declaremodule{standard}{curses.wrapper}
1358\sectionauthor{Eric Raymond}{esr@thyrsus.com}
1359\moduleauthor{Eric Raymond}{esr@thyrsus.com}
Fred Drakeec4b2af2000-08-09 14:34:48 +00001360\modulesynopsis{Terminal configuration wrapper for curses programs.}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001361\versionadded{1.6}
1362
1363This module supplies one function, \function{wrapper()}, which runs
1364another function which should be the rest of your curses-using
1365application. If the application raises an exception,
1366\function{wrapper()} will restore the terminal to a sane state before
1367passing it further up the stack and generating a traceback.
1368
Fred Drakeec4b2af2000-08-09 14:34:48 +00001369\begin{funcdesc}{wrapper}{func, \moreargs}
Eric S. Raymond5a007692000-08-04 07:35:41 +00001370Wrapper function that initializes curses and calls another function,
Fred Drakeec4b2af2000-08-09 14:34:48 +00001371\var{func}, restoring normal keyboard/screen behavior on error.
1372The callable object \var{func} is then passed the main window 'stdscr'
Eric S. Raymond5a007692000-08-04 07:35:41 +00001373as its first argument, followed by any other arguments passed to
1374\function{wrapper()}.
1375\end{funcdesc}
1376
Eric S. Raymond1ebd3f62000-08-09 21:11:07 +00001377Before calling the hook function, \function{wrapper()} turns on cbreak
1378mode, turns off echo, enables the terminal keypad, and initializes
1379colors if the terminal has color support. On exit (whether normally
1380or by exception) it restores cooked mode, turns on echo, and disables
1381the terminal keypad.
Eric S. Raymond5a007692000-08-04 07:35:41 +00001382