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