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