- 论坛徽章:
- 0
|
请教sdccf,你的CURSES函数.....
curses(S)
*********
____________________________________________________________________________
curses -- CRT screen handling and optimization package
Syntax
======
cc ... -lcurses
#include <curses.h>;
Description
===========
The curses library routines give the user a terminal-independent method of
updating character screens with reasonable optimization. A program using
these routines must be compiled with the -lcurses option of cc(CP).
The curses package allows:
o overall screen, window and pad manipulation
o output to windows and pads
o reading terminal input
o control over terminal and curses input and output options
o environment query routines
o color manipulation
o use of soft label keys
o terminfo access
o access to low-level curses routines
To initialize the routines, you must call the routine initscr or newterm
before using any of the other routines that deal with windows and screens.
The routine endwin(S) must be called before exiting. Most interactive,
screen-oriented programs want single-character input without echoing. To
get it, use this sequence:
cbreak();
noecho();
Most programs would also use the sequence:
nonl();
intrflush(stdscr,FALSE);
keypad(stdscr,TRUE);
Before you run a curses( ) program, set the tab stops of the terminal and
output its initialization strings if they are defined. You can do this
using the command
tput init
after the shell environment variable TERM has been exported. (See terminfo
(F) and terminfo(M) for details.)
The curses( ) library lets you manipulate data structures, called windows,
which can be thought of as two-dimensional arrays of characters. The
library supplies a default window called stdscr, which is the size of the
terminal screen. You can create others using newwin( ).
Windows are referred to by variables declared as WINDOW *. These data
structures are manipulated with routines described on curses pages (whose
names begin with ``curs_''). Among the most basic routines are move( ) and
addch( ). The library includes more general versions of these routines that
allow you to specify a window.
After routines manipulate a window, refresh( ) is called, telling curses( )
to make the user's screen look like stdscr. The characters in a window are
actually of type chtype (character and attribute data) so that other
information about the character can also be stored with each character.
Special windows called pads can also be manipulated. They are windows that
might not be associated with a viewable part of the screen. See curs_pad(S)
for more information.
In addition to drawing characters on the screen, you can use video
attributes and colors, producing characters that are underlined, reverse
video, or in color on terminals that support those modes. You can also
output line-drawing characters. On input, curses( ) can also translate the
escape sequences from arrow and function keys into single values. The video
attributes, line-drawing characters, and input values use names, defined in
curses.h, such as A_REVERSE, ACS_HLINE, and KEY_LEFT.
curses( ) has routines that manipulate color on color alphanumeric
terminals. To use them, call start_color( ), usually right after initscr(
). Colors are always used in pairs, called color-pairs. A color-pair has a
foreground color (the character) and a background color (the field on which
the character is displayed).
You initialize a color-pair with the routine init_pair( ). After it has been
initialized, you can use COLOR_PAIR(n), a macro defined in curses.h, in the
same way that you use other video attributes. If a terminal can redefine
colors, the following routines are useful:
o has_color( ) returns TRUE or FALSE, depending on whether the terminal has
color capability.
o can_change_color( ) returns TRUE or FALSE, depending on whether the user
can change the colors.
o color_content( ) reports to the user the amounts of red, green, and blue
in an initialized color.
o pair_content( ) reports to the user how a specified color-pair is
currently defined.
o init_color( ) changes the definition of a color.
If the environment variables LINES and COLUMNS are set, or if the program is
running in a window environment, line and column information in the
environment overrides information read by terminfo( ). Programs running in
a window environment need this because the size of a screen is changeable.
If the environment variable TERMINFO is defined, any program using curses( )
checks for a local terminal definition before checking in the standard
place. For example, if TERM is set to wyse150, then the compiled terminal
definition is found in
html.awk: part.03: 1917: Trying to use .nf in display, havent started .fi
1>;&2
/usr/lib/terminfo/w/wyse150
(The w is copied from the first letter of wyse150 to avoid creating huge
directories.) However, if TERMINFO is set to $HOME/myterms, curses( ) first
checks
$HOME/myterms/w/wyse150
and if that fails, it checks
/usr/lib/terminfo/w/wyse150
This is useful for developing experimental definitions or when write
permission in /usr/lib/terminfo is not available.
The integer variables LINES and COLS are defined in curses.h and are filled
in by initscr( ) with the size of the screen. The constant TRUE has the
value 1; and the constant FALSE has the value 0.
curses routines also define the WINDOW * variable curscr, which is used for
certain low-level operations such as clearing and redrawing a screen.
However, curscr can be used in only a few routines.
International functions
+++++++++++++++++++++++
The number of bytes and the number of columns to hold a character from the
supplementary character set is locale-specific (locale category LC_CTYPE).
You can specify it in the character class table.
For editing, it is entirely appropriate to operate at the character level.
But for screen formatting, arbitrary movement of characters on screen is
not desirable.
Routines that overwrite characters (such as addch( )) operate on a screen
level. Overwriting a character with a character that requires a different
number of columns can produce orphaned columns. They are filled with
background characters.
Routines that insert characters (such as insch( )) operate on a character
level (that is, at the character boundaries). A new character is inserted
right before the current character, regardless of which column of a
character the cursor points to. Before insertion, the cursor moves to the
first column of the character.
Routines that delete characters (such as delch( )) also operate on a
character level (that is, at the character boundaries). The character at
the cursor is deleted, no matter which column of the character the cursor
points to. Before deletion, the cursor moves to the first column of the
character.
You cannot place a multi-column character on the last column of a line. If
you try, the last column is set to the background character. Such an
operation can also create orphaned columns, filled with background
characters.
Overlapping and overwriting a window follows the operation of overwriting
characters around its edge. The orphaned columns, if any, are handled as in
character operations.
The cursor can be placed anywhere in a window. It moves to the first column
of a multi-column character before an insertion or deletion. |
|