| Main index | Section 3 | Options |
#include <curses.h>const char *unctrl(chtype ch); wchar_t *wunctrl(cchar_t *wch);
const char *keyname(int c); const char *key_name(wchar_t wc);
void filter(void);
void use_env(bool f);
int putwin(WINDOW *win, FILE *filep); WINDOW *getwin(FILE *filep);
int delay_output(int ms); int flushinp(void);
/* extensions */ void nofilter(void); void use_tioctl(bool f);
| &#187; | Printable characters are displayed as themselves, e.g., a one-character string containing the key. |
| &#187; | Control characters are displayed in the ^X notation. |
| &#187; | Printing characters are displayed as is. |
| &#187; | DEL (character 127) is displayed as ^?. |
| &#187; | Values above 128 are either meta characters (if the screen has not been initialized, or if meta(3X) has been called with a TRUE parameter), shown in the M-X notation, or are displayed as themselves. In the latter case, the values may not be printable; this follows the X/Open specification. |
In both unctrl and wunctrl the attributes and color associated with the character parameter are ignored.
| &#187; | Key codes below 256 are characters. They are displayed using unctrl. |
| &#187; | Values above 256 may be the codes for function keys. The function key name is displayed. |
| &#187; | Otherwise (if there is no corresponding name and the key is not a character) the function returns null, to denote an error. X/Open also lists an UNKNOWN KEY return value, which some implementations return rather than null. |
| &#187; | keyname returns null where key_name would display a meta character. |
| &#187; | key_name does not return the name of a function key. |
| &#187; | LINES is set to 1; |
| &#187; | the capabilities clear, cud1, cud, cup, cuu1, cuu, vpa are disabled; |
| &#187; | the capability ed is disabled if bce is set; |
| &#187; | and the home string is set to the value of cr. |
| &#187; | Normally ncurses looks first at the terminal database for the screen size. |
| If use_env was called with FALSE for parameter, it stops here unless use_tioctl was also called with TRUE for parameter. | |
| &#187; | Then it asks for the screen size via operating system calls. If successful, it overrides the values from the terminal database. |
| &#187; | Finally (unless use_env was called with FALSE parameter), ncurses examines the LINES or COLUMNS environment variables, using a value in those to override the results from the operating system or terminal database. |
| curses also updates the screen size in response to SIGWINCH, unless overridden by the LINES or COLUMNS environment variables, | |
| &#187; | checks if the LINES and COLUMNS environment variables are set to a number greater than zero. |
| &#187; | for each, ncurses updates the corresponding environment variable with the value that it has obtained via operating system call or from the terminal database. |
| &#187; | ncurses re-fetches the value of the environment variables so that it is still the environment variables which set the screen size. |
| |||||||||||||
The getwin routine reads window related data stored in the file by putwin. The routine then creates and initializes a new window using that data. It returns a pointer to the new window. There are a few caveats:
| &#187; | the data written is a copy of the WINDOW structure, and its associated character cells. The format differs between the wide-character ( ncursesw) and non-wide ( ncurses) libraries. You can transfer data between the two, however. |
| &#187; | the retrieved window is always created as a top-level window (or pad), rather than a subwindow. |
| &#187; | the window's character cells contain the color pair value, but not the actual color numbers. If cells in the retrieved window use color pairs which have not been created in the application using init_pair, they will not be colored when the window is refreshed. |
| &#187; | the terminal description has npc (no_pad_char) capability, or |
| &#187; | the environment variable NCURSES_NO_PADDING is set. |
Routines that return pointers return NULL on error.
X/Open Curses does not specify any error conditions. In this implementation
flushinp returns an error if the terminal was not initialized. putwin returns an error if the associated fwrite calls return an error.
| &#187; | SVr4 curses does not delay if no padding character is available. |
| &#187; | NetBSD curses uses napms when no padding character is available, but does not take timing into account when using the padding character. |
| &#187; | The files written and read by these functions use an implementation-specific format. Although the format is an obvious target for standardization, it has been overlooked. |
| Interestingly enough, according to the copyright dates in Solaris source, the functions (along with scr_init, etc.) originated with the University of California, Berkeley (in 1982) and were later (in 1988) incorporated into SVr4. Oddly, there are no such functions in the 4.3BSD curses sources. | |
| &#187; | Most implementations simply dump the binary WINDOW structure to the file. These include SVr4 curses, NetBSD and PDCurses, as well as older ncurses versions. This implementation (as well as the X/Open variant of Solaris curses, dated 1995) uses textual dumps. |
| The implementations which use binary dumps use block-I/O (the fwrite and fread functions). Those that use textual dumps use buffered-I/O. A few applications may happen to write extra data in the file using these functions. Doing that can run into problems mixing block- and buffered-I/O. This implementation reduces the problem on writes by flushing the output. However, reading from a file written using mixed schemes may not be successful. | |
| &#187; | the parameter is a 7-bit US-ASCII code. This is the case that X/Open Curses documented. |
| &#187; | the parameter is in the range 128-159, i.e., a C1 control code. If use_legacy_coding(3X) has been called with a 2 parameter, unctrl returns the parameter, i.e., a one-character string with the parameter as the first character. Otherwise, it returns ~@, ~A, etc., analogous to ^@, ^A, C0 controls. |
| X/Open Curses does not document whether unctrl can be called before initializing curses. This implementation permits that, and returns the ~@, etc., values in that case. | |
| &#187; | parameter values outside the 0 to 255 range. unctrl returns a null pointer. |
Likewise, the meta(3X) function allows the caller to change the output of keyname, i.e., it determines whether to use the M- prefix for meta keys (codes in the range 128 to 255). Both use_legacy_coding(3X) and meta(3X) succeed only after curses is initialized. X/Open Curses does not document the treatment of codes 128 to 159. When treating them as meta keys (or if keyname is called before initializing curses), this implementation returns strings M-^@, M-^A, etc.
X/Open Curses documents unctrl as declared in <unctrl.h>, which ncurses does. However, ncurses' <curses.h> includes <unctrl.h>, matching the behavior of SVr4 curses. Other implementations may not do that.
| 2024-04-20 | curs_util (3X) | ncurses 6.5 |
| Main index | Section 3 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
| “ | Unix’s “power tools” are more like power switchblades that slice off the operator’s fingers quickly and efficiently. | ” |
| — The Unix Haters' handbook | ||