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