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