blob: e35c7318d4f8af23e57ffb23d0aa33e822d715e0 [file] [log] [blame]
Fred Drakea4070ce1999-06-21 21:13:09 +00001\section{\module{curses} ---
2 Terminal independant console handling}
3
4\declaremodule{extension}{curses}
5\sectionauthor{Moshe Zadka}{mzadka@geocities.com}
6\modulesynopsis{An interface to the curses library.}
7
8The \module{curses} module provides an interface to the curses \UNIX{}
9library, the de-facto standard for portable advanced terminal
10handling.
11
12While curses is most widely used in the \UNIX{} environment, versions
13are available for DOS, OS/2, and possibly other systems as well. The
14extension module has not been tested with all available versions of
15curses.
16
17\begin{seealso}
18 \seetext{Tutorial material on using curses with Python is available
Fred Drake37f15741999-11-10 16:21:37 +000019 on the Python Web site as Andrew Kuchling's
20\citetitle[http://www.python.org/doc/howto/curses/curses.html]{Curses
Fred Drakea4070ce1999-06-21 21:13:09 +000021 Programming with Python}, at
22 \url{http://www.python.org/doc/howto/curses/curses.html}.}
23\end{seealso}
24
25
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000026\subsection{Functions \label{curses-functions}}
Fred Drakea4070ce1999-06-21 21:13:09 +000027
28The module \module{curses} defines the following exception:
29\begin{excdesc}{error}
30Curses function returned an error status.
31\end{excdesc}
32
Fred Drake0bccd731999-06-23 17:28:01 +000033\strong{Note:} Whenever \var{x} or \var{y} arguments to a function
34or a method are optional, they default to the current cursor location.
35Whenever \var{attr} is optional, it defaults to \constant{A_NORMAL}.
36
Fred Drakea4070ce1999-06-21 21:13:09 +000037The module \module{curses} defines the following functions:
38
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +000039\begin{funcdesc}{baudrate}{}
40Returns the output speed of the terminal in bits per second.
41\end{funcdesc}
42
43\begin{funcdesc}{beep}{}
44Emit a short sound.
45\end{funcdesc}
46
47\begin{funcdesc}{can_change_color}{}
48Returns true or false, depending on whether the programmer can change
49the colors displayed by the terminal.
50\end{funcdesc}
51
52\begin{funcdesc}{cbreak}{}
53Enter cbreak mode.
54\end{funcdesc}
55
56\begin{funcdesc}{color_content}{color_number}
57Returns the intensity of the red, green, and blue (RGB) components in
58the color \var{color_number}, which must be between 0 and COLORS. A
593-tuple is returned, containing the R,G,B values for the given color,
60which will be between 0 (no component) and 1000 (maximum amount of
61component).
62\end{funcdesc}
63
64\begin{funcdesc}{color_pair}{color_number}
65Returns the attribute value for displaying text in the specified
66color. This attribute value can be combined with
67\constant{A_STANDOUT}, \constant{A_REVERSE}, and the other
68\constant{A_*} attributes. \function{pair_number()} is the counterpart to this function.
69\end{funcdesc}
70
71\begin{funcdesc}{curs_set}{visibility}
72Sets the cursor state. \var{visibility} can be set to 0, 1, or 2, for
73invisible, normal, or very visible. If the terminal supports the
74visibility requested, the previous cursor state is returned;
75otherwise, an exception is raised.
76\end{funcdesc}
77
78\begin{funcdesc}{def_prog_mode}{}
79Saves the current terminal mode as the ``program'' mode, the mode when
80the running program is using curses. (Its counterpart is the
81``shell'' mode, for when the program is not in curses.) Subsequent calls
82to \function{reset_prog_mode()} will restore this mode.
83\end{funcdesc}
84
85\begin{funcdesc}{def_shell_mode}{}
86Saves the current terminal mode as the ``shell'' mode, the mode when
87the running program is not using curses. (Its counterpart is the
88``program'' mode, when the program is using curses capabilities.)
89Subsequent calls
90to \function{reset_shell_mode()} will restore this mode.
91\end{funcdesc}
92
93\begin{funcdesc}{delay_output}{ms}
94Inserts an \var{ms} millisecond pause in output.
95\end{funcdesc}
96
97\begin{funcdesc}{doupdate}{}
98Update the screen.
99\end{funcdesc}
100
101\begin{funcdesc}{echo}{}
102Enter echo mode.
Fred Drakea4070ce1999-06-21 21:13:09 +0000103\end{funcdesc}
104
105\begin{funcdesc}{endwin}{}
106De-initialize the library, and return terminal to normal status.
107\end{funcdesc}
108
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000109\begin{funcdesc}{erasechar}{}
110Returns the user's current erase character.
111\end{funcdesc}
112
113\begin{funcdesc}{filter}{}
114The \function{filter()} routine, if used, must be called before
115\function{initscr()} is called.
116
117The effect is that, during those calls, LINES is set to 1; the
118capabilities clear, cup, cud, cud1, cuu1, cuu, vpa are disabled; and
119the home string is set to the value of cr.
120\end{funcdesc}
121
122\begin{funcdesc}{flash}{}
123Flash the screen.
124\end{funcdesc}
125
126\begin{funcdesc}{flushinp}{}
127Flush all input buffers.
128\end{funcdesc}
129
130\begin{funcdesc}{getsyx}{}
131Returns the current coordinates of the virtual screen cursor in y and
132x. If leaveok is currently true, then -1,-1 is returned.
133\end{funcdesc}
134
135\begin{funcdesc}{getwin}{file}
136Reads window related data stored in the file by an earlier
137\function{putwin()} call. The routine then creates and initializes a
138new window using that data, returning the new window object.
139\end{funcdesc}
140
141\begin{funcdesc}{has_colors}{}
142Returns true if the terminal can manipulate colors; otherwise, it
143returns false.
144\end{funcdesc}
145
146\begin{funcdesc}{has_ic}{}
147Returns true if the terminal has insert- and delete- character
148capabilities.
149\end{funcdesc}
150
151\begin{funcdesc}{has_il}{}
152Returns true if the terminal has insert- and
153delete-line capabilities, or can simulate them using
154scrolling regions.
155\end{funcdesc}
156
157\begin{funcdesc}{has_key}{ch}
158Takes a key value \var{ch}, and returns true if the current terminal
159type recognizes a key with that value.
160\end{funcdesc}
161
162\begin{funcdesc}{halfdelay}{tenths}
163Used for half-delay mode, which is similar to cbreak mode in that
164characters typed by the user are immediately available to the program.
165However, after blocking for \var{tenths} tenths of seconds, an
166exception is raised if nothing has been typed. The value of
167\var{tenths} must be a number between 1 and 255. Use nocbreak to
168leave half-delay mode.
169\end{funcdesc}
170
171\begin{funcdesc}{init_color}{color_number, r, g, b}
172Changes the definition of a color, taking the number of the color to
173be changed followed by three RGB values (for the amounts of red,
174green, and blue components). The value of \var{color_number} must be
175between 0 and COLORS. Each of \var{r}, \var{g}, \var{b}, must be a
176value between 0 and 1000. When \function{init_color()} is used, all
177occurrences of that color on the screen immediately change to the new
178definition.
179\end{funcdesc}
180
181\begin{funcdesc}{init_pair}{pair_number, fg, bg}
182Changes the definition of a color-pair. It takes three arguments: the
183number of the color-pair to be changed, the foreground color number,
184and the background color number. The value of \var{pair_number} must
185be between 1 and COLOR_PAIRS-1 (the 0 color pair is wired to white on
186black and cannot be changed). The value of \var{fg} and \var{bg}
187arguments must be between 0 and COLORS. If the color-pair was
188previously initialized, the screen is refreshed and all occurrences of
189that color-pair are changed to the new definition.
190\end{funcdesc}
191
192\begin{funcdesc}{initscr}{}
193Initialize the library. Returns a \class{WindowObject} which represents
194the whole screen.
195\end{funcdesc}
196
Fred Drakea4070ce1999-06-21 21:13:09 +0000197\begin{funcdesc}{isendwin}{}
198Returns true if \function{endwin()} has been called.
199\end{funcdesc}
200
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000201\begin{funcdesc}{keyname}{k}
202Return the name of the key numbered \var{k}.
203\end{funcdesc}
204
205\begin{funcdesc}{killchar}{}
206Returns the user's current line kill character.
207\end{funcdesc}
208
209\begin{funcdesc}{longname}{}
210Returns a string containing a verbose description of the current
211terminal. The maximum length of a verbose description is 128
212characters. It is defined only after the call to
213\function{initscr()}.
214\end{funcdesc}
215
216\begin{funcdesc}{meta}{yes}
217If \var{yes} is 1, allow 8-bit characters. If \var{yes} is 0,
218allow only 7-bit chars.
219\end{funcdesc}
220
221\begin{funcdesc}{newpad}{nlines, ncols}
222Creates and returns a pointer to a new pad data structure with the
223given number of lines and columns. A pad is returned as a
224window object.
225
226A pad is like a window,
227except that it is not restricted by the screen size, and is not
228necessarily associated with a particular part of the screen.
229Pads can be used when a large window is needed, and only a part
230of the window will be on the screen at one time. Automatic
231refreshes of pads (e.g., from scrolling or echoing of
232 input) do not occur. It is not legal to call wrefresh
233 with a pad as an argument; the routines prefresh or
234 pnoutrefresh should be called instead. Note that these
235 routines require additional parameters to specify the part of
236 the pad to be displayed and the location on the screen to be
237 used for the display.
238
Fred Drakea4070ce1999-06-21 21:13:09 +0000239\end{funcdesc}
240
241\begin{funcdesc}{newwin}{\optional{nlines, ncols,} begin_y, begin_x}
242Return a new window, whose left-upper corner is at
243\code{(\var{begin_y}, \var{begin_x})}, and whose height/width is
Fred Drake0bccd731999-06-23 17:28:01 +0000244\var{nlines}/\var{ncols}.
245
246By default, the window will extend from the
Fred Drakea4070ce1999-06-21 21:13:09 +0000247specified position to the lower right corner of the screen.
248\end{funcdesc}
249
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000250\begin{funcdesc}{nl}{}
251Enter nl mode.
Fred Drakea4070ce1999-06-21 21:13:09 +0000252\end{funcdesc}
253
254\begin{funcdesc}{nocbreak}{}
255Leave cbreak mode.
256\end{funcdesc}
257
Fred Drakea4070ce1999-06-21 21:13:09 +0000258\begin{funcdesc}{noecho}{}
259Leave echo mode.
260\end{funcdesc}
261
Fred Drakea4070ce1999-06-21 21:13:09 +0000262\begin{funcdesc}{nonl}{}
263Leave nl mode.
264\end{funcdesc}
265
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000266\begin{funcdesc}{noqiflush}{}
267 When the noqiflush routine is used, normal flush of input and
268 output queues associated with the INTR, QUIT and SUSP
269 characters will not be done. You may want to call
270 \function{noqiflush()} in a signal handler if you want output
271 to continue as though the interrupt had not occurred, after the
272 handler exits.
Fred Drakea4070ce1999-06-21 21:13:09 +0000273\end{funcdesc}
274
275\begin{funcdesc}{noraw}{}
276Leave raw mode.
277\end{funcdesc}
278
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000279\begin{funcdesc}{pair_content}{pair_number}
280Returns a tuple \var{(fg,bg)} containing the colors for the requested
281color pair. The value of \var{pair_number} must be between 0 and
282COLOR_PAIRS-1.
Fred Drakea4070ce1999-06-21 21:13:09 +0000283\end{funcdesc}
284
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000285\begin{funcdesc}{pair_number}{attr}
286Returns the number of the color-pair set by the attribute value \var{attr}.
287\function{color_pair()} is the counterpart to this function.
Fred Drakea4070ce1999-06-21 21:13:09 +0000288\end{funcdesc}
289
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000290\begin{funcdesc}{putp}{string}
291Equivalent to \code{tputs(str, 1, putchar)}. Note that the output of putp always
292goes to standard output.
293\end{funcdesc}
294
295\begin{funcdesc}{qiflush}{ \optional{flag} }
296If \var{flag} is false, the effect is the same as calling
297\function{noqiflush()}. If \var{flag} is true, or no argument is
298provided, the queues will be flushed when these control characters are
299read.
300\end{funcdesc}
301
302\begin{funcdesc}{raw}{}
303Enter raw mode.
304\end{funcdesc}
305
306\begin{funcdesc}{reset_prog_mode}{}
307Restores the terminal to ``program'' mode, as previously saved
308by \function{def_prog_mode()}.
309\end{funcdesc}
310
311\begin{funcdesc}{reset_shell_mode}{}
312Restores the terminal to ``shell'' mode, as previously saved
313by \function{def_shell_mode()}.
314\end{funcdesc}
315
316\begin{funcdesc}{setsyx}{y, x}
317Sets the virtual screen cursor to \var{y}, \var{x}.
318If \var{y} and \var{x} are both -1, then leaveok is set.
319\end{funcdesc}
320
321\begin{funcdesc}{start_color}{}
322Must be called if the programmer wants to use colors, and before any
323other color manipulation routine is called. It is good
324practice to call this routine right after \function{initscr()}.
325
326\function{start_color()} initializes eight basic colors (black, red,
327green, yellow, blue, magenta, cyan, and white), and two global
328variables in the \module{curses} module, COLORS and COLOR_PAIRS,
329containing the maximum number of colors and color-pairs the terminal
330can support. It also restores the colors on the terminal to the
331values they had when the terminal was just turned on.
332\end{funcdesc}
333
334\begin{funcdesc}{termattrs}{}
335Returns a logical OR of all video attributes supported by the
336terminal. This information is useful when a curses program needs
337complete control over the appearance of the screen.
338\end{funcdesc}
339
340\begin{funcdesc}{termname}{}
341Returns the value of the environment variable TERM, truncated to 14
342characters.
343\end{funcdesc}
344
345\begin{funcdesc}{unctrl}{ch}
346Returns a string which is a printable representation of the character
347\var{ch}. Control characters are displayed as a caret followed by the
348character, for example as \verb|^C|. Printing characters are left as they
349are.
350\end{funcdesc}
351
352\begin{funcdesc}{ungetch}{ch}
353Push \var{ch} so the next \method{getch()} will return it.
354\strong{Note:} only one \var{ch} can be pushed before \method{getch()}
355is called.
356\end{funcdesc}
357
358\begin{funcdesc}{use_env}{flag}
359If used, this function should be called before \function{initscr} or
360newterm are called. When \var{flag} is false, the values of
361lines and columns specified in the terminfo database will be
362used, even if environment variables LINES and COLUMNS (used by
363default) are set, or if curses is running in a window (in which
364case default behavior would be to use the window size if LINES
365and COLUMNS are not set).
366\end{funcdesc}
Fred Drakea4070ce1999-06-21 21:13:09 +0000367
368\subsection{Window Objects \label{curses-window-objects}}
369
370Window objects, as returned by \function{initscr()} and
371\function{newwin()} above, have the
372following methods:
373
Fred Drakea4070ce1999-06-21 21:13:09 +0000374\begin{methoddesc}{addch}{\optional{y, x,} ch\optional{, attr}}
375\strong{Note:} A \emph{character} means a C character (i.e., an
376\ASCII{} code), rather then a Python character (a string of length 1).
377(This note is true whenever the documentation mentions a character.)
378
379Paint character \var{ch} at \code{(\var{y}, \var{x})} with attributes
380\var{attr}, overwriting any character previously painter at that
381location. By default, the character position and attributes are the
382current settings for the window object.
383\end{methoddesc}
384
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000385\begin{methoddesc}{addnstr}{\optional{y, x,} str, n\optional{, attr}}
386Paint at most \var{n} characters of the
387string \var{str} at \code{(\var{y}, \var{x})} with attributes
Fred Drake0bccd731999-06-23 17:28:01 +0000388\var{attr}, overwriting anything previously on the display.
Fred Drakea4070ce1999-06-21 21:13:09 +0000389\end{methoddesc}
390
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000391\begin{methoddesc}{addstr}{\optional{y, x,} str\optional{, attr}}
392Paint the string \var{str} at \code{(\var{y}, \var{x})} with attributes
393\var{attr}, overwriting anything previously on the display.
Fred Drakea4070ce1999-06-21 21:13:09 +0000394\end{methoddesc}
395
396\begin{methoddesc}{attroff}{attr}
Fred Drake0bccd731999-06-23 17:28:01 +0000397Turn off attribute \var{attr}.
Fred Drakea4070ce1999-06-21 21:13:09 +0000398\end{methoddesc}
399
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000400\begin{methoddesc}{attron}{attr}
401Turn on attribute \var{attr}.
Fred Drakea4070ce1999-06-21 21:13:09 +0000402\end{methoddesc}
403
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000404\begin{methoddesc}{attrset}{attr}
405Set the attributes to \var{attr}.
Fred Drakea4070ce1999-06-21 21:13:09 +0000406\end{methoddesc}
407
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000408\begin{methoddesc}{bkgd}{ch\optional{, attr}}
409Sets the background property of the window to the character \var{ch},
410with attributes \var{attr}. The change is then applied to every
411character position in that window:
412\begin{itemize}
413\item The attribute of every character in the window is
414 changed to the new background attribute.
415
416\item Wherever the former background character appears,
417it is changed to the new background character.
418\end{itemize}
419
420\end{methoddesc}
421
422\begin{methoddesc}{bkgdset}{ch\optional{, attr}}
423Sets the window's background. A window's background consists of a
424character and any combination of attributes. The attribute part of
425the background is combined (OR'ed) with all non-blank characters that
426are written into the window. Both the character and attribute parts
427of the background are combined with the blank characters. The
428background becomes a property of the character and moves with the
429character through any scrolling and insert/delete line/character
430operations.
Fred Drakea4070ce1999-06-21 21:13:09 +0000431\end{methoddesc}
432
Fred Drake0bccd731999-06-23 17:28:01 +0000433\begin{methoddesc}{border}{\optional{ls\optional{, rs\optional{, ts\optional{,
434 bs\optional{, tl\optional{, tr\optional{,
435 bl\optional{, br}}}}}}}}}
436Draw a border around the edges of the window. Each parameter specifies
437the character to use for a specific part of the border; see the table
438below for more details. The characters must be specified as integers;
439using one-character strings will cause \exception{TypeError} to be
440raised.
441
442\strong{Note:} A \code{0} value for any parameter will cause the
443default character to be used for that parameter. Keyword parameters
444can \emph{not} be used. The defaults are listed in this table:
445
446\begin{tableiii}{l|l|l}{var}{Parameter}{Description}{Default value}
447 \lineiii{ls}{Left side}{\constant{ACS_VLINE}}
448 \lineiii{rs}{Right side}{\constant{ACS_VLINE}}
449 \lineiii{ts}{Top}{\constant{ACS_HLINE}}
450 \lineiii{bs}{Bottom}{\constant{ACS_HLINE}}
451 \lineiii{tl}{Upper-left corner}{\constant{ACS_ULCORNER}}
452 \lineiii{tr}{Upper-right corner}{\constant{ACS_URCORNER}}
453 \lineiii{bl}{Bottom-left corner}{\constant{ACS_BLCORNER}}
454 \lineiii{br}{Bottom-right corner}{\constant{ACS_BRCORNER}}
455\end{tableiii}
Fred Drakea4070ce1999-06-21 21:13:09 +0000456\end{methoddesc}
457
Fred Drake0bccd731999-06-23 17:28:01 +0000458\begin{methoddesc}{box}{\optional{vertch, horch}}
459Similar to \method{border()}, but both \var{ls} and \var{rs} are
460\var{vertch} and both \var{ts} and {bs} are \var{horch}. The default
461corner characters are always used by this function.
Fred Drakea4070ce1999-06-21 21:13:09 +0000462\end{methoddesc}
463
Fred Drakea4070ce1999-06-21 21:13:09 +0000464\begin{methoddesc}{clear}{}
465Like \method{erase()}, but also causes the whole screen to be repainted
466upon next call to \method{refresh()}.
467\end{methoddesc}
468
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000469\begin{methoddesc}{clearok}{yes}
470If \var{yes} is 1, the next call to \method{refresh()}
471will clear the screen completely.
472\end{methoddesc}
473
Fred Drakea4070ce1999-06-21 21:13:09 +0000474\begin{methoddesc}{clrtobot}{}
475Erase from cursor to the end of the screen: all lines below the cursor
476are deleted, and then the equivalent of \method{clrtoeol()} is performed.
477\end{methoddesc}
478
479\begin{methoddesc}{clrtoeol}{}
480Erase from cursor to the end of the line.
481\end{methoddesc}
482
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000483\begin{methoddesc}{cursyncup}{}
484Updates the current cursor position of all the ancestors of the window
485to reflect the current cursor position of the window.
Fred Drakea4070ce1999-06-21 21:13:09 +0000486\end{methoddesc}
487
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000488\begin{methoddesc}{delch}{\optional{x, y}}
489Delete any character at \code{(\var{y}, \var{x})}.
Fred Drakea4070ce1999-06-21 21:13:09 +0000490\end{methoddesc}
491
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000492\begin{methoddesc}{deleteln}{}
493Delete the line under the cursor. All following lines are moved up
494by 1 line.
495\end{methoddesc}
496
497\begin{methoddesc}{derwin}{\optional{nlines, ncols,} begin_y, begin_y}
498An abbreviation for ``derive window'', \method{derwin()} is the same
499as calling \method{subwin()}, except that \var{begin_y} and
500\var{begin_x} are relative to the origin of the window, rather than
501relative to the entire screen. Returns a window object for the
502derived window.
503\end{methoddesc}
504
505\begin{methoddesc}{echochar}{ch\optional{, attr}}
506Add character \var{ch} with attribute \var{attr}, and immediately
507call \method{refresh}.
508\end{methoddesc}
509
510\begin{methoddesc}{erase}{}
511Clear the window.
512\end{methoddesc}
513
514\begin{methoddesc}{getbegyx}{}
515Return a tuple \code{(\var{y}, \var{x})} of co-ordinates of upper-left
516corner.
Fred Drakea4070ce1999-06-21 21:13:09 +0000517\end{methoddesc}
518
519\begin{methoddesc}{getch}{\optional{x, y}}
520Get a character. Note that the integer returned does \emph{not} have to
521be in \ASCII{} range: function keys, keypad keys and so on return numbers
522higher then 256. In no-delay mode, an exception is raised if there is
523no input.
524\end{methoddesc}
525
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000526\begin{methoddesc}{getkey}{\optional{x, y}}
527Get a character, returning a string instead of an integer, as
528\method{getch()} does. Function keys, keypad keys and so on return a
529multibyte string containing the key name. In no-delay mode, an
530exception is raised if there is no input.
531\end{methoddesc}
532
533\begin{methoddesc}{getmaxyx}{}
534Return a tuple \code{(\var{y}, \var{x})} of the height and width of
535the window.
536\end{methoddesc}
537
538\begin{methoddesc}{getparyx}{}
539Returns the beginning coordinates of this window relative to its
540parent window into two integer variables y and x. Returns
541\code{-1,-1} if this window has no parent.
542\end{methoddesc}
543
Fred Drakea4070ce1999-06-21 21:13:09 +0000544\begin{methoddesc}{getstr}{\optional{x, y}}
545Read a string from the user, with primitive line editing capacity.
546\end{methoddesc}
547
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000548\begin{methoddesc}{getyx}{}
549Return a tuple \code{(\var{y}, \var{x})} of current cursor position.
550\end{methoddesc}
551
552\begin{methoddesc}{hline}{\optional{y, x,} ch, n}
553Display a horizontal line starting at \code{(\var{y}, \var{x})} with
554length \var{n} consisting of the character \var{ch}.
555\end{methoddesc}
556
557\begin{methoddesc}{idcok}{flag}
558If \var{flag} is false, curses no longer considers using the hardware
559insert/delete character feature of the terminal; if \var{flag} is
560true, use of character insertion and deletion is enabled. When curses
561is first initialized, use of character insert/delete is enabled by
562default.
563\end{methoddesc}
564
565\begin{methoddesc}{idlok}{yes}
566If called with \var{yes} equal to 1, \module{curses} will try and use
567hardware line editing facilities. Otherwise, line insertion/deletion
568are disabled.
569\end{methoddesc}
570
571\begin{methoddesc}{immedok}{flag}
572If \var{flag} is true, any change in the window image
573automatically causes the window to be refreshed; you no longer
574have to call \method{refresh()} yourself. However, it may
575degrade performance considerably, due to repeated calls to
576wrefresh. This option is disabled by default.
577\end{methoddesc}
578
Fred Drakea4070ce1999-06-21 21:13:09 +0000579\begin{methoddesc}{inch}{\optional{x, y}}
580Return the character at the given position in the window. The bottom
5818 bits are the character proper, and upper bits are the attributes.
582\end{methoddesc}
583
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000584\begin{methoddesc}{insch}{\optional{y, x,} ch\optional{, attr}}
585Paint character \var{ch} at \code{(\var{y}, \var{x})} with attributes
586\var{attr}, moving the line from position \var{x} right by one
587character.
Fred Drakea4070ce1999-06-21 21:13:09 +0000588\end{methoddesc}
589
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000590\begin{methoddesc}{insdelln}{nlines}
591Inserts \var{nlines} lines into the specified window above the current
592line. The \var{nlines} bottom lines are lost. For negative
593\var{nlines}, delete \var{nlines} lines starting with the one under
594the cursor, and move the remaining lines up. The bottom \var{nlines}
595lines are cleared. The current cursor position remains the same.
596\end{methoddesc}
597
598\begin{methoddesc}{insertln}{}
599Insert a blank line under the cursor. All following lines are moved
600down by 1 line.
601\end{methoddesc}
602
603\begin{methoddesc}{insnstr}{\optional{y, x, } str, n \optional{, attr}}
604Insert a character string (as many characters as will fit on the line)
605before the character under the cursor, up to \var{n} characters.
606If \var{n} is zero or negative,
607the entire string is inserted.
608All characters to the right of
609the cursor are shifted right, with the the rightmost characters on the
610line being lost. The cursor position does not change (after moving to
611\var{y}, \var{x}, if specified).
612\end{methoddesc}
613
614\begin{methoddesc}{insstr}{\optional{y, x, } str \optional{, attr}}
615Insert a character string (as many characters as will fit on the line)
616before the character under the cursor. All characters to the right of
617the cursor are shifted right, with the the rightmost characters on the
618line being lost. The cursor position does not change (after moving to
619\var{y}, \var{x}, if specified).
620\end{methoddesc}
621
622\begin{methoddesc}{instr}{\optional{y, x} \optional{, n}}
623Returns a string of characters, extracted from the window starting at
624the current cursor position, or at \var{y}, \var{x} if specified.
625Attributes are stripped from the characters. If \var{n} is specified,
626\method{instr()} returns return a string at most \var{n} characters
627long (exclusive of the trailing NUL).
628\end{methoddesc}
629
630\begin{methoddesc}{is_linetouched}{\var{line}}
631Returns true if the specified line was modified since the last call to
632\method{refresh()}; otherwise returns false. Raises a
633\exception{curses.error} exception if \var{line} is not valid
634for the given window.
635\end{methoddesc}
636
637\begin{methoddesc}{is_wintouched}{}
638Returns true if the specified window was modified since the last call to
639\method{refresh()}; otherwise returns false.
640\end{methoddesc}
641
642\begin{methoddesc}{keypad}{yes}
643If \var{yes} is 1, escape sequences generated by some keys (keypad,
644function keys) will be interpreted by \module{curses}.
645If \var{yes} is 0, escape sequences will be left as is in the input
646stream.
Fred Drakea4070ce1999-06-21 21:13:09 +0000647\end{methoddesc}
648
649\begin{methoddesc}{leaveok}{yes}
650If \var{yes} is 1,
651cursor is left where it is, instead of being at ``cursor position.''
652This reduces cursor movement where possible. If possible it will be made
653invisible.
654
655If \var{yes} is 0, cursor will always be at
656``cursor position'' after an update.
657\end{methoddesc}
658
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000659\begin{methoddesc}{move}{new_y, new_x}
660Move cursor to \code{(\var{new_y}, \var{new_x})}.
Fred Drakea4070ce1999-06-21 21:13:09 +0000661\end{methoddesc}
662
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000663\begin{methoddesc}{mvderwin}{y, x}
664Moves the window inside its parent window. The screen-relative
665parameters of the window are not changed. This routine is used to
666display different parts of the parent window at the same physical
667position on the screen.
668\end{methoddesc}
Fred Drakea4070ce1999-06-21 21:13:09 +0000669
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000670\begin{methoddesc}{mvwin}{new_y, new_x}
671Move the window so its upper-left corner is at \code{(\var{new_y}, \var{new_x})}.
Fred Drakea4070ce1999-06-21 21:13:09 +0000672\end{methoddesc}
673
674\begin{methoddesc}{nodelay}{yes}
675If \var{yes} is 1, \method{getch()} will be non-blocking.
676\end{methoddesc}
677
678\begin{methoddesc}{notimeout}{yes}
679If \var{yes} is 1, escape sequences will not be timed out.
680
681If \var{yes} is 0, after a few milliseconds, an escape sequence will
682not be interpreted, and will be left in the input stream as is.
683\end{methoddesc}
Andrew M. Kuchlingf1dc5fa2000-05-23 16:46:04 +0000684
685\begin{methoddesc}{noutrefresh}{}
686Mark for refresh but wait.
687\end{methoddesc}
688
689\begin{methoddesc}{putwin}{file}
690Writes all data associated with the window into the provided file
691object. This information can be later retrieved using the
692\function{getwin()} function.
693
694\end{methoddesc}
695
696\begin{methoddesc}{redrawln}{beg, num}
697Indicates that the \var{num} screen lines, starting at line \var{beg},
698are corrupted and should be completely redrawn on the next
699\method{refresh()} call.
700\end{methoddesc}
701
702\begin{methoddesc}{redrawwin}{}
703Touches the entire window, causing it to be completely redrawn on the
704next \method{refresh()} call.
705\end{methoddesc}
706
707\begin{methoddesc}{refresh}{ \optional{pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol} }
708Update the display immediately (sync actual screen with previous
709drawing/deleting methods).
710
711The 6 optional arguments can only be specified when the window is a
712pad created with \function{newpad()}. The additional parameters are
713needed to indicate what part of the pad and screen are involved.
714\var{pminrow} and \var{pmincol} specify the upper left-hand corner of the
715rectangle to be displayed in the pad. \var{sminrow}, \var{smincol},
716\var{smaxrow}, and \var{smaxcol} specify the edges of the rectangle to be displayed on the screen. The lower right-hand corner of the
717rectangle to be displayed in the pad is calculated from the screen
718coordinates, since the rectangles must be the same size. Both
719rectangles must be entirely contained within their respective
720structures. Negative values of \var{pminrow}, \var{pmincol},
721\var{sminrow}, or \var{smincol} are treated as if they were zero.
722\end{methoddesc}
723
724\begin{methoddesc}{scroll}{\optional{lines\code{ = 1}}}
725Scroll the screen upward by \var{lines} lines.
726\end{methoddesc}
727
728\begin{methoddesc}{scrollok}{flag}
729Controls what happens when the cursor of a window is moved off the
730 edge of the window or scrolling region, either as a result of a
731 newline action on the bottom line, or typing the last character
732 of the last line. If \var{flag} is false, the cursor is left
733 on the bottom line. If \var{flag} is true, the window is
734 scrolled up one line. Note that in order to get the physical
735 scrolling effect on the terminal, it is also necessary to call
736 \method{idlok()}.
737\end{methoddesc}
738
739\begin{methoddesc}{setscrreg}{top, bottom}
740Set the scrolling region from line \var{top} to line \var{bottom}. All
741scrolling actions will take place in this region.
742\end{methoddesc}
743
744\begin{methoddesc}{standend}{}
745Turn off all attributes.
746\end{methoddesc}
747
748\begin{methoddesc}{standout}{}
749Turn on attribute \var{A_STANDOUT}.
750\end{methoddesc}
751
752\begin{methoddesc}{subpad}{\optional{nlines, ncols,} begin_y, begin_y}
753Return a sub-window, whose upper-left corner is at
754\code{(\var{begin_y}, \var{begin_x})}, and whose width/height is
755\var{ncols}/\var{nlines}.
756\end{methoddesc}
757
758\begin{methoddesc}{subwin}{\optional{nlines, ncols,} begin_y, begin_y}
759Return a sub-window, whose upper-left corner is at
760\code{(\var{begin_y}, \var{begin_x})}, and whose width/height is
761\var{ncols}/\var{nlines}.
762
763By default, the sub-window will extend from the
764specified position to the lower right corner of the window.
765\end{methoddesc}
766
767\begin{methoddesc}{syncdown}{}
768Touches each location in the window that has been touched in any of
769its ancestor windows. This routine is called by \method{refresh()},
770so it should almost never be necessary to call it manually.
771\end{methoddesc}
772
773\begin{methoddesc}{syncok}{flag}
774If called with \var{flag} set to true, then \method{syncup()} is
775called automatically whenever there is a change in the window.
776\end{methoddesc}
777
778\begin{methoddesc}{syncup}{}
779Touches all locations in ancestors of the window that have been changed in
780the window.
781\end{methoddesc}
782
783\begin{methoddesc}{touchline}{start, count}
784Pretend \var{count} lines have been changed, starting with line
785\var{start}.
786\end{methoddesc}
787
788\begin{methoddesc}{touchwin}{}
789Pretend the whole window has been changed, for purposes of drawing
790optimizations.
791\end{methoddesc}
792
793\begin{methoddesc}{untouchwin}{}
794Marks all lines in the window as unchanged since the last call to
795\method{refresh()}.
796\end{methoddesc}
797
798\begin{methoddesc}{vline}{\optional{y, x,} ch, n}
799Display a vertical line starting at \code{(\var{y}, \var{x})} with
800length \var{n} consisting of the character \var{ch}.
801\end{methoddesc}
802
803\subsection{Constants}
804
805The \module{curses} module defines the following data members:
806
807\begin{datadesc}{version}
808A string representing the current version of the module.
809Also available as \constant{__version__}.
810\end{datadesc}
811
812
813\begin{tableii}{c|l}{code}{Attribute}{Meaning}
814 \lineii{A_ALTCHARSET}{Alternate character set mode.}
815 \lineii{A_BLINK}{Blink mode.}
816 \lineii{A_BOLD}{Bold mode.}
817 \lineii{A_DIM}{Dim mode.}
818 \lineii{A_NORMAL}{Normal attribute.}
819 \lineii{A_STANDOUT}{Standout mode.}
820 \lineii{A_UNDERLINE}{Underline mode.}
821\end{tableii}
822
823Keys are referred to by integer constants with names starting with
824\code{KEY_}. The exact names available are system dependent.
825
826% XXX this table is far too large!
827% XXX should this table be alphabetized?
828
829\begin{tableii}{c|l}{code}{Key constant}{Key}
830 \lineii{KEY_MIN}{Minimum key value}
831 \lineii{KEY_BREAK}{ Break key (unreliable) }
832 \lineii{KEY_DOWN}{ Down-arrow }
833 \lineii{KEY_UP}{ Up-arrow }
834 \lineii{KEY_LEFT}{ Left-arrow }
835 \lineii{KEY_RIGHT}{ Right-arrow }
836 \lineii{KEY_HOME}{ Home key (upward+left arrow) }
837 \lineii{KEY_BACKSPACE}{ Backspace (unreliable) }
838 \lineii{KEY_F0}{ Function keys. Up to 64 function keys are supported. }
839 \lineii{KEY_F\var{n}}{ Value of function key \var{n} }
840 \lineii{KEY_DL}{ Delete line }
841 \lineii{KEY_IL}{ Insert line }
842 \lineii{KEY_DC}{ Delete character }
843 \lineii{KEY_IC}{ Insert char or enter insert mode }
844 \lineii{KEY_EIC}{ Exit insert char mode }
845 \lineii{KEY_CLEAR}{ Clear screen }
846 \lineii{KEY_EOS}{ Clear to end of screen }
847 \lineii{KEY_EOL}{ Clear to end of line }
848 \lineii{KEY_SF}{ Scroll 1 line forward }
849 \lineii{KEY_SR}{ Scroll 1 line backward (reverse) }
850 \lineii{KEY_NPAGE}{ Next page }
851 \lineii{KEY_PPAGE}{ Previous page }
852 \lineii{KEY_STAB}{ Set tab }
853 \lineii{KEY_CTAB}{ Clear tab }
854 \lineii{KEY_CATAB}{ Clear all tabs }
855 \lineii{KEY_ENTER}{ Enter or send (unreliable) }
856 \lineii{KEY_SRESET}{ Soft (partial) reset (unreliable) }
857 \lineii{KEY_RESET}{ Reset or hard reset (unreliable) }
858 \lineii{KEY_PRINT}{ Print }
859 \lineii{KEY_LL}{ Home down or bottom (lower left) }
860 \lineii{KEY_A1}{ Upper left of keypad }
861 \lineii{KEY_A3}{ Upper right of keypad }
862 \lineii{KEY_B2}{ Center of keypad }
863 \lineii{KEY_C1}{ Lower left of keypad }
864 \lineii{KEY_C3}{ Lower right of keypad }
865 \lineii{KEY_BTAB}{ Back tab }
866 \lineii{KEY_BEG}{ Beg (beginning) }
867 \lineii{KEY_CANCEL}{ Cancel }
868 \lineii{KEY_CLOSE}{ Close }
869 \lineii{KEY_COMMAND}{ Cmd (command) }
870 \lineii{KEY_COPY}{ Copy }
871 \lineii{KEY_CREATE}{ Create }
872 \lineii{KEY_END}{ End }
873 \lineii{KEY_EXIT}{ Exit }
874 \lineii{KEY_FIND}{ Find }
875 \lineii{KEY_HELP}{ Help }
876 \lineii{KEY_MARK}{ Mark }
877 \lineii{KEY_MESSAGE}{ Message }
878 \lineii{KEY_MOVE}{ Move }
879 \lineii{KEY_NEXT}{ Next }
880 \lineii{KEY_OPEN}{ Open }
881 \lineii{KEY_OPTIONS}{ Options }
882 \lineii{KEY_PREVIOUS}{ Prev (previous) }
883 \lineii{KEY_REDO}{ Redo }
884 \lineii{KEY_REFERENCE}{ Ref (reference) }
885 \lineii{KEY_REFRESH}{ Refresh }
886 \lineii{KEY_REPLACE}{ Replace }
887 \lineii{KEY_RESTART}{ Restart }
888 \lineii{KEY_RESUME}{ Resume }
889 \lineii{KEY_SAVE}{ Save }
890 \lineii{KEY_SBEG}{ Shifted Beg (beginning) }
891 \lineii{KEY_SCANCEL}{ Shifted Cancel }
892 \lineii{KEY_SCOMMAND}{ Shifted Command }
893 \lineii{KEY_SCOPY}{ Shifted Copy }
894 \lineii{KEY_SCREATE}{ Shifted Create }
895 \lineii{KEY_SDC}{ Shifted Delete char }
896 \lineii{KEY_SDL}{ Shifted Delete line }
897 \lineii{KEY_SELECT}{ Select }
898 \lineii{KEY_SEND}{ Shifted End }
899 \lineii{KEY_SEOL}{ Shifted Clear line }
900 \lineii{KEY_SEXIT}{ Shifted Dxit }
901 \lineii{KEY_SFIND}{ Shifted Find }
902 \lineii{KEY_SHELP}{ Shifted Help }
903 \lineii{KEY_SHOME}{ Shifted Home }
904 \lineii{KEY_SIC}{ Shifted Input }
905 \lineii{KEY_SLEFT}{ Shifted Left arrow }
906 \lineii{KEY_SMESSAGE}{ Shifted Message }
907 \lineii{KEY_SMOVE}{ Shifted Move }
908 \lineii{KEY_SNEXT}{ Shifted Next }
909 \lineii{KEY_SOPTIONS}{ Shifted Options }
910 \lineii{KEY_SPREVIOUS}{ Shifted Prev }
911 \lineii{KEY_SPRINT}{ Shifted Print }
912 \lineii{KEY_SREDO}{ Shifted Redo }
913 \lineii{KEY_SREPLACE}{ Shifted Replace }
914 \lineii{KEY_SRIGHT}{ Shifted Right arrow }
915 \lineii{KEY_SRSUME}{ Shifted Resume }
916 \lineii{KEY_SSAVE}{ Shifted Save }
917 \lineii{KEY_SSUSPEND}{ Shifted Suspend }
918 \lineii{KEY_SUNDO}{ Shifted Undo }
919 \lineii{KEY_SUSPEND}{ Suspend }
920 \lineii{KEY_UNDO}{ Undo }
921 \lineii{KEY_MOUSE}{ Mouse event has occurred }
922 \lineii{KEY_RESIZE}{ Terminal resize event }
923 \lineii{KEY_MAX}{Maximum key value}
924\end{tableii}
925
926The following table lists characters from the alternate character set.
927\strong{Note:} These are available only after \function{initscr()} has
928been called.
929
930\begin{tableii}{c|l}{code}{ACS code}{Meaning}
931 \lineii{ACS_BBSS}{}
932 \lineii{ACS_BLOCK}{}
933 \lineii{ACS_BOARD}{}
934 \lineii{ACS_BSBS}{}
935 \lineii{ACS_BSSB}{}
936 \lineii{ACS_BSSS}{}
937 \lineii{ACS_BTEE}{}
938 \lineii{ACS_BULLET}{}
939 \lineii{ACS_CKBOARD}{}
940 \lineii{ACS_DARROW}{}
941 \lineii{ACS_DEGREE}{}
942 \lineii{ACS_DIAMOND}{}
943 \lineii{ACS_GEQUAL}{ (Not available with SGI curses)}
944 \lineii{ACS_HLINE}{}
945 \lineii{ACS_LANTERN}{}
946 \lineii{ACS_LARROW}{}
947 \lineii{ACS_LEQUAL}{ (Not available with SGI curses)}
948 \lineii{ACS_LLCORNER}{}
949 \lineii{ACS_LRCORNER}{}
950 \lineii{ACS_LTEE}{}
951 \lineii{ACS_NEQUAL}{ (Not available with SGI curses)}
952 \lineii{ACS_PI}{ (Not available with SGI curses)}
953 \lineii{ACS_PLMINUS}{}
954 \lineii{ACS_PLUS}{}
955 \lineii{ACS_RARROW}{}
956 \lineii{ACS_RTEE}{}
957 \lineii{ACS_S1}{}
958 \lineii{ACS_S3}{ (Not available with SGI curses)}
959 \lineii{ACS_S9}{}
960 \lineii{ACS_SBBS}{}
961 \lineii{ACS_SBSB}{}
962 \lineii{ACS_SBSS}{}
963 \lineii{ACS_SSBB}{}
964 \lineii{ACS_SSBS}{}
965 \lineii{ACS_SSSB}{}
966 \lineii{ACS_SSSS}{}
967 \lineii{ACS_STERLING}{ (Not available with SGI curses)}
968 \lineii{ACS_TTEE}{}
969 \lineii{ACS_UARROW}{}
970 \lineii{ACS_ULCORNER}{}
971 \lineii{ACS_URCORNER}{}
972 \lineii{ACS_VLINE}{}
973\end{tableii}
974
975The following table lists the predefined colors:
976
977\begin{tableii}{c|l}{code}{Constant}{Color}
978 \lineii{COLOR_BLACK}{Black}
979 \lineii{COLOR_BLUE}{Blue}
980 \lineii{COLOR_CYAN}{Cyan (light greenish blue)}
981 \lineii{COLOR_GREEN}{Green}
982 \lineii{COLOR_MAGENTA}{Magenta (purplish red)}
983 \lineii{COLOR_RED}{Red}
984 \lineii{COLOR_WHITE}{White}
985 \lineii{COLOR_YELLOW}{Yellow}
986\end{tableii}
987