BSD 4_1_snap development
[unix-history] / usr / doc / curses / intro.1
CommitLineData
d3c0043c
KA
1.bp
2.sh 1 Overview
3.pp
4In making available the generalized terminal descriptions in \*(tc,
5much information was made available to the programmer,
6but little work was taken out of one's hands.
7The purpose of this package is to allow the C programmer
8to do the most common type of terminal dependent functions,
9those of movement optimization and optimal screen updating,
10without doing any of the dirty work,
11and (hopefully) with nearly as much ease as is necessary to simply print
12or read things.
13.pp
14The package is split into three parts:
15(1) Screen updating;
16(2) Screen updating with user input;
17and
18(3) Cursor motion optimization.
19.pp
20It is possible to use the motion optimization
21without using either of the other two,
22and screen updating and input can be done
23without any programmer knowledge of the motion optimization,
24or indeed the \*(et \*(db itself.
25.sh 2 "Terminology (or, Words You Can Say to Sound Brilliant)"
26.pp
27In this document,
28the following terminology is kept to with reasonable consistency:
29.de Ip
30.sp
31.in 5n
32.ti 0n
33.bi "\\$1" :
34..
35.Ip window
36An internal representation
37containing an image of what a section of the terminal screen may look like
38at some point in time.
39This subsection can either encompass the entire terminal screen,
40or any smaller portion down to a single character within that screen.
41.Ip "terminal"
42Sometimes called
43.bi terminal
44.bi screen .
45The package's idea of what the terminal's screen currently looks like,
46i.e., what the user sees now.
47This is a special
48.i screen :
49.Ip screen
50This is a subset of windows which are as large as the terminal screen,
51i.e., they start at the upper left hand corner
52and encompass the lower right hand corner.
53One of these,
54.Vn stdscr ,
55is automatically provided for the programmer.
56.rm Ip
57.sh 2 "Compiling Things"
58.pp
59In order to use the library,
60it is necessary to have certain types and variables defined.
61Therefore, the programmer must have a line:
62.(l
63.b "#include <curses.h>"
64.)l
65at the top of the program source.
66The header file
67.b <curses.h>
68needs to include
69.b <sgtty.h> ,
70so the one should not do so oneself\**.
71.(f
72\**
73The screen package also uses the Standard I/O library,
74so
75.b <curses.h>
76includes
77.b <stdio.h> .
78It is redundant
79(but harmless)
80for the programmer to do it, too.
81.)f
82Also,
83compilations should have the following form:
84.(l
85.ie t \fBcc\fR [ \fIflags\fR ] file ... \fB\-lcurses \-ltermlib\fR
86.el \fIcc\fR [ flags ] file ... \fI\-lcurses \-ltermlib\fR
87.)l
88.sh 2 "Screen Updating"
89.pp
90In order to update the screen optimally,
91it is necessary for the routines to know what the screen currently looks like
92and what the programmer wants it to look like next.
93For this purpose,
94a data type
95(structure)
96named
97.Vn WINDOW
98is defined
99which describes a window image to the routines,
100including its starting position on the screen
101(the \*y of the upper left hand corner)
102and its size.
103One of these
104(called
105.Vn curscr
106for
107.i "current screen" )
108is a screen image of what the terminal currently looks like.
109Another screen
110(called
111.Vn stdscr ,
112for
113.i "standard screen" )
114is provided
115by default
116to make changes on.
117.pp
118A window is a purely internal representation.
119It is used to build and store
120a potential image of a portion of the terminal.
121It doesn't bear any necessary relation
122to what is really on the terminal screen.
123It is more like an array of characters on which to make changes.
124.pp
125When one has a window which describes
126what some part the terminal should look like,
127the routine
128.Fn refresh
129(or
130.Fn wrefresh
131if the window is not
132.Vn stdscr )
133is called.
134.Fn refresh
135makes the terminal,
136in the area covered by the window,
137look like that window.
138Note, therefore, that changing something on a window
139.i does
140.bi not
141.i "change the terminal" .
142Actual updates to the terminal screen
143are made only by calling
144.Fn refresh
145or
146.Fn wrefresh .
147This allows the programmer to maintain several different ideas
148of what a portion of the terminal screen should look like.
149Also, changes can be made to windows in any order,
150without regard to motion efficiency.
151Then, at will,
152the programmer can effectively say
153.q "make it look like this,"
154and let the package worry about the best way to do this.
155.sh 2 "Naming Conventions"
156.pp
157As hinted above,
158the routines can use several windows,
159but two are automatically given:
160.Vn curscr ,
161which knows what the terminal looks like,
162and
163.Vn stdscr ,
164which is what the programmer wants the terminal to look like next.
165The user should never really access
166.Vn curscr
167directly.
168Changes should be made to
169the appropriate screen,
170and then the routine
171.Fn refresh
172(or
173.Fn wrefresh )
174should be called.
175.pp
176Many functions are set up to deal with
177.Vn stdscr
178as a default screen.
179For example, to add a character to
180.Vn stdscr ,
181one calls
182.Fn addch
183with the desired character.
184If a different window is to be used,
185the routine
186.Fn waddch
187(for
188.b w indow-specific
189.Fn addch )
190is provided\**.
191.(f
192\**
193Actually,
194.Fn addch
195is really a
196.q #define
197macro with arguments,
198as are most of the "functions" which deal with
199.Vn stdscr
200as a default.
201.)f
202This convention of prepending function names with a
203.Bq w
204when they are to be applied to specific windows
205is consistent.
206The only routines which do
207.i not
208do this are those
209to which a window must always be specified.
210.pp
211In order to move the current \*y from one point to another,
212the routines
213.Fn move
214and
215.Fn wmove
216are provided.
217However,
218it is often desirable to first move and then perform some I/O operation.
219In order to avoid clumsyness,
220most I/O routines can be preceded by the prefix
221.Bq mv
222and the desired \*y then can be added to the arguments to the function.
223For example,
224the calls
225.(l
226move(y\*,x);
227addch(ch);
228.)l
229can be replaced by
230.(l
231mvaddch(y\*,x\*,ch);
232.)l
233and
234.(l
235wmove(win\*,y\*,x);
236waddch(win\*,ch);
237.)l
238can be replaced by
239.(l
240mvwaddch(win\*,y\*,x\*,ch);
241.)l
242Note that the window description pointer
243.Vn win ) (
244comes before the added \*y.
245If such pointers are need,
246they are always the first parameters passed.