BSD 4_2 development
[unix-history] / usr / doc / curses / Curses.doc
CommitLineData
bd2570ea
KA
1
2
3
4
5.
6
7
8
9
10 Screen Updating and Cursor Movement Optimization:
11 A Library Package
12
13 _\bK_\be_\bn_\bn_\be_\bt_\bh _\bC. _\bR. _\bC. _\bA_\br_\bn_\bo_\bl_\bd
14
15 Computer Science Division
16 Department of Electrical Engineering and Computer Science
17 University of California, Berkeley
18 Berkeley, California 94720
19
20
21
22 _\bA_\bB_\bS_\bT_\bR_\bA_\bC_\bT
23
24
25
26
27
28 This document describes a package of C library
29 functions which allow the user to:
30
31 1) update a screen with reasonable optimization,
32
33 2) get input from the terminal in a screen-oriented
34 fashion, and
35
36 3) independent from the above, move the cursor op-
37 timally from one point to another.
38
39 These routines all use the /_\be_\bt_\bc/_\bt_\be_\br_\bm_\bc_\ba_\bp database to
40 describe the capabilities of the terminal.
41
42 _\bA_\bc_\bk_\bn_\bo_\bw_\bl_\be_\bd_\bg_\be_\bm_\be_\bn_\bt_\bs
43
44 This package would not exist without the work of Bill
45 Joy, who, in writing his editor, created the capability to
46 generally describe terminals, wrote the routines which read
47 this database, and, most importantly, those which implement
48 optimal cursor movement, which routines I have simply lifted
49 nearly intact. Doug Merritt and Kurt Shoens also were ex-
50 tremely important, as were both willing to waste time
51 listening to me rant and rave. The help and/or support of
52 Ken Abrams, Alan Char, Mark Horton, and Joe Kalash, was, and
53 is, also greatly appreciated.
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72.
73 Screen Package
74
75
76 _\b1. _\bO_\bv_\be_\br_\bv_\bi_\be_\bw
77
78 In making available the generalized terminal descrip-
79 tions in /_\be_\bt_\bc/_\bt_\be_\br_\bm_\bc_\ba_\bp, much information was made available
80 to the programmer, but little work was taken out of one's
81 hands. The purpose of this package is to allow the C pro-
82 grammer to do the most common type of terminal dependent
83 functions, those of movement optimization and optimal screen
84 updating, without doing any of the dirty work, and (hopeful-
85 ly) with nearly as much ease as is necessary to simply print
86 or read things.
87
88 The package is split into three parts: (1) Screen up-
89 dating; (2) Screen updating with user input; and (3) Cursor
90 motion optimization.
91
92 It is possible to use the motion optimization without
93 using either of the other two, and screen updating and input
94 can be done without any programmer knowledge of the motion
95 optimization, or indeed the database itself.
96
97 _\b1._\b1. _\bT_\be_\br_\bm_\bi_\bn_\bo_\bl_\bo_\bg_\by (_\bo_\br, _\bW_\bo_\br_\bd_\bs _\bY_\bo_\bu _\bC_\ba_\bn _\bS_\ba_\by _\bt_\bo _\bS_\bo_\bu_\bn_\bd _\bB_\br_\bi_\bl_\bl_\bi_\b-
98 _\ba_\bn_\bt)
99
100 In this document, the following terminology is kept to
101 with reasonable consistency:
102
103 _\bw_\bi_\bn_\bd_\bo_\bw: An internal representation containing an image of
104 what a section of the terminal screen may look like at
105 some point in time. This subsection can either encom-
106 pass the entire terminal screen, or any smaller portion
107 down to a single character within that screen.
108
109 _\bt_\be_\br_\bm_\bi_\bn_\ba_\bl: Sometimes called _\bt_\be_\br_\bm_\bi_\bn_\ba_\bl _\bs_\bc_\br_\be_\be_\bn. The package's
110 idea of what the terminal's screen currently looks
111 like, i.e., what the user sees now. This is a special
112 _\bs_\bc_\br_\be_\be_\bn:
113
114 _\bs_\bc_\br_\be_\be_\bn: This is a subset of windows which are as large as
115 the terminal screen, i.e., they start at the upper left
116 hand corner and encompass the lower right hand corner.
117 One of these, _\bs_\bt_\bd_\bs_\bc_\br, is automatically provided for the
118 programmer.
119
120 _\b1._\b2. _\bC_\bo_\bm_\bp_\bi_\bl_\bi_\bn_\bg _\bT_\bh_\bi_\bn_\bg_\bs
121
122 In order to use the library, it is necessary to have
123 certain types and variables defined. Therefore, the pro-
124 grammer must have a line:
125
126 #_\bi_\bn_\bc_\bl_\bu_\bd_\be <_\bc_\bu_\br_\bs_\be_\bs._\bh>
127
128 at the top of the program source. The header file
129
130
131 - 1 -
132
133
134
135
136
137
138
139.
140 Screen Package
141
142
143 <_\bc_\bu_\br_\bs_\be_\bs._\bh> needs to include <_\bs_\bg_\bt_\bt_\by._\bh>, so the one should not
144 do so oneself[1]. Also, compilations should have the fol-
145 lowing form:
146
147 _\bc_\bc [ flags ] file ... -_\bl_\bc_\bu_\br_\bs_\be_\bs -_\bl_\bt_\be_\br_\bm_\bl_\bi_\bb
148
149
150 _\b1._\b3. _\bS_\bc_\br_\be_\be_\bn _\bU_\bp_\bd_\ba_\bt_\bi_\bn_\bg
151
152 In order to update the screen optimally, it is neces-
153 sary for the routines to know what the screen currently
154 looks like and what the programmer wants it to look like
155 next. For this purpose, a data type (structure) named _\bW_\bI_\bN_\b-
156 _\bD_\bO_\bW is defined which describes a window image to the rou-
157 tines, including its starting position on the screen (the
158 (y, x) co-ordinates of the upper left hand corner) and its
159 size. One of these (called _\bc_\bu_\br_\bs_\bc_\br for _\bc_\bu_\br_\br_\be_\bn_\bt _\bs_\bc_\br_\be_\be_\bn) is a
160 screen image of what the terminal currently looks like.
161 Another screen (called _\bs_\bt_\bd_\bs_\bc_\br, for _\bs_\bt_\ba_\bn_\bd_\ba_\br_\bd _\bs_\bc_\br_\be_\be_\bn) is pro-
162 vided by default to make changes on.
163
164 A window is a purely internal representation. It is
165 used to build and store a potential image of a portion of
166 the terminal. It doesn't bear any necessary relation to
167 what is really on the terminal screen. It is more like an
168 array of characters on which to make changes.
169
170 When one has a window which describes what some part
171 the terminal should look like, the routine _\br_\be_\bf_\br_\be_\bs_\bh() (or
172 _\bw_\br_\be_\bf_\br_\be_\bs_\bh() if the window is not _\bs_\bt_\bd_\bs_\bc_\br) is called. _\br_\be_\b-
173 _\bf_\br_\be_\bs_\bh() makes the terminal, in the area covered by the win-
174 dow, look like that window. Note, therefore, that changing
175 something on a window _\bd_\bo_\be_\bs _\bn_\bo_\bt _\bc_\bh_\ba_\bn_\bg_\be _\bt_\bh_\be _\bt_\be_\br_\bm_\bi_\bn_\ba_\bl. Actual
176 updates to the terminal screen are made only by calling _\br_\be_\b-
177 _\bf_\br_\be_\bs_\bh() or _\bw_\br_\be_\bf_\br_\be_\bs_\bh(). This allows the programmer to main-
178 tain several different ideas of what a portion of the termi-
179 nal screen should look like. Also, changes can be made to
180 windows in any order, without regard to motion efficiency.
181 Then, at will, the programmer can effectively say "make it
182 look like this," and let the package worry about the best
183 way to do this.
184
185 _\b1._\b4. _\bN_\ba_\bm_\bi_\bn_\bg _\bC_\bo_\bn_\bv_\be_\bn_\bt_\bi_\bo_\bn_\bs
186
187 As hinted above, the routines can use several windows,
188 but two are automatically given: _\bc_\bu_\br_\bs_\bc_\br, which knows what
189 the terminal looks like, and _\bs_\bt_\bd_\bs_\bc_\br, which is what the pro-
190 ____________________
191 [1] The screen package also uses the Standard I/O li-
192 brary, so <_\bc_\bu_\br_\bs_\be_\bs._\bh> includes <_\bs_\bt_\bd_\bi_\bo._\bh>. It is redundant
193 (but harmless) for the programmer to do it, too.
194
195
196
197
198 - 2 -
199
200
201
202
203
204
205
206.
207 Screen Package
208
209
210 grammer wants the terminal to look like next. The user
211 should never really access _\bc_\bu_\br_\bs_\bc_\br directly. Changes should
212 be made to the appropriate screen, and then the routine _\br_\be_\b-
213 _\bf_\br_\be_\bs_\bh() (or _\bw_\br_\be_\bf_\br_\be_\bs_\bh()) should be called.
214
215 Many functions are set up to deal with _\bs_\bt_\bd_\bs_\bc_\br as a de-
216 fault screen. For example, to add a character to _\bs_\bt_\bd_\bs_\bc_\br,
217 one calls _\ba_\bd_\bd_\bc_\bh() with the desired character. If a dif-
218 ferent window is to be used, the routine _\bw_\ba_\bd_\bd_\bc_\bh() (for
219 _\bwindow-specific _\ba_\bd_\bd_\bc_\bh()) is provided[2]. This convention of
220 prepending function names with a "_\bw" when they are to be ap-
221 plied to specific windows is consistent. The only routines
222 which do _\bn_\bo_\bt do this are those to which a window must always
223 be specified.
224
225 In order to move the current (y, x) co-ordinates from
226 one point to another, the routines _\bm_\bo_\bv_\be() and _\bw_\bm_\bo_\bv_\be() are
227 provided. However, it is often desirable to first move and
228 then perform some I/O operation. In order to avoid clumsy-
229 ness, most I/O routines can be preceded by the prefix "_\bm_\bv"
230 and the desired (y, x) co-ordinates then can be added to the
231 arguments to the function. For example, the calls
232
233 move(y, x);
234 addch(ch);
235
236 can be replaced by
237
238 mvaddch(y, x, ch);
239
240 and
241
242 wmove(win, y, x);
243 waddch(win, ch);
244
245 can be replaced by
246
247 mvwaddch(win, y, x, ch);
248
249 Note that the window description pointer (_\bw_\bi_\bn) comes before
250 the added (y, x) co-ordinates. If such pointers are need,
251 they are always the first parameters passed.
252
253 _\b2. _\bV_\ba_\br_\bi_\ba_\bb_\bl_\be_\bs
254
255 Many variables which are used to describe the terminal
256 environment are available to the programmer. They are:
257 ____________________
258 [2] Actually, _\ba_\bd_\bd_\bc_\bh() is really a "#define" macro with
259 arguments, as are most of the "functions" which deal with
260 _\bs_\bt_\bd_\bs_\bc_\br as a default.
261
262
263
264
265 - 3 -
266
267
268
269
270
271
272
273.
274 Screen Package
275
276
277 type name description
278 __________________________________________________________________
279 WINDOW *curscr
280
281 current version of the screen (terminal screen).
282 WINDOW *stdscr
283
284 standard screen. Most updates are usually done
285 here.
286 char * Def_term
287
288 default terminal type if type cannot be determined
289 bool My_term
290
291 use the terminal specification in _\bD_\be_\bf__\bt_\be_\br_\bm as ter-
292 minal, irrelevant of real terminal type
293 char * ttytype
294
295 full name of the current terminal.
296 int LINES
297
298 number of lines on the terminal
299 int COLS
300
301 number of columns on the terminal
302 int ERR
303
304 error flag returned by routines on a fail.
305 int OK
306
307 error flag returned by routines when things go
308 right.
309
310
311 There are also several "#define" constants and types
312 which are of general usefulness:
313
314
315 reg storage class ``register'' (e.g., _\br_\be_\bg _\bi_\bn_\bt _\bi;)
316 bool boolean type, actually a ``char'' (e.g., _\bb_\bo_\bo_\bl _\bd_\bo_\bn_\be_\bi_\bt;)
317 TRUE boolean ``true'' flag (1).
318 FALSE boolean ``false'' flag (0).
319
320
321 _\b3. _\bU_\bs_\ba_\bg_\be
322
323 This is a description of how to actually use the screen
324 package. In it, we assume all updating, reading, etc. is
325 applied to _\bs_\bt_\bd_\bs_\bc_\br. All instructions will work on any win-
326 dow, with changing the function name and parameters as men-
327 tioned above.
328
329 _\b3._\b1. _\bS_\bt_\ba_\br_\bt_\bi_\bn_\bg _\bu_\bp
330
331 In order to use the screen package, the routines must
332 know about terminal characteristics, and the space for
333 _\bc_\bu_\br_\bs_\bc_\br and _\bs_\bt_\bd_\bs_\bc_\br must be allocated. These functions are
334 performed by _\bi_\bn_\bi_\bt_\bs_\bc_\br(). Since it must allocate space for
335 the windows, it can overflow core when attempting to do so.
336 On this rather rare occasion, _\bi_\bn_\bi_\bt_\bs_\bc_\br() returns ERR. _\bi_\bn_\b-
337 _\bi_\bt_\bs_\bc_\br() must _\ba_\bl_\bw_\ba_\by_\bs be called before any of the routines
338 which affect windows are used. If it is not, the program
339 will core dump as soon as either _\bc_\bu_\br_\bs_\bc_\br or _\bs_\bt_\bd_\bs_\bc_\br are refer-
340 enced. However, it is usually best to wait to call it until
341 after you are sure you will need it, like after checking for
342 startup errors. Terminal status changing routines like _\bn_\bl()
343 and _\bc_\br_\bm_\bo_\bd_\be() should be called after _\bi_\bn_\bi_\bt_\bs_\bc_\br().
344
345 Now that the screen windows have been allocated, you
346 can set them up for the run. If you want to, say, allow the
347 window to scroll, use _\bs_\bc_\br_\bo_\bl_\bl_\bo_\bk(). If you want the cursor to
348
349
350 - 4 -
351
352
353
354
355
356
357
358.
359 Screen Package
360
361
362 be left after the last change, use _\bl_\be_\ba_\bv_\be_\bo_\bk(). If this isn't
363 done, _\br_\be_\bf_\br_\be_\bs_\bh() will move the cursor to the window's current
364 (y, x) co-ordinates after updating it. New windows of your
365 own can be created, too, by using the functions _\bn_\be_\bw_\bw_\bi_\bn() and
366 _\bs_\bu_\bb_\bw_\bi_\bn(). _\bd_\be_\bl_\bw_\bi_\bn() will allow you to get rid of old win-
367 dows. If you wish to change the official size of the termi-
368 nal by hand, just set the variables _\bL_\bI_\bN_\bE_\bS and _\bC_\bO_\bL_\bS to be
369 what you want, and then call _\bi_\bn_\bi_\bt_\bs_\bc_\br(). This is best done
370 before, but can be done either before or after, the first
371 call to _\bi_\bn_\bi_\bt_\bs_\bc_\br(), as it will always delete any existing
372 _\bs_\bt_\bd_\bs_\bc_\br and/or _\bc_\bu_\br_\bs_\bc_\br before creating new ones.
373
374 _\b3._\b2. _\bT_\bh_\be _\bN_\bi_\bt_\bt_\by-_\bG_\br_\bi_\bt_\bt_\by
375
376 _\b3._\b2._\b1. _\bO_\bu_\bt_\bp_\bu_\bt
377
378 Now that we have set things up, we will want to actual-
379 ly update the terminal. The basic functions used to change
380 what will go on a window are _\ba_\bd_\bd_\bc_\bh() and _\bm_\bo_\bv_\be(). _\ba_\bd_\bd_\bc_\bh()
381 adds a character at the current (y, x) co-ordinates, return-
382 ing ERR if it would cause the window to illegally scroll,
383 i.e., printing a character in the lower right-hand corner of
384 a terminal which automatically scrolls if scrolling is not
385 allowed. _\bm_\bo_\bv_\be() changes the current (y, x) co-ordinates to
386 whatever you want them to be. It returns ERR if you try to
387 move off the window when scrolling is not allowed. As men-
388 tioned above, you can combine the two into _\bm_\bv_\ba_\bd_\bd_\bc_\bh() to do
389 both things in one fell swoop.
390
391 The other output functions, such as _\ba_\bd_\bd_\bs_\bt_\br() and
392 _\bp_\br_\bi_\bn_\bt_\bw(), all call _\ba_\bd_\bd_\bc_\bh() to add characters to the window.
393
394 After you have put on the window what you want there,
395 when you want the portion of the terminal covered by the
396 window to be made to look like it, you must call _\br_\be_\bf_\br_\be_\bs_\bh().
397 In order to optimize finding changes, _\br_\be_\bf_\br_\be_\bs_\bh() assumes that
398 any part of the window not changed since the last _\br_\be_\bf_\br_\be_\bs_\bh()
399 of that window has not been changed on the terminal, i.e.,
400 that you have not refreshed a portion of the terminal with
401 an overlapping window. If this is not the case, the routine
402 _\bt_\bo_\bu_\bc_\bh_\bw_\bi_\bn() is provided to make it look like the entire win-
403 dow has been changed, thus making _\br_\be_\bf_\br_\be_\bs_\bh() check the whole
404 subsection of the terminal for changes.
405
406 If you call _\bw_\br_\be_\bf_\br_\be_\bs_\bh() with _\bc_\bu_\br_\bs_\bc_\br, it will make the
407 screen look like _\bc_\bu_\br_\bs_\bc_\br thinks it looks like. This is use-
408 ful for implementing a command which would redraw the screen
409 in case it get messed up.
410
411 _\b3._\b2._\b2. _\bI_\bn_\bp_\bu_\bt
412
413 Input is essentially a mirror image of output. The
414 complementary function to _\ba_\bd_\bd_\bc_\bh() is _\bg_\be_\bt_\bc_\bh() which, if echo
415
416
417 - 5 -
418
419
420
421
422
423
424
425.
426 Screen Package
427
428
429 is set, will call _\ba_\bd_\bd_\bc_\bh() to echo the character. Since the
430 screen package needs to know what is on the terminal at all
431 times, if characters are to be echoed, the tty must be in
432 raw or cbreak mode. If it is not, _\bg_\be_\bt_\bc_\bh() sets it to be
433 cbreak, and then reads in the character.
434
435 _\b3._\b2._\b3. _\bM_\bi_\bs_\bc_\be_\bl_\bl_\ba_\bn_\be_\bo_\bu_\bs
436
437 All sorts of fun functions exists for maintaining and
438 changing information about the windows. For the most part,
439 the descriptions in section 5.4. should suffice.
440
441 _\b3._\b3. _\bF_\bi_\bn_\bi_\bs_\bh_\bi_\bn_\bg _\bu_\bp
442
443 In order to do certain optimizations, and, on some ter-
444 minals, to work at all, some things must be done before the
445 screen routines start up. These functions are performed in
446 _\bg_\be_\bt_\bt_\bt_\bm_\bo_\bd_\be() and _\bs_\be_\bt_\bt_\be_\br_\bm(), which are called by _\bi_\bn_\bi_\bt_\bs_\bc_\br().
447 In order to clean up after the routines, the routine
448 _\be_\bn_\bd_\bw_\bi_\bn() is provided. It restores tty modes to what they
449 were when _\bi_\bn_\bi_\bt_\bs_\bc_\br() was first called. Thus, anytime after
450 the call to initscr, _\be_\bn_\bd_\bw_\bi_\bn() should be called before exit-
451 ing.
452
453 _\b4. _\bC_\bu_\br_\bs_\bo_\br _\bM_\bo_\bt_\bi_\bo_\bn _\bO_\bp_\bt_\bi_\bm_\bi_\bz_\ba_\bt_\bi_\bo_\bn: _\bS_\bt_\ba_\bn_\bd_\bi_\bn_\bg _\bA_\bl_\bo_\bn_\be
454
455 It is possible to use the cursor optimization functions
456 of this screen package without the overhead and additional
457 size of the screen updating functions. The screen updating
458 functions are designed for uses where parts of the screen
459 are changed, but the overall image remains the same. This
460 includes such programs as _\be_\by_\be and _\bv_\bi[3]. Certain other pro-
461 grams will find it difficult to use these functions in this
462 manner without considerable unnecessary program overhead.
463 For such applications, such as some "_\bc_\br_\bt _\bh_\ba_\bc_\bk_\bs"[4] and op-
464 timizing _\bc_\ba_\bt(1)-type programs, all that is needed is the mo-
465 tion optimizations. This, therefore, is a description of
466 what some of what goes on at the lower levels of this screen
467 package. The descriptions assume a certain amount of fami-
468 liarity with programming problems and some finer points of
469 C. None of it is terribly difficult, but you should be
470 forewarned.
471
472
473
474 ____________________
475 [3] _\bE_\by_\be actually uses these functions, _\bv_\bi does not.
476 [4] Graphics programs designed to run on character-
477 oriented terminals. I could name many, but they come and
478 go, so the list would be quickly out of date. Recently,
479 there have been programs such as _\br_\bo_\bc_\bk_\be_\bt and _\bg_\bu_\bn.
480
481
482
483
484 - 6 -
485
486
487
488
489
490
491
492.
493 Screen Package
494
495
496 _\b4._\b1. _\bT_\be_\br_\bm_\bi_\bn_\ba_\bl _\bI_\bn_\bf_\bo_\br_\bm_\ba_\bt_\bi_\bo_\bn
497
498 In order to use a terminal's features to the best of a
499 program's abilities, it must first know what they are[5].
500 The /_\be_\bt_\bc/_\bt_\be_\br_\bm_\bc_\ba_\bp database describes these, but a certain
501 amount of decoding is necessary, and there are, of course,
502 both efficient and inefficient ways of reading them in. The
503 algorithm that the uses is taken from _\bv_\bi and is hideously
504 efficient. It reads them in a tight loop into a set of
505 variables whose names are two uppercase letters with some
506 mnemonic value. For example, _\bH_\bO is a string which moves the
507 cursor to the "home" position[6]. As there are two types of
508 variables involving ttys, there are two routines. The
509 first, _\bg_\be_\bt_\bt_\bm_\bo_\bd_\be(), sets some variables based upon the tty
510 modes accessed by _\bg_\bt_\bt_\by(2) and _\bs_\bt_\bt_\by(2) The second, _\bs_\be_\bt_\bt_\be_\br_\bm(),
511 a larger task by reading in the descriptions from the
512 /_\be_\bt_\bc/_\bt_\be_\br_\bm_\bc_\ba_\bp database. This is the way these routines are
513 used by _\bi_\bn_\bi_\bt_\bs_\bc_\br():
514
515
516 _\bi_\bf (isatty(0)) {
517 gettmode();
518 _\bi_\bf (sp=getenv("TERM"))
519 setterm(sp);
520 }
521 _\be_\bl_\bs_\be
522 setterm(Def_term);
523 _puts(TI);
524 _puts(VS);
525
526
527
528 _\bi_\bs_\ba_\bt_\bt_\by() checks to see if file descriptor 0 is a termi-
529 nal[7]. If it is, _\bg_\be_\bt_\bt_\bm_\bo_\bd_\be() sets the terminal description
530 modes from a _\bg_\bt_\bt_\by(2) _\bg_\be_\bt_\be_\bn_\bv() is then called to get the name
531 of the terminal, and that value (if there is one) is passed
532 to _\bs_\be_\bt_\bt_\be_\br_\bm(), which reads in the variables from /_\be_\bt_\bc/_\bt_\be_\br_\bm_\bc_\ba_\bp
533 associated with that terminal. (_\bg_\be_\bt_\be_\bn_\bv() returns a pointer
534 to a string containing the name of the terminal, which we
535 save in the character pointer _\bs_\bp.) If _\bi_\bs_\ba_\bt_\bt_\by() returns
536 ____________________
537 [5] If this comes as any surprise to you, there's this
538 tower in Paris they're thinking of junking that I can let
539 you have for a song.
540 [6] These names are identical to those variables used in
541 the /_\be_\bt_\bc/_\bt_\be_\br_\bm_\bc_\ba_\bp database to describe each capability. See
542 Appendix A for a complete list of those read, and _\bt_\be_\br_\bm_\bc_\ba_\bp(5)
543 for a full description.
544 [7] _\bi_\bs_\ba_\bt_\bt_\by() is defined in the default C library function
545 routines. It does a _\bg_\bt_\bt_\by(2) on the descriptor and checks
546 the return value.
547
548
549
550
551 - 7 -
552
553
554
555
556
557
558
559.
560 Screen Package
561
562
563 false, the default terminal _\bD_\be_\bf__\bt_\be_\br_\bm is used. The _\bT_\bI and _\bV_\bS
564 sequences initialize the terminal (__\bp_\bu_\bt_\bs() is a macro which
565 uses _\bt_\bp_\bu_\bt_\bs() (see _\bt_\be_\br_\bm_\bc_\ba_\bp(3)) to put out a string). It is
566 these things which _\be_\bn_\bd_\bw_\bi_\bn() undoes.
567
568 _\b4._\b2. _\bM_\bo_\bv_\be_\bm_\be_\bn_\bt _\bO_\bp_\bt_\bi_\bm_\bi_\bz_\ba_\bt_\bi_\bo_\bn_\bs, _\bo_\br, _\bG_\be_\bt_\bt_\bi_\bn_\bg _\bO_\bv_\be_\br _\bY_\bo_\bn_\bd_\be_\br
569
570 Now that we have all this useful information, it would
571 be nice to do something with it[8]. The most difficult
572 thing to do properly is motion optimization. When you con-
573 sider how many different features various terminals have
574 (tabs, backtabs, non-destructive space, home sequences, ab-
575 solute tabs, .....) you can see that deciding how to get
576 from here to there can be a decidedly non-trivial task. The
577 editor _\bv_\bi uses many of these features, and the routines it
578 uses to do this take up many pages of code. Fortunately, I
579 was able to liberate them with the author's permission, and
580 use them here.
581
582 After using _\bg_\be_\bt_\bt_\bm_\bo_\bd_\be() and _\bs_\be_\bt_\bt_\be_\br_\bm() to get the termi-
583 nal descriptions, the function _\bm_\bv_\bc_\bu_\br() deals with this task.
584 It usage is simple: you simply tell it where you are now and
585 where you want to go. For example
586
587 mvcur(0, 0, LINES/2, COLS/2)
588
589
590 would move the cursor from the home position (0, 0) to the
591 middle of the screen. If you wish to force absolute ad-
592 dressing, you can use the function _\bt_\bg_\bo_\bt_\bo() from the _\bt_\be_\br_\bm_\b-
593 _\bl_\bi_\bb(7) routines, or you can tell _\bm_\bv_\bc_\bu_\br() that you are impos-
594 sibly far away, like Cleveland. For example, to absolutely
595 address the lower left hand corner of the screen from any-
596 where just claim that you are in the upper right hand
597 corner:
598
599 mvcur(0, COLS-1, LINES-1, 0)
600
601
602 _\b5. _\bT_\bh_\be _\bF_\bu_\bn_\bc_\bt_\bi_\bo_\bn_\bs
603
604 In the following definitions, "[*]" means that the
605 "function" is really a "#define" macro with arguments. This
606 means that it will not show up in stack traces in the de-
607 bugger, or, in the case of such functions as _\ba_\bd_\bd_\bc_\bh(), it
608 will show up as it's "_\bw" counterpart. The arguments are
609 given to show the order and type of each. Their names are
610 ____________________
611 [8] Actually, it _\bc_\ba_\bn be emotionally fulfilling just to
612 get the information. This is usually only true, however, if
613 you have the social life of a kumquat.
614
615
616
617
618 - 8 -
619
620
621
622
623
624
625
626.
627 Screen Package
628
629
630 not mandatory, just suggestive.
631
632 _\b5._\b1. _\bO_\bu_\bt_\bp_\bu_\bt _\bF_\bu_\bn_\bc_\bt_\bi_\bo_\bn_\bs
633
634
635
636 _\ba_\bd_\bd_\bc_\bh(_\bc_\bh) [*]
637 char ch;
638
639 _\bw_\ba_\bd_\bd_\bc_\bh(_\bw_\bi_\bn, _\bc_\bh)
640 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
641 _\bc_\bh_\ba_\br _\bc_\bh;
642
643 Add the character _\bc_\bh on the window at the current
644 (y, x) co-ordinates. If the character is a newline
645 ('\n') the line will be cleared to the end, and the
646 current (y, x) co-ordinates will be changed to the be-
647 ginning off the next line if newline mapping is on, or
648 to the next line at the same x co-ordinate if it is
649 off. A return ('\r') will move to the beginning of the
650 line on the window. Tabs ('\t') will be expanded into
651 spaces in the normal tabstop positions of every eight
652 characters. This returns ERR if it would cause the
653 screen to scroll illegally.
654
655
656
657 _\ba_\bd_\bd_\bs_\bt_\br(_\bs_\bt_\br) [*]
658 _\bc_\bh_\ba_\br *_\bs_\bt_\br;
659
660 _\bw_\ba_\bd_\bd_\bs_\bt_\br(_\bw_\bi_\bn, _\bs_\bt_\br)
661 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
662 _\bc_\bh_\ba_\br *_\bs_\bt_\br;
663
664 Add the string pointed to by _\bs_\bt_\br on the window at the
665 current (y, x) co-ordinates. This returns ERR if it
666 would cause the screen to scroll illegally. In this
667 case, it will put on as much as it can.
668
669
670
671 _\bb_\bo_\bx(_\bw_\bi_\bn, _\bv_\be_\br_\bt, _\bh_\bo_\br)
672 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
673 _\bc_\bh_\ba_\br _\bv_\be_\br_\bt, _\bh_\bo_\br;
674
675 Draws a box around the window using _\bv_\be_\br_\bt as the charac-
676 ter for drawing the vertical sides, and _\bh_\bo_\br for drawing
677 the horizontal lines. If scrolling is not allowed, and
678 the window encompasses the lower right-hand corner of
679 the terminal, the corners are left blank to avoid a
680 scroll.
681
682
683
684
685 - 9 -
686
687
688
689
690
691
692
693.
694 Screen Package
695
696
697
698 _\bc_\bl_\be_\ba_\br() [*]
699
700 _\bw_\bc_\bl_\be_\ba_\br(_\bw_\bi_\bn)
701 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
702
703 Resets the entire window to blanks. If _\bw_\bi_\bn is a
704 screen, this sets the clear flag, which will cause a
705 clear-screen sequence to be sent on the next _\br_\be_\bf_\br_\be_\bs_\bh()
706 call. This also moves the current (y, x) co-ordinates
707 to (0, 0).
708
709
710
711 _\bc_\bl_\be_\ba_\br_\bo_\bk(_\bs_\bc_\br, _\bb_\bo_\bo_\bl_\bf) [*]
712 _\bW_\bI_\bN_\bD_\bO_\bW *_\bs_\bc_\br;
713 _\bb_\bo_\bo_\bl _\bb_\bo_\bo_\bl_\bf;
714
715 Sets the clear flag for the screen _\bs_\bc_\br. If _\bb_\bo_\bo_\bl_\bf is
716 TRUE, this will force a clear-screen to be printed on
717 the next _\br_\be_\bf_\br_\be_\bs_\bh(), or stop it from doing so if _\bb_\bo_\bo_\bl_\bf
718 is FALSE. This only works on screens, and, unlike
719 _\bc_\bl_\be_\ba_\br(), does not alter the contents of the screen. If
720 _\bs_\bc_\br is _\bc_\bu_\br_\bs_\bc_\br, the next _\br_\be_\bf_\br_\be_\bs_\bh() call will cause a
721 clear-screen, even if the window passed to _\br_\be_\bf_\br_\be_\bs_\bh() is
722 not a screen.
723
724
725
726 _\bc_\bl_\br_\bt_\bo_\bb_\bo_\bt() [*]
727
728 _\bw_\bc_\bl_\br_\bt_\bo_\bb_\bo_\bt(_\bw_\bi_\bn)
729 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
730
731 Wipes the window clear from the current (y, x) co-
732 ordinates to the bottom. This does not force a clear-
733 screen sequence on the next refresh under any cir-
734 cumstances. This has no associated "mv" command.
735
736
737
738 _\bc_\bl_\br_\bt_\bo_\be_\bo_\bl() [*]
739
740 _\bw_\bc_\bl_\br_\bt_\bo_\be_\bo_\bl(_\bw_\bi_\bn)
741 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
742
743 Wipes the window clear from the current (y, x) co-
744 ordinates to the end of the line. This has no associ-
745 ated "mv" command.
746
747
748
749 _\bd_\be_\bl_\bc_\bh()
750
751
752 - 10 -
753
754
755
756
757
758
759
760.
761 Screen Package
762
763
764
765 _\bw_\bd_\be_\bl_\bc_\bh(_\bw_\bi_\bn)
766 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
767
768 Delete the character at the current (y, x) co-
769 ordinates. Each character after it on the line shifts
770 to the left, and the last character becomes blank.
771
772
773
774 _\bd_\be_\bl_\be_\bt_\be_\bl_\bn()
775
776 _\bw_\bd_\be_\bl_\be_\bt_\be_\bl_\bn(_\bw_\bi_\bn)
777 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
778
779 Delete the current line. Every line below the current
780 one will move up, and the bottom line will become
781 blank. The current (y, x) co-ordinates will remain un-
782 changed.
783
784
785
786 _\be_\br_\ba_\bs_\be() [*]
787
788 _\bw_\be_\br_\ba_\bs_\be(_\bw_\bi_\bn)
789 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
790
791 Erases the window to blanks without setting the clear
792 flag. This is analagous to _\bc_\bl_\be_\ba_\br(), except that it
793 never causes a clear-screen sequence to be generated on
794 a _\br_\be_\bf_\br_\be_\bs_\bh(). This has no associated "mv" command.
795
796
797
798 _\bi_\bn_\bs_\bc_\bh(_\bc)
799 _\bc_\bh_\ba_\br _\bc;
800
801 _\bw_\bi_\bn_\bs_\bc_\bh(_\bw_\bi_\bn, _\bc)
802 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
803 _\bc_\bh_\ba_\br _\bc;
804
805 Insert _\bc at the current (y, x) co-ordinates Each char-
806 acter after it shifts to the right, and the last char-
807 acter disappears. This returns ERR if it would cause
808 the screen to scroll illegally.
809
810
811
812 _\bi_\bn_\bs_\be_\br_\bt_\bl_\bn()
813
814 _\bw_\bi_\bn_\bs_\be_\br_\bt_\bl_\bn(_\bw_\bi_\bn)
815 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
816
817
818
819 - 11 -
820
821
822
823
824
825
826
827.
828 Screen Package
829
830
831 Insert a line above the current one. Every line below
832 the current line will be shifted down, and the bottom
833 line will disappear. The current line will become
834 blank, and the current (y, x) co-ordinates will remain
835 unchanged. This returns ERR if it would cause the
836 screen to scroll illegally.
837
838
839
840 _\bm_\bo_\bv_\be(_\by, _\bx) [*]
841 _\bi_\bn_\bt _\by, _\bx;
842
843 _\bw_\bm_\bo_\bv_\be(_\bw_\bi_\bn, _\by, _\bx)
844 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
845 _\bi_\bn_\bt _\by, _\bx;
846
847 Change the current (y, x) co-ordinates of the window to
848 (_\by, _\bx). This returns ERR if it would cause the screen
849 to scroll illegally.
850
851
852
853 _\bo_\bv_\be_\br_\bl_\ba_\by(_\bw_\bi_\bn_\b1, _\bw_\bi_\bn_\b2)
854 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn_\b1, *_\bw_\bi_\bn_\b2;
855
856 Overlay _\bw_\bi_\bn_\b1 on _\bw_\bi_\bn_\b2. The contents of _\bw_\bi_\bn_\b1, insofar as
857 they fit, are placed on _\bw_\bi_\bn_\b2 at their starting (y, x)
858 co-ordinates. This is done non-destructively, i.e.,
859 blanks on _\bw_\bi_\bn_\b1 leave the contents of the space on _\bw_\bi_\bn_\b2
860 untouched.
861
862
863
864 _\bo_\bv_\be_\br_\bw_\br_\bi_\bt_\be(_\bw_\bi_\bn_\b1, _\bw_\bi_\bn_\b2)
865 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn_\b1, *_\bw_\bi_\bn_\b2;
866
867 Overwrite _\bw_\bi_\bn_\b1 on _\bw_\bi_\bn_\b2. The contents of _\bw_\bi_\bn_\b1, insofar
868 as they fit, are placed on _\bw_\bi_\bn_\b2 at their starting
869 (y, x) co-ordinates. This is done destructively, i.e.,
870 blanks on _\bw_\bi_\bn_\b1 become blank on _\bw_\bi_\bn_\b2.
871
872
873
874 _\bp_\br_\bi_\bn_\bt_\bw(_\bf_\bm_\bt, _\ba_\br_\bg_\b1, _\ba_\br_\bg_\b2, ...)
875 _\bc_\bh_\ba_\br *_\bf_\bm_\bt;
876
877 _\bw_\bp_\br_\bi_\bn_\bt_\bw(_\bw_\bi_\bn, _\bf_\bm_\bt, _\ba_\br_\bg_\b1, _\ba_\br_\bg_\b2, ...)
878 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
879 _\bc_\bh_\ba_\br *_\bf_\bm_\bt;
880
881 Performs a _\bp_\br_\bi_\bn_\bt_\bf() on the window starting at the
882 current (y, x) co-ordinates. It uses _\ba_\bd_\bd_\bs_\bt_\br() to add
883 the string on the window. It is often advisable to use
884
885
886 - 12 -
887
888
889
890
891
892
893
894.
895 Screen Package
896
897
898 the field width options of _\bp_\br_\bi_\bn_\bt_\bf() to avoid leaving
899 things on the window from earlier calls. This returns
900 ERR if it would cause the screen to scroll illegally.
901
902
903
904 _\br_\be_\bf_\br_\be_\bs_\bh() [*]
905
906 _\bw_\br_\be_\bf_\br_\be_\bs_\bh(_\bw_\bi_\bn)
907 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
908
909 Synchronize the terminal screen with the desired win-
910 dow. If the window is not a screen, only that part
911 covered by it is updated. This returns ERR if it would
912 cause the screen to scroll illegally. In this case, it
913 will update whatever it can without causing the scroll.
914
915
916
917 _\bs_\bt_\ba_\bn_\bd_\bo_\bu_\bt() [*]
918
919 _\bw_\bs_\bt_\ba_\bn_\bd_\bo_\bu_\bt(_\bw_\bi_\bn)
920 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
921
922 _\bs_\bt_\ba_\bn_\bd_\be_\bn_\bd() [*]
923
924 _\bw_\bs_\bt_\ba_\bn_\bd_\be_\bn_\bd(_\bw_\bi_\bn)
925 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
926
927 Start and stop putting characters onto _\bw_\bi_\bn in standout
928 mode. _\bs_\bt_\ba_\bn_\bd_\bo_\bu_\bt() causes any characters added to the
929 window to be put in standout mode on the terminal (if
930 it has that capability). _\bs_\bt_\ba_\bn_\bd_\be_\bn_\bd() stops this. The
931 sequences _\bS_\bO and _\bS_\bE (or _\bU_\bS and _\bU_\bE if they are not de-
932 fined) are used (see Appendix A).
933
934 _\b5._\b2. _\bI_\bn_\bp_\bu_\bt _\bF_\bu_\bn_\bc_\bt_\bi_\bo_\bn_\bs
935
936
937
938 _\bc_\br_\bm_\bo_\bd_\be() [*]
939
940 _\bn_\bo_\bc_\br_\bm_\bo_\bd_\be() [*]
941
942 Set or unset the terminal to/from cbreak mode.
943
944
945
946 _\be_\bc_\bh_\bo() [*]
947
948 _\bn_\bo_\be_\bc_\bh_\bo() [*]
949
950
951
952
953 - 13 -
954
955
956
957
958
959
960
961.
962 Screen Package
963
964
965 Sets the terminal to echo or not echo characters.
966
967
968
969 _\bg_\be_\bt_\bc_\bh() [*]
970
971 _\bw_\bg_\be_\bt_\bc_\bh(_\bw_\bi_\bn)
972 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
973
974 Gets a character from the terminal and (if necessary)
975 echos it on the window. This returns ERR if it would
976 cause the screen to scroll illegally. Otherwise, the
977 character gotten is returned. If _\bn_\bo_\be_\bc_\bh_\bo has been set,
978 then the window is left unaltered. In order to retain
979 control of the terminal, it is necessary to have one of
980 _\bn_\bo_\be_\bc_\bh_\bo, _\bc_\bb_\br_\be_\ba_\bk, or _\br_\ba_\bw_\bm_\bo_\bd_\be set. If you do not set one,
981 whatever routine you call to read characters will set
982 _\bc_\bb_\br_\be_\ba_\bk for you, and then reset to the original mode
983 when finished.
984
985
986
987 _\bg_\be_\bt_\bs_\bt_\br(_\bs_\bt_\br) [*]
988 _\bc_\bh_\ba_\br *_\bs_\bt_\br;
989
990 _\bw_\bg_\be_\bt_\bs_\bt_\br(_\bw_\bi_\bn, _\bs_\bt_\br)
991 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
992 _\bc_\bh_\ba_\br *_\bs_\bt_\br;
993
994 Get a string through the window and put it in the loca-
995 tion pointed to by _\bs_\bt_\br, which is assumed to be large
996 enough to handle it. It sets tty modes if necessary,
997 and then calls _\bg_\be_\bt_\bc_\bh() (or _\bw_\bg_\be_\bt_\bc_\bh(_\bw_\bi_\bn)) to get the
998 characters needed to fill in the string until a newline
999 or EOF is encountered. The newline stripped off the
1000 string. This returns ERR if it would cause the screen
1001 to scroll illegally.
1002
1003
1004
1005 _\br_\ba_\bw() [*]
1006
1007 _\bn_\bo_\br_\ba_\bw() [*]
1008
1009 Set or unset the terminal to/from raw mode. On version
1010 7 _\bU_\bN_\bI_\bX[_\b9] this also turns of newline mapping (see
1011 _\bn_\bl()).
1012
1013
1014 ____________________
1015 [9] _\bU_\bN_\bI_\bX is a trademark of Bell Laboratories.
1016
1017
1018
1019
1020 - 14 -
1021
1022
1023
1024
1025
1026
1027
1028.
1029 Screen Package
1030
1031
1032
1033 _\bs_\bc_\ba_\bn_\bw(_\bf_\bm_\bt, _\ba_\br_\bg_\b1, _\ba_\br_\bg_\b2, ...)
1034 _\bc_\bh_\ba_\br *_\bf_\bm_\bt;
1035
1036 _\bw_\bs_\bc_\ba_\bn_\bw(_\bw_\bi_\bn, _\bf_\bm_\bt, _\ba_\br_\bg_\b1, _\ba_\br_\bg_\b2, ...)
1037 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
1038 _\bc_\bh_\ba_\br *_\bf_\bm_\bt;
1039
1040 Perform a _\bs_\bc_\ba_\bn_\bf() through the window using _\bf_\bm_\bt. It
1041 does this using consecutive _\bg_\be_\bt_\bc_\bh()'s (or
1042 _\bw_\bg_\be_\bt_\bc_\bh(_\bw_\bi_\bn)'s). This returns ERR if it would cause the
1043 screen to scroll illegally.
1044
1045 _\b5._\b3. _\bM_\bi_\bs_\bc_\be_\bl_\bl_\ba_\bn_\be_\bo_\bu_\bs _\bF_\bu_\bn_\bc_\bt_\bi_\bo_\bn_\bs
1046
1047
1048
1049 _\bd_\be_\bl_\bw_\bi_\bn(_\bw_\bi_\bn)
1050 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
1051
1052 Deletes the window from existence. All resources are
1053 freed for future use by _\bc_\ba_\bl_\bl_\bo_\bc(3). If a window has a
1054 _\bs_\bu_\bb_\bw_\bi_\bn() allocated window inside of it, deleting the
1055 outer window the subwindow is not affected, even though
1056 this does invalidate it. Therefore, subwindows should
1057 be deleted before their outer windows are.
1058
1059
1060
1061 _\be_\bn_\bd_\bw_\bi_\bn()
1062
1063 Finish up window routines before exit. This restores
1064 the terminal to the state it was before _\bi_\bn_\bi_\bt_\bs_\bc_\br() (or
1065 _\bg_\be_\bt_\bt_\bm_\bo_\bd_\be() and _\bs_\be_\bt_\bt_\be_\br_\bm()) was called. It should always
1066 be called before exiting. It does not exit. This is
1067 especially useful for resetting tty stats when trapping
1068 rubouts via _\bs_\bi_\bg_\bn_\ba_\bl(2).
1069
1070
1071
1072 _\bg_\be_\bt_\by_\bx(_\bw_\bi_\bn, _\by, _\bx) [*]
1073 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
1074 _\bi_\bn_\bt _\by, _\bx;
1075
1076 Puts the current (y, x) co-ordinates of _\bw_\bi_\bn in the
1077 variables _\by and _\bx. Since it is a macro, not a func-
1078 tion, you do not pass the address of _\by and _\bx.
1079
1080
1081
1082 _\bi_\bn_\bc_\bh() [*]
1083
1084 _\bw_\bi_\bn_\bc_\bh(_\bw_\bi_\bn) [*]
1085
1086
1087 - 15 -
1088
1089
1090
1091
1092
1093
1094
1095.
1096 Screen Package
1097
1098
1099 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
1100
1101 Returns the character at the current (y, x) co-
1102 ordinates on the given window. This does not make any
1103 changes to the window. This has no associated "mv"
1104 command.
1105
1106
1107
1108 _\bi_\bn_\bi_\bt_\bs_\bc_\br()
1109
1110 Initialize the screen routines. This must be called
1111 before any of the screen routines are used. It ini-
1112 tializes the terminal-type data and such, and without
1113 it, none of the routines can operate. If standard in-
1114 put is not a tty, it sets the specifications to the
1115 terminal whose name is pointed to by _\bD_\be_\bf__\bt_\be_\br_\bm (initialy
1116 "dumb"). If the boolean _\bM_\by__\bt_\be_\br_\bm is true, _\bD_\be_\bf__\bt_\be_\br_\bm is
1117 always used.
1118
1119
1120
1121 _\bl_\be_\ba_\bv_\be_\bo_\bk(_\bw_\bi_\bn, _\bb_\bo_\bo_\bl_\bf) [*]
1122 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
1123 _\bb_\bo_\bo_\bl _\bb_\bo_\bo_\bl_\bf;
1124
1125 Sets the boolean flag for leaving the cursor after the
1126 last change. If _\bb_\bo_\bo_\bl_\bf is TRUE, the cursor will be left
1127 after the last update on the terminal, and the current
1128 (y, x) co-ordinates for _\bw_\bi_\bn will be changed according-
1129 ly. If it is FALSE, it will be moved to the current
1130 (y, x) co-ordinates. This flag (initialy FALSE) re-
1131 tains its value until changed by the user.
1132
1133
1134
1135 _\bl_\bo_\bn_\bg_\bn_\ba_\bm_\be(_\bt_\be_\br_\bm_\bb_\bu_\bf, _\bn_\ba_\bm_\be)
1136 _\bc_\bh_\ba_\br *_\bt_\be_\br_\bm_\bb_\bu_\bf, *_\bn_\ba_\bm_\be;
1137
1138 Fills in _\bn_\ba_\bm_\be with the long (full) name of the terminal
1139 described by the termcap entry in _\bt_\be_\br_\bm_\bb_\bu_\bf. It is gen-
1140 erally of little use, but is nice for telling the user
1141 in a readable format what terminal we think he has.
1142 This is available in the global variable _\bt_\bt_\by_\bt_\by_\bp_\be.
1143 _\bT_\be_\br_\bm_\bb_\bu_\bf is usually set via the termlib routine
1144 _\bt_\bg_\be_\bt_\be_\bn_\bt().
1145
1146
1147
1148 _\bm_\bv_\bw_\bi_\bn(_\bw_\bi_\bn, _\by, _\bx)
1149 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
1150 _\bi_\bn_\bt _\by, _\bx;
1151
1152
1153
1154 - 16 -
1155
1156
1157
1158
1159
1160
1161
1162.
1163 Screen Package
1164
1165
1166 Move the home position of the window _\bw_\bi_\bn from its
1167 current starting coordinates to (_\by, _\bx). If that would
1168 put part or all of the window off the edge of the ter-
1169 minal screen, _\bm_\bv_\bw_\bi_\bn() returns ERR and does not change
1170 anything.
1171
1172
1173 _\bW_\bI_\bN_\bD_\bO_\bW *
1174 _\bn_\be_\bw_\bw_\bi_\bn(_\bl_\bi_\bn_\be_\bs, _\bc_\bo_\bl_\bs, _\bb_\be_\bg_\bi_\bn__\by, _\bb_\be_\bg_\bi_\bn__\bx)
1175 _\bi_\bn_\bt _\bl_\bi_\bn_\be_\bs, _\bc_\bo_\bl_\bs, _\bb_\be_\bg_\bi_\bn__\by, _\bb_\be_\bg_\bi_\bn__\bx;
1176
1177 Create a new window with _\bl_\bi_\bn_\be_\bs lines and _\bc_\bo_\bl_\bs columns
1178 starting at position (_\bb_\be_\bg_\bi_\bn__\by, _\bb_\be_\bg_\bi_\bn__\bx). If either
1179 _\bl_\bi_\bn_\be_\bs or _\bc_\bo_\bl_\bs is 0 (zero), that dimension will be set
1180 to (_\bL_\bI_\bN_\bE_\bS - _\bb_\be_\bg_\bi_\bn__\by) or (_\bC_\bO_\bL_\bS - _\bb_\be_\bg_\bi_\bn__\bx) respectively.
1181 Thus, to get a new window of dimensions _\bL_\bI_\bN_\bE_\bS x _\bC_\bO_\bL_\bS,
1182 use _\bn_\be_\bw_\bw_\bi_\bn(_\b0, _\b0, _\b0, _\b0).
1183
1184
1185
1186 _\bn_\bl() [*]
1187
1188 _\bn_\bo_\bn_\bl() [*]
1189
1190 Set or unset the terminal to/from nl mode, i.e.,
1191 start/stop the system from mapping <_\bR_\bE_\bT_\bU_\bR_\bN> to <_\bL_\bI_\bN_\bE-
1192 _\bF_\bE_\bE_\bD>. If the mapping is not done, _\br_\be_\bf_\br_\be_\bs_\bh() can do
1193 more optimization, so it is recommended, but not re-
1194 quired, to turn it off.
1195
1196
1197
1198 _\bs_\bc_\br_\bo_\bl_\bl_\bo_\bk(_\bw_\bi_\bn, _\bb_\bo_\bo_\bl_\bf) [*]
1199 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
1200 _\bb_\bo_\bo_\bl _\bb_\bo_\bo_\bl_\bf;
1201
1202 Set the scroll flag for the given window. If _\bb_\bo_\bo_\bl_\bf is
1203 FALSE, scrolling is not allowed. This is its default
1204 setting.
1205
1206
1207
1208 _\bt_\bo_\bu_\bc_\bh_\bw_\bi_\bn(_\bw_\bi_\bn)
1209 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
1210
1211 Make it appear that the every location on the window
1212 has been changed. This is usually only needed for re-
1213 freshes with overlapping windows.
1214
1215
1216 _\bW_\bI_\bN_\bD_\bO_\bW *
1217 _\bs_\bu_\bb_\bw_\bi_\bn(_\bw_\bi_\bn, _\bl_\bi_\bn_\be_\bs, _\bc_\bo_\bl_\bs, _\bb_\be_\bg_\bi_\bn__\by, _\bb_\be_\bg_\bi_\bn__\bx)
1218 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
1219
1220
1221 - 17 -
1222
1223
1224
1225
1226
1227
1228
1229.
1230 Screen Package
1231
1232
1233 _\bi_\bn_\bt _\bl_\bi_\bn_\be_\bs, _\bc_\bo_\bl_\bs, _\bb_\be_\bg_\bi_\bn__\by, _\bb_\be_\bg_\bi_\bn__\bx;
1234
1235 Create a new window with _\bl_\bi_\bn_\be_\bs lines and _\bc_\bo_\bl_\bs columns
1236 starting at position (_\bb_\be_\bg_\bi_\bn__\by, _\bb_\be_\bg_\bi_\bn__\bx) in the middle
1237 of the window _\bw_\bi_\bn. This means that any change made to
1238 either window in the area covered by the subwindow will
1239 be made on both windows. _\bb_\be_\bg_\bi_\bn__\by, _\bb_\be_\bg_\bi_\bn__\bx are speci-
1240 fied relative to the overall screen, not the relative
1241 (0, 0) of _\bw_\bi_\bn. If either _\bl_\bi_\bn_\be_\bs or _\bc_\bo_\bl_\bs is 0 (zero),
1242 that dimension will be set to (_\bL_\bI_\bN_\bE_\bS - _\bb_\be_\bg_\bi_\bn__\by) or
1243 (_\bC_\bO_\bL_\bS - _\bb_\be_\bg_\bi_\bn__\bx) respectively.
1244
1245
1246
1247 _\bu_\bn_\bc_\bt_\br_\bl(_\bc_\bh) [*]
1248 _\bc_\bh_\ba_\br _\bc_\bh;
1249
1250 This is actually a debug function for the library, but
1251 it is of general usefulness. It returns a string which
1252 is a representation of _\bc_\bh. Control characters become
1253 their upper-case equivalents preceded by a "^". Other
1254 letters stay just as they are. To use _\bu_\bn_\bc_\bt_\br_\bl(), you
1255 must have #_\bi_\bn_\bc_\bl_\bu_\bd_\be <_\bu_\bn_\bc_\bt_\br_\bl._\bh> in your file.
1256
1257 _\b5._\b4. _\bD_\be_\bt_\ba_\bi_\bl_\bs
1258
1259
1260
1261 _\bg_\be_\bt_\bt_\bm_\bo_\bd_\be()
1262
1263 Get the tty stats. This is normally called by _\bi_\bn_\b-
1264 _\bi_\bt_\bs_\bc_\br().
1265
1266
1267
1268 _\bm_\bv_\bc_\bu_\br(_\bl_\ba_\bs_\bt_\by, _\bl_\ba_\bs_\bt_\bx, _\bn_\be_\bw_\by, _\bn_\be_\bw_\bx)
1269 _\bi_\bn_\bt _\bl_\ba_\bs_\bt_\by, _\bl_\ba_\bs_\bt_\bx, _\bn_\be_\bw_\by, _\bn_\be_\bw_\bx;
1270
1271 Moves the terminal's cursor from (_\bl_\ba_\bs_\bt_\by, _\bl_\ba_\bs_\bt_\bx) to
1272 (_\bn_\be_\bw_\by, _\bn_\be_\bw_\bx) in an approximation of optimal fashion.
1273 This routine uses the functions borrowed from _\be_\bx ver-
1274 sion 2.6. It is possible to use this optimization
1275 without the benefit of the screen routines. With the
1276 screen routines, this should not be called by the user.
1277 _\bm_\bo_\bv_\be() and _\br_\be_\bf_\br_\be_\bs_\bh() should be used to move the cursor
1278 position, so that the routines know what's going on.
1279
1280
1281
1282 _\bs_\bc_\br_\bo_\bl_\bl(_\bw_\bi_\bn)
1283 _\bW_\bI_\bN_\bD_\bO_\bW *_\bw_\bi_\bn;
1284
1285
1286
1287
1288 - 18 -
1289
1290
1291
1292
1293
1294
1295
1296.
1297 Screen Package
1298
1299
1300 Scroll the window upward one line. This is normally
1301 not used by the user.
1302
1303
1304
1305 _\bs_\ba_\bv_\be_\bt_\bt_\by() [*]
1306
1307 _\br_\be_\bs_\be_\bt_\bt_\by() [*]
1308
1309 _\bs_\ba_\bv_\be_\bt_\bt_\by() saves the current tty characteristic flags.
1310 _\br_\be_\bs_\be_\bt_\bt_\by() restores them to what _\bs_\ba_\bv_\be_\bt_\bt_\by() stored.
1311 These functions are performed automatically by _\bi_\bn_\b-
1312 _\bi_\bt_\bs_\bc_\br() and _\be_\bn_\bd_\bw_\bi_\bn().
1313
1314
1315
1316 _\bs_\be_\bt_\bt_\be_\br_\bm(_\bn_\ba_\bm_\be)
1317 _\bc_\bh_\ba_\br *_\bn_\ba_\bm_\be;
1318
1319 Set the terminal characteristics to be those of the
1320 terminal named _\bn_\ba_\bm_\be. This is normally called by _\bi_\bn_\b-
1321 _\bi_\bt_\bs_\bc_\br().
1322
1323
1324
1325 _\bt_\bs_\bt_\bp()
1326
1327 If the new _\bt_\bt_\by(4) driver is in use, this function will
1328 save the current tty state and then put the process to
1329 sleep. When the process gets restarted, it restores
1330 the tty state and then calls _\bw_\br_\be_\bf_\br_\be_\bs_\bh(_\bc_\bu_\br_\bs_\bc_\br) to redraw
1331 the screen. _\bi_\bn_\bi_\bt_\bs_\bc_\br() sets the signal SIGTSTP to trap
1332 to this routine.
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355 - 19 -
1356
1357
1358
1359
1360
1361
1362
1363.
1364 _\bA_\bp_\bp_\be_\bn_\bd_\bi_\bx _\bA
1365
1366
1367 _\b1. _\bC_\ba_\bp_\ba_\bb_\bi_\bl_\bi_\bt_\bi_\be_\bs _\bf_\br_\bo_\bm _\bt_\be_\br_\bm_\bc_\ba_\bp
1368
1369 _\b1._\b1. _\bD_\bi_\bs_\bc_\bl_\ba_\bi_\bm_\be_\br
1370
1371 The description of terminals is a difficult business,
1372 and we only attempt to summarize the capabilities here: for
1373 a full description see the paper describing termcap.
1374
1375 _\b1._\b2. _\bO_\bv_\be_\br_\bv_\bi_\be_\bw
1376
1377 Capabilities from termcap are of three kinds: string
1378 valued options, numeric valued options, and boolean options.
1379 The string valued options are the most complicated, since
1380 they may include padding information, which we describe now.
1381
1382 Intelligent terminals often require padding on intelli-
1383 gent operations at high (and sometimes even low) speed.
1384 This is specified by a number before the string in the capa-
1385 bility, and has meaning for the capabilities which have a _\bP
1386 at the front of their comment. This normally is a number of
1387 milliseconds to pad the operation. In the current system
1388 which has no true programmable delays, we do this by sending
1389 a sequence of pad characters (normally nulls, but can be
1390 changed (specified by _\bP_\bC)). In some cases, the pad is
1391 better computed as some number of milliseconds times the
1392 number of affected lines (to the bottom of the screen usual-
1393 ly, except when terminals have insert modes which will shift
1394 several lines.) This is specified as, e.g., _\b1_\b2*. before the
1395 capability, to say 12 milliseconds per affected whatever
1396 (currently always line). Capabilities where this makes
1397 sense say _\bP*.
1398
1399
1400 _\b1._\b3. _\bV_\ba_\br_\bi_\ba_\bb_\bl_\be_\bs _\bS_\be_\bt _\bB_\by _\bs_\be_\bt_\bt_\be_\br_\bm()
1401
1402 variables set by _\bs_\be_\bt_\bt_\be_\br_\bm()
1403
1404 Type Name Pad Description
1405 _____________________________________________________________
1406 char * AL P* Add new blank Line
1407 bool AM Automatic Margins
1408 char * BC Back Cursor movement
1409 bool BS BackSpace works
1410 char * BT P Back Tab
1411 bool CA Cursor Addressable
1412 char * CD P* Clear to end of Display
1413 char * CE P Clear to End of line
1414 char * CL P* CLear screen
1415 char * CM P Cursor Motion
1416 char * DC P* Delete Character
1417 char * DL P* Delete Line sequence
1418 char * DM Delete Mode (enter)
1419
1420
1421
1422 - 20 -
1423
1424
1425
1426
1427
1428
1429
1430.
1431 _\bA_\bp_\bp_\be_\bn_\bd_\bi_\bx _\bA
1432
1433
1434 variables set by _\bs_\be_\bt_\bt_\be_\br_\bm()
1435
1436 Type Name Pad Description
1437 _____________________________________________________________
1438 char * DO DOwn line sequence
1439 char * ED End Delete mode
1440 bool EO can Erase Overstrikes with ' '
1441 char * EI End Insert mode
1442 char * HO HOme cursor
1443 bool HZ HaZeltine ~ braindamage
1444 char * IC P Insert Character
1445 bool IN Insert-Null blessing
1446 char * IM enter Insert Mode (IC usually set, too)
1447 char * IP P* Pad after char Inserted using IM+IE
1448 char * LL quick to Last Line, column 0
1449 char * MA ctrl character MAp for cmd mode
1450 bool MI can Move in Insert mode
1451 bool NC No Cr: \r sends \r\n then eats \n
1452 char * ND Non-Destructive space
1453 bool OS OverStrike works
1454 char PC Pad Character
1455 char * SE Standout End (may leave space)
1456 char * SF P Scroll Forwards
1457 char * SO Stand Out begin (may leave space)
1458 char * SR P Scroll in Reverse
1459 char * TA P TAb (not ^I or with padding)
1460 char * TE Terminal address enable Ending sequence
1461 char * TI Terminal address enable Initialization
1462 char * UC Underline a single Character
1463 char * UE Underline Ending sequence
1464 bool UL UnderLining works even though !OS
1465 char * UP UPline
1466 char * US Underline Starting sequence[10]
1467 char * VB Visible Bell
1468 char * VE Visual End sequence
1469 char * VS Visual Start sequence
1470 bool XN a Newline gets eaten after wrap
1471
1472 Names starting with _\bX are reserved for severely nauseous
1473 glitches
1474
1475 _\b1._\b4. _\bV_\ba_\br_\bi_\ba_\bb_\bl_\be_\bs _\bS_\be_\bt _\bB_\by _\bg_\be_\bt_\bt_\bm_\bo_\bd_\be()
1476
1477 variables set by _\bg_\be_\bt_\bt_\bm_\bo_\bd_\be()
1478
1479 type name description
1480 ____________________________________________________________
1481 ____________________
1482 [10] US and UE, if they do not exist in the termcap en-
1483 try, are copied from SO and SE in _\bs_\be_\bt_\bt_\be_\br_\bm()
1484
1485
1486
1487
1488
1489 - 21 -
1490
1491
1492
1493
1494
1495
1496
1497.
1498 _\bA_\bp_\bp_\be_\bn_\bd_\bi_\bx _\bA
1499
1500
1501 variables set by _\bg_\be_\bt_\bt_\bm_\bo_\bd_\be()
1502
1503 type name description
1504 ____________________________________________________________
1505 bool NONL Term can't hack linefeeds doing a CR
1506 bool GT Gtty indicates Tabs
1507 bool UPPERCASE Terminal generates only uppercase letters
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556 - 22 -
1557
1558
1559
1560
1561
1562
1563
1564.
1565 _\bA_\bp_\bp_\be_\bn_\bd_\bi_\bx _\bB
1566
1567
1568 _\b1.
1569 _\bT_\bh_\be _\bW_\bI_\bN_\bD_\bO_\bW _\bs_\bt_\br_\bu_\bc_\bt_\bu_\br_\be
1570
1571 The WINDOW structure is defined as follows:
1572
1573 # _\bd_\be_\bf_\bi_\bn_\be WINDOW _\bs_\bt_\br_\bu_\bc_\bt _win_st
1574
1575 _\bs_\bt_\br_\bu_\bc_\bt _win_st {
1576 _\bs_\bh_\bo_\br_\bt _cury, _curx;
1577 _\bs_\bh_\bo_\br_\bt _maxy, _maxx;
1578 _\bs_\bh_\bo_\br_\bt _begy, _begx;
1579 _\bs_\bh_\bo_\br_\bt _flags;
1580 bool _clear;
1581 bool _leave;
1582 bool _scroll;
1583 _\bc_\bh_\ba_\br **_y;
1584 _\bs_\bh_\bo_\br_\bt *_firstch;
1585 _\bs_\bh_\bo_\br_\bt *_lastch;
1586 };
1587
1588 # _\bd_\be_\bf_\bi_\bn_\be _SUBWIN 01
1589 # _\bd_\be_\bf_\bi_\bn_\be _ENDLINE 02
1590 # _\bd_\be_\bf_\bi_\bn_\be _FULLWIN 04
1591 # _\bd_\be_\bf_\bi_\bn_\be _SCROLLWIN 010
1592 # _\bd_\be_\bf_\bi_\bn_\be _STANDOUT 0200
1593
1594
1595 __\bc_\bu_\br_\by and __\bc_\bu_\br_\bx are the current (y, x) co-ordinates for
1596 the window. New characters added to the screen are added at
1597 this point. __\bm_\ba_\bx_\by and __\bm_\ba_\bx_\bx are the maximum values allowed
1598 for (__\bc_\bu_\br_\by, __\bc_\bu_\br_\bx). __\bb_\be_\bg_\by and __\bb_\be_\bg_\bx are the starting (y, x)
1599 co-ordinates on the terminal for the window, i.e., the
1600 window's home. __\bc_\bu_\br_\by, __\bc_\bu_\br_\bx, __\bm_\ba_\bx_\by, and __\bm_\ba_\bx_\bx are measured
1601 relative to (__\bb_\be_\bg_\by, __\bb_\be_\bg_\bx), not the terminal's home.
1602
1603 __\bc_\bl_\be_\ba_\br tells if a clear-screen sequence is to be gen-
1604 erated on the next _\br_\be_\bf_\br_\be_\bs_\bh() call. This is only meaningful
1605 for screens. The initial clear-screen for the first _\br_\be_\b-
1606 _\bf_\br_\be_\bs_\bh() call is generated by initially setting clear to be
1607 TRUE for _\bc_\bu_\br_\bs_\bc_\br, which always generates a clear-screen if
1608 set, irrelevant of the dimensions of the window involved.
1609 __\bl_\be_\ba_\bv_\be is TRUE if the current (y, x) co-ordinates and the
1610 cursor are to be left after the last character changed on
1611 the terminal, or not moved if there is no change. __\bs_\bc_\br_\bo_\bl_\bl
1612 is TRUE if scrolling is allowed.
1613
1614 __\by is a pointer to an array of lines which describe the
1615 terminal. Thus:
1616
1617 _y[i]
1618
1619
1620
1621 is a pointer to the _\bith line, and
1622
1623 _y[i][j]
1624
1625
1626
1627 is the _\bjth character on the _\bith line.
1628
1629 __\bf_\bl_\ba_\bg_\bs can have one or more values or'd into it.
1630 __\bS_\bU_\bB_\bW_\bI_\bN means that the window is a subwindow, which indi-
1631 cates to _\bd_\be_\bl_\bw_\bi_\bn() that the space for the lines is not to be
1632 freed. __\bE_\bN_\bD_\bL_\bI_\bN_\bE says that the end of the line for this win-
1633 dow is also the end of a screen. __\bF_\bU_\bL_\bL_\bW_\bI_\bN says that this
1634 window is a screen. __\bS_\bC_\bR_\bO_\bL_\bL_\bW_\bI_\bN indicates that the last
1635 character of this screen is at the lower right-hand corner
1636 of the terminal; _\bi._\be., if a character was put there, the
1637 terminal would scroll. __\bS_\bT_\bA_\bN_\bD_\bO_\bU_\bT says that all characters
1638 added to the screen are in standout mode.
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694 _\b1. _\bE_\bx_\ba_\bm_\bp_\bl_\be_\bs
1695
1696 Here we present a few examples of how to use the pack-
1697 age. They attempt to be representative, though not
1698 comprehensive.
1699
1700 _\b2. _\bS_\bc_\br_\be_\be_\bn _\bU_\bp_\bd_\ba_\bt_\bi_\bn_\bg
1701
1702 The following examples are intended to demonstrate the
1703 basic structure of a program using the screen updating sec-
1704 tions of the package. Several of the programs require cal-
1705 culational sections which are irrelevant of to the example,
1706 and are therefore usually not included. It is hoped that
1707 the data structure definitions give enough of an idea to al-
1708 low understanding of what the relevant portions do. The
1709 rest is left as an exercise to the reader, and will not be
1710 on the final.
1711
1712 _\b2._\b1. _\bT_\bw_\bi_\bn_\bk_\bl_\be
1713
1714 This is a moderately simple program which prints pretty
1715 patterns on the screen that might even hold your interest
1716 for 30 seconds or more. It switches between patterns of as-
1717 terisks, putting them on one by one in random order, and
1718 then taking them off in the same fashion. It is more effi-
1719 cient to write this using only the motion optimization, as
1720 is demonstrated below.
1721
1722 # _\bi_\bn_\bc_\bl_\bu_\bd_\be <curses.h>
1723 # _\bi_\bn_\bc_\bl_\bu_\bd_\be <signal.h>
1724
1725 /*
1726 * _\bt_\bh_\be _\bi_\bd_\be_\ba _\bf_\bo_\br _\bt_\bh_\bi_\bs _\bp_\br_\bo_\bg_\br_\ba_\bm _\bw_\ba_\bs _\ba _\bp_\br_\bo_\bd_\bu_\bc_\bt _\bo_\bf _\bt_\bh_\be _\bi_\bm_\ba_\bg_\bi_\bn_\ba_\bt_\bi_\bo_\bn _\bo_\bf
1727 * _\bK_\bu_\br_\bt _\bS_\bc_\bh_\bo_\be_\bn_\bs. _\bN_\bo_\bt _\br_\be_\bs_\bp_\bo_\bn_\bs_\bi_\bb_\bl_\be _\bf_\bo_\br _\bm_\bi_\bn_\bd_\bs _\bl_\bo_\bs_\bt _\bo_\br _\bs_\bt_\bo_\bl_\be_\bn.
1728 */
1729
1730 # _\bd_\be_\bf_\bi_\bn_\be NCOLS 80
1731 # _\bd_\be_\bf_\bi_\bn_\be NLINES 24
1732 # _\bd_\be_\bf_\bi_\bn_\be MAXPATTERNS 4
1733
1734 _\bs_\bt_\br_\bu_\bc_\bt locs {
1735 _\bc_\bh_\ba_\br y, x;
1736 };
1737
1738 _\bt_\by_\bp_\be_\bd_\be_\bf _\bs_\bt_\br_\bu_\bc_\bt locs LOCS;
1739
1740 LOCS Layout[NCOLS * NLINES]; /* _\bc_\bu_\br_\br_\be_\bn_\bt _\bb_\bo_\ba_\br_\bd _\bl_\ba_\by_\bo_\bu_\bt */
1741
1742 _\bi_\bn_\bt Pattern, /* _\bc_\bu_\br_\br_\be_\bn_\bt _\bp_\ba_\bt_\bt_\be_\br_\bn _\bn_\bu_\bm_\bb_\be_\br */
1743 Numstars; /* _\bn_\bu_\bm_\bb_\be_\br _\bo_\bf _\bs_\bt_\ba_\br_\bs _\bi_\bn _\bp_\ba_\bt_\bt_\be_\br_\bn */
1744
1745 mainmain() {
1746
1747 _\bc_\bh_\ba_\br *getenv();
1748 _\bi_\bn_\bt die();
1749
1750 srand(getpid()); /* _\bi_\bn_\bi_\bt_\bi_\ba_\bl_\bi_\bz_\be _\br_\ba_\bn_\bd_\bo_\bm _\bs_\be_\bq_\bu_\be_\bn_\bc_\be */
1751
1752 initscr();
1753 signal(SIGINT, die);
1754 noecho();
1755 nonl();
1756 leaveok(stdscr, TRUE);
1757 scrollok(stdscr, FALSE);
1758
1759 _\bf_\bo_\br (;;) {
1760 makeboard(); /* _\bm_\ba_\bk_\be _\bt_\bh_\be _\bb_\bo_\ba_\br_\bd _\bs_\be_\bt_\bu_\bp */
1761 puton('*'); /* _\bp_\bu_\bt _\bo_\bn '*'_\bs */
1762 puton(' '); /* _\bc_\bo_\bv_\be_\br _\bu_\bp _\bw_\bi_\bt_\bh ' '_\bs */
1763 }
1764 }
1765
1766 /*
1767 * _\bO_\bn _\bp_\br_\bo_\bg_\br_\ba_\bm _\be_\bx_\bi_\bt, _\bm_\bo_\bv_\be _\bt_\bh_\be _\bc_\bu_\br_\bs_\bo_\br _\bt_\bo _\bt_\bh_\be _\bl_\bo_\bw_\be_\br _\bl_\be_\bf_\bt _\bc_\bo_\br_\bn_\be_\br _\bb_\by
1768 * _\bd_\bi_\br_\be_\bc_\bt _\ba_\bd_\bd_\br_\be_\bs_\bs_\bi_\bn_\bg, _\bs_\bi_\bn_\bc_\be _\bc_\bu_\br_\br_\be_\bn_\bt _\bl_\bo_\bc_\ba_\bt_\bi_\bo_\bn _\bi_\bs _\bn_\bo_\bt _\bg_\bu_\ba_\br_\ba_\bn_\bt_\be_\be_\bd.
1769 * _\bW_\be _\bl_\bi_\be _\ba_\bn_\bd _\bs_\ba_\by _\bw_\be _\bu_\bs_\be_\bd _\bt_\bo _\bb_\be _\ba_\bt _\bt_\bh_\be _\bu_\bp_\bp_\be_\br _\br_\bi_\bg_\bh_\bt _\bc_\bo_\br_\bn_\be_\br _\bt_\bo _\bg_\bu_\ba_\br_\ba_\bn_\bt_\be_\be
1770 * _\ba_\bb_\bs_\bo_\bl_\bu_\bt_\be _\ba_\bd_\bd_\br_\be_\bs_\bs_\bi_\bn_\bg.
1771 */
1772 diedie() {
1773
1774 signal(SIGINT, SIG_IGN);
1775 mvcur(0, COLS-1, LINES-1, 0);
1776 endwin();
1777 exit(0);
1778 }
1779
1780
1781 /*
1782 * _\bM_\ba_\bk_\be _\bt_\bh_\be _\bc_\bu_\br_\br_\be_\bn_\bt _\bb_\bo_\ba_\br_\bd _\bs_\be_\bt_\bu_\bp. _\bI_\bt _\bp_\bi_\bc_\bk_\bs _\ba _\br_\ba_\bn_\bd_\bo_\bm _\bp_\ba_\bt_\bt_\be_\br_\bn _\ba_\bn_\bd
1783 * _\bc_\ba_\bl_\bl_\bs _\bi_\bs_\bo_\bn() _\bt_\bo _\bd_\be_\bt_\be_\br_\bm_\bi_\bn_\be _\bi_\bf _\bt_\bh_\be _\bc_\bh_\ba_\br_\ba_\bc_\bt_\be_\br _\bi_\bs _\bo_\bn _\bt_\bh_\ba_\bt _\bp_\ba_\bt_\bt_\be_\br_\bn
1784 * _\bo_\br _\bn_\bo_\bt.
1785 */
1786 makeboardmakeboard() {
1787
1788 reg _\bi_\bn_\bt y, x;
1789 reg LOCS *lp;
1790
1791 Pattern = rand() % MAXPATTERNS;
1792 lp = Layout;
1793 _\bf_\bo_\br (y = 0; y < NLINES; y++)
1794 _\bf_\bo_\br (x = 0; x < NCOLS; x++)
1795 _\bi_\bf (ison(y, x)) {
1796 lp->y = y;
1797 lp++->x = x;
1798 }
1799 Numstars = lp - Layout;
1800 }
1801
1802 /*
1803 * _\bR_\be_\bt_\bu_\br_\bn _\bT_\bR_\bU_\bE _\bi_\bf (_\by, _\bx) _\bi_\bs _\bo_\bn _\bt_\bh_\be _\bc_\bu_\br_\br_\be_\bn_\bt _\bp_\ba_\bt_\bt_\be_\br_\bn.
1804 */
1805 isonison(y, x)
1806 reg _\bi_\bn_\bt y, x; {
1807
1808 _\bs_\bw_\bi_\bt_\bc_\bh (Pattern) {
1809 _\bc_\ba_\bs_\be 0: /* _\ba_\bl_\bt_\be_\br_\bn_\ba_\bt_\bi_\bn_\bg _\bl_\bi_\bn_\be_\bs */
1810 _\br_\be_\bt_\bu_\br_\bn !(y & 01);
1811 _\bc_\ba_\bs_\be 1: /* _\bb_\bo_\bx */
1812 _\bi_\bf (x >= LINES && y >= NCOLS)
1813 _\br_\be_\bt_\bu_\br_\bn FALSE;
1814 _\bi_\bf (y < 3 || y >= NLINES - 3)
1815 _\br_\be_\bt_\bu_\br_\bn TRUE;
1816 _\br_\be_\bt_\bu_\br_\bn (x < 3 || x >= NCOLS - 3);
1817
1818
1819 _\bc_\ba_\bs_\be 2: /* _\bh_\bo_\bl_\by _\bp_\ba_\bt_\bt_\be_\br_\bn! */
1820 _\br_\be_\bt_\bu_\br_\bn ((x + y) & 01);
1821 _\bc_\ba_\bs_\be 3: /* _\bb_\ba_\br _\ba_\bc_\br_\bo_\bs_\bs _\bc_\be_\bn_\bt_\be_\br */
1822 _\br_\be_\bt_\bu_\br_\bn (y >= 9 && y <= 15);
1823 }
1824
1825 /* _\bN_\bO_\bT_\bR_\bE_\bA_\bC_\bH_\bE_\bD */
1826 }
1827
1828 putonputon(ch)
1829 reg _\bc_\bh_\ba_\br ch; {
1830
1831 reg LOCS *lp;
1832 reg _\bi_\bn_\bt r;
1833 reg LOCS *end;
1834 LOCS temp;
1835
1836 end = &Layout[Numstars];
1837 _\bf_\bo_\br (lp = Layout; lp < end; lp++) {
1838 r = rand() % Numstars;
1839 temp = *lp;
1840 *lp = Layout[r];
1841 Layout[r] = temp;
1842 }
1843
1844 _\bf_\bo_\br (lp = Layout; lp < end; lp++) {
1845 mvaddch(lp->y, lp->x, ch);
1846 refresh();
1847 }
1848 }
1849
1850
1851 _\b2._\b2. _\bL_\bi_\bf_\be
1852
1853 This program plays the famous computer pattern game of
1854 life (Scientific American, May, 1974). The calculational
1855 routines create a linked list of structures defining where
1856 each piece is. Nothing here claims to be optimal, merely
1857 demonstrative. This program, however, is a very good place
1858 to use the screen updating routines, as it allows them to
1859 worry about what the last position looked like, so you don't
1860 have to. It also demonstrates some of the input routines.
1861
1862 # _\bi_\bn_\bc_\bl_\bu_\bd_\be <curses.h>
1863 # _\bi_\bn_\bc_\bl_\bu_\bd_\be <signal.h>
1864
1865 /*
1866 * _\bR_\bu_\bn _\ba _\bl_\bi_\bf_\be _\bg_\ba_\bm_\be. _\bT_\bh_\bi_\bs _\bi_\bs _\ba _\bd_\be_\bm_\bo_\bn_\bs_\bt_\br_\ba_\bt_\bi_\bo_\bn _\bp_\br_\bo_\bg_\br_\ba_\bm _\bf_\bo_\br
1867 * _\bt_\bh_\be _\bS_\bc_\br_\be_\be_\bn _\bU_\bp_\bd_\ba_\bt_\bi_\bn_\bg _\bs_\be_\bc_\bt_\bi_\bo_\bn _\bo_\bf _\bt_\bh_\be -_\bl_\bc_\bu_\br_\bs_\be_\bs _\bc_\bu_\br_\bs_\bo_\br _\bp_\ba_\bc_\bk_\ba_\bg_\be.
1868 */
1869
1870 _\bs_\bt_\br_\bu_\bc_\bt lst_st { /* _\bl_\bi_\bn_\bk_\be_\bd _\bl_\bi_\bs_\bt _\be_\bl_\be_\bm_\be_\bn_\bt */
1871 _\bi_\bn_\bt y, x; /* (_\by, _\bx) _\bp_\bo_\bs_\bi_\bt_\bi_\bo_\bn _\bo_\bf _\bp_\bi_\be_\bc_\be */
1872 _\bs_\bt_\br_\bu_\bc_\bt lst_st *next, *last; /* _\bd_\bo_\bu_\bb_\bl_\by _\bl_\bi_\bn_\bk_\be_\bd */
1873 };
1874
1875 _\bt_\by_\bp_\be_\bd_\be_\bf _\bs_\bt_\br_\bu_\bc_\bt lst_st LIST;
1876
1877 LIST *Head; /* _\bh_\be_\ba_\bd _\bo_\bf _\bl_\bi_\bn_\bk_\be_\bd _\bl_\bi_\bs_\bt */
1878
1879 mainmain(ac, av)
1880 _\bi_\bn_\bt ac;
1881 _\bc_\bh_\ba_\br *av[]; {
1882
1883 _\bi_\bn_\bt die();
1884
1885 evalargs(ac, av); /* _\be_\bv_\ba_\bl_\bu_\ba_\bt_\be _\ba_\br_\bg_\bu_\bm_\be_\bn_\bt_\bs */
1886
1887 initscr(); /* _\bi_\bn_\bi_\bt_\bi_\ba_\bl_\bi_\bz_\be _\bs_\bc_\br_\be_\be_\bn _\bp_\ba_\bc_\bk_\ba_\bg_\be */
1888 signal(SIGINT, die); /* _\bs_\be_\bt _\bt_\bo _\br_\be_\bs_\bt_\bo_\br_\be _\bt_\bt_\by _\bs_\bt_\ba_\bt_\bs */
1889
1890
1891 crmode(); /* _\bs_\be_\bt _\bf_\bo_\br _\bc_\bh_\ba_\br-_\bb_\by-_\bc_\bh_\ba_\br */
1892 noecho(); /* _\bi_\bn_\bp_\bu_\bt */
1893 nonl(); /* _\bf_\bo_\br _\bo_\bp_\bt_\bi_\bm_\bi_\bz_\ba_\bt_\bi_\bo_\bn */
1894
1895 getstart(); /* _\bg_\be_\bt _\bs_\bt_\ba_\br_\bt_\bi_\bn_\bg _\bp_\bo_\bs_\bi_\bt_\bi_\bo_\bn */
1896 _\bf_\bo_\br (;;) {
1897 prboard(); /* _\bp_\br_\bi_\bn_\bt _\bo_\bu_\bt _\bc_\bu_\br_\br_\be_\bn_\bt _\bb_\bo_\ba_\br_\bd */
1898 update(); /* _\bu_\bp_\bd_\ba_\bt_\be _\bb_\bo_\ba_\br_\bd _\bp_\bo_\bs_\bi_\bt_\bi_\bo_\bn */
1899 }
1900 }
1901
1902 /*
1903 * _\bT_\bh_\bi_\bs _\bi_\bs _\bt_\bh_\be _\br_\bo_\bu_\bt_\bi_\bn_\be _\bw_\bh_\bi_\bc_\bh _\bi_\bs _\bc_\ba_\bl_\bl_\be_\bd _\bw_\bh_\be_\bn _\br_\bu_\bb_\bo_\bu_\bt _\bi_\bs _\bh_\bi_\bt.
1904 * _\bI_\bt _\br_\be_\bs_\be_\bt_\bs _\bt_\bh_\be _\bt_\bt_\by _\bs_\bt_\ba_\bt_\bs _\bt_\bo _\bt_\bh_\be_\bi_\br _\bo_\br_\bi_\bg_\bi_\bn_\ba_\bl _\bv_\ba_\bl_\bu_\be_\bs. _\bT_\bh_\bi_\bs
1905 * _\bi_\bs _\bt_\bh_\be _\bn_\bo_\br_\bm_\ba_\bl _\bw_\ba_\by _\bo_\bf _\bl_\be_\ba_\bv_\bi_\bn_\bg _\bt_\bh_\be _\bp_\br_\bo_\bg_\br_\ba_\bm.
1906 */
1907 diedie() {
1908
1909 signal(SIGINT, SIG_IGN); /* _\bi_\bg_\bn_\bo_\br_\be _\br_\bu_\bb_\bo_\bu_\bt_\bs */
1910 mvcur(0, COLS-1, LINES-1, 0); /* _\bg_\bo _\bt_\bo _\bb_\bo_\bt_\bt_\bo_\bm _\bo_\bf _\bs_\bc_\br_\be_\be_\bn */
1911 endwin(); /* _\bs_\be_\bt _\bt_\be_\br_\bm_\bi_\bn_\ba_\bl _\bt_\bo _\bi_\bn_\bi_\bt_\bi_\ba_\bl _\bs_\bt_\ba_\bt_\be */
1912 exit(0);
1913 }
1914
1915 /*
1916 * _\bG_\be_\bt _\bt_\bh_\be _\bs_\bt_\ba_\br_\bt_\bi_\bn_\bg _\bp_\bo_\bs_\bi_\bt_\bi_\bo_\bn _\bf_\br_\bo_\bm _\bt_\bh_\be _\bu_\bs_\be_\br. _\bT_\bh_\be_\by _\bk_\be_\by_\bs _\bu, _\bi, _\bo, _\bj, _\bl,
1917 * _\bm, ,, _\ba_\bn_\bd . _\ba_\br_\be _\bu_\bs_\be_\bd _\bf_\bo_\br _\bm_\bo_\bv_\bi_\bn_\bg _\bt_\bh_\be_\bi_\br _\br_\be_\bl_\ba_\bt_\bi_\bv_\be _\bd_\bi_\br_\be_\bc_\bt_\bi_\bo_\bn_\bs _\bf_\br_\bo_\bm _\bt_\bh_\be
1918 * _\bk _\bk_\be_\by. _\bT_\bh_\bu_\bs, _\bu _\bm_\bo_\bv_\be _\bd_\bi_\ba_\bg_\bo_\bn_\ba_\bl_\bl_\by _\bu_\bp _\bt_\bo _\bt_\bh_\be _\bl_\be_\bf_\bt, , _\bm_\bo_\bv_\be_\bs _\bd_\bi_\br_\be_\bc_\bt_\bl_\by _\bd_\bo_\bw_\bn,
1919 * _\be_\bt_\bc. _\bx _\bp_\bl_\ba_\bc_\be_\bs _\ba _\bp_\bi_\be_\bc_\be _\ba_\bt _\bt_\bh_\be _\bc_\bu_\br_\br_\be_\bn_\bt _\bp_\bo_\bs_\bi_\bt_\bi_\bo_\bn, " " _\bt_\ba_\bk_\be_\bs _\bi_\bt _\ba_\bw_\ba_\by.
1920 * _\bT_\bh_\be _\bi_\bn_\bp_\bu_\bt _\bc_\ba_\bn _\ba_\bl_\bs_\bo _\bb_\be _\bf_\br_\bo_\bm _\ba _\bf_\bi_\bl_\be. _\bT_\bh_\be _\bl_\bi_\bs_\bt _\bi_\bs _\bb_\bu_\bi_\bl_\bt _\ba_\bf_\bt_\be_\br _\bt_\bh_\be
1921 * _\bb_\bo_\ba_\br_\bd _\bs_\be_\bt_\bu_\bp _\bi_\bs _\br_\be_\ba_\bd_\by.
1922 */
1923 getstartgetstart() {
1924
1925 reg _\bc_\bh_\ba_\br c;
1926 reg _\bi_\bn_\bt x, y;
1927
1928 box(stdscr, '|', '_'); /* _\bb_\bo_\bx _\bi_\bn _\bt_\bh_\be _\bs_\bc_\br_\be_\be_\bn */
1929 move(1, 1); /* _\bm_\bo_\bv_\be _\bt_\bo _\bu_\bp_\bp_\be_\br _\bl_\be_\bf_\bt _\bc_\bo_\br_\bn_\be_\br */
1930
1931 _\bd_\bo {
1932 refresh(); /* _\bp_\br_\bi_\bn_\bt _\bc_\bu_\br_\br_\be_\bn_\bt _\bp_\bo_\bs_\bi_\bt_\bi_\bo_\bn */
1933 _\bi_\bf ((c=getch()) == 'q')
1934 _\bb_\br_\be_\ba_\bk;
1935 _\bs_\bw_\bi_\bt_\bc_\bh (c) {
1936 _\bc_\ba_\bs_\be 'u':
1937 _\bc_\ba_\bs_\be 'i':
1938 _\bc_\ba_\bs_\be 'o':
1939 _\bc_\ba_\bs_\be 'j':
1940 _\bc_\ba_\bs_\be 'l':
1941 _\bc_\ba_\bs_\be 'm':
1942 _\bc_\ba_\bs_\be ',':
1943 _\bc_\ba_\bs_\be '.':
1944 adjustyx(c);
1945 _\bb_\br_\be_\ba_\bk;
1946 _\bc_\ba_\bs_\be 'f':
1947 mvaddstr(0, 0, "File name: ");
1948 getstr(buf);
1949 readfile(buf);
1950 _\bb_\br_\be_\ba_\bk;
1951 _\bc_\ba_\bs_\be 'x':
1952 addch('X');
1953 _\bb_\br_\be_\ba_\bk;
1954 _\bc_\ba_\bs_\be ' ':
1955 addch(' ');
1956 _\bb_\br_\be_\ba_\bk;
1957 }
1958 }
1959
1960 _\bi_\bf (Head != NULL) /* _\bs_\bt_\ba_\br_\bt _\bn_\be_\bw _\bl_\bi_\bs_\bt */
1961 dellist(Head);
1962 Head = malloc(_\bs_\bi_\bz_\be_\bo_\bf (LIST));
1963
1964 /*
1965 * _\bl_\bo_\bo_\bp _\bt_\bh_\br_\bo_\bu_\bg_\bh _\bt_\bh_\be _\bs_\bc_\br_\be_\be_\bn _\bl_\bo_\bo_\bk_\bi_\bn_\bg _\bf_\bo_\br '_\bx'_\bs, _\ba_\bn_\bd _\ba_\bd_\bd _\ba _\bl_\bi_\bs_\bt
1966 * _\be_\bl_\be_\bm_\be_\bn_\bt _\bf_\bo_\br _\be_\ba_\bc_\bh _\bo_\bn_\be
1967 */
1968 _\bf_\bo_\br (y = 1; y < LINES - 1; y++)
1969 _\bf_\bo_\br (x = 1; x < COLS - 1; x++) {
1970 move(y, x);
1971 _\bi_\bf (inch() == 'x')
1972 addlist(y, x);
1973 }
1974 }
1975
1976 /*
1977 * _\bP_\br_\bi_\bn_\bt _\bo_\bu_\bt _\bt_\bh_\be _\bc_\bu_\br_\br_\be_\bn_\bt _\bb_\bo_\ba_\br_\bd _\bp_\bo_\bs_\bi_\bt_\bi_\bo_\bn _\bf_\br_\bo_\bm _\bt_\bh_\be _\bl_\bi_\bn_\bk_\be_\bd _\bl_\bi_\bs_\bt
1978 */
1979 prboardprboard() {
1980
1981 reg LIST *hp;
1982
1983 erase(); /* _\bc_\bl_\be_\ba_\br _\bo_\bu_\bt _\bl_\ba_\bs_\bt _\bp_\bo_\bs_\bi_\bt_\bi_\bo_\bn */
1984 box(stdscr, '|', '_'); /* _\bb_\bo_\bx _\bi_\bn _\bt_\bh_\be _\bs_\bc_\br_\be_\be_\bn */
1985
1986 /*
1987 * _\bg_\bo _\bt_\bh_\br_\bo_\bu_\bg_\bh _\bt_\bh_\be _\bl_\bi_\bs_\bt _\ba_\bd_\bd_\bi_\bn_\bg _\be_\ba_\bc_\bh _\bp_\bi_\be_\bc_\be _\bt_\bo _\bt_\bh_\be _\bn_\be_\bw_\bl_\by
1988 * _\bb_\bl_\ba_\bn_\bk _\bb_\bo_\ba_\br_\bd
1989 */
1990 _\bf_\bo_\br (hp = Head; hp; hp = hp->next)
1991 mvaddch(hp->y, hp->x, 'X');
1992
1993 refresh();
1994 }
1995
1996
1997 _\b3. _\bM_\bo_\bt_\bi_\bo_\bn _\bo_\bp_\bt_\bi_\bm_\bi_\bz_\ba_\bt_\bi_\bo_\bn
1998
1999 The following example shows how motion optimization is
2000 written on its own. Programs which flit from one place to
2001 another without regard for what is already there usually do
2002 not need the overhead of both space and time associated with
2003 screen updating. They should instead use motion optimiza-
2004 tion.
2005
2006 _\b3._\b1. _\bT_\bw_\bi_\bn_\bk_\bl_\be
2007
2008 The _\bt_\bw_\bi_\bn_\bk_\bl_\be program is a good candidate for simple mo-
2009 tion optimization. Here is how it could be written (only
2010 the routines that have been changed are shown):
2011
2012 mainmain() {
2013
2014 reg _\bc_\bh_\ba_\br *sp;
2015 _\bc_\bh_\ba_\br *getenv();
2016 _\bi_\bn_\bt _putchar(), die();
2017
2018 srand(getpid()); /* _\bi_\bn_\bi_\bt_\bi_\ba_\bl_\bi_\bz_\be _\br_\ba_\bn_\bd_\bo_\bm _\bs_\be_\bq_\bu_\be_\bn_\bc_\be */
2019
2020 _\bi_\bf (isatty(0)) {
2021 gettmode();
2022 _\bi_\bf (sp=getenv("TERM"))
2023 setterm(sp);
2024 signal(SIGINT, die);
2025 }
2026 _\be_\bl_\bs_\be {
2027 printf("Need a terminal on %d\n", _tty_ch);
2028 exit(1);
2029 }
2030 _puts(TI);
2031 _puts(VS);
2032
2033 noecho();
2034 nonl();
2035 tputs(CL, NLINES, _putchar);
2036 _\bf_\bo_\br (;;) {
2037 makeboard(); /* _\bm_\ba_\bk_\be _\bt_\bh_\be _\bb_\bo_\ba_\br_\bd _\bs_\be_\bt_\bu_\bp */
2038 puton('*'); /* _\bp_\bu_\bt _\bo_\bn '*'_\bs */
2039 puton(' '); /* _\bc_\bo_\bv_\be_\br _\bu_\bp _\bw_\bi_\bt_\bh ' '_\bs */
2040 }
2041 }
2042
2043 /*
2044 * __\bp_\bu_\bt_\bc_\bh_\ba_\br _\bd_\be_\bf_\bi_\bn_\be_\bd _\bf_\bo_\br _\bt_\bp_\bu_\bt_\bs() (_\ba_\bn_\bd __\bp_\bu_\bt_\bs())
2045 */
2046 _putchar_putchar(c)
2047 reg _\bc_\bh_\ba_\br c; {
2048
2049 putchar(c);
2050 }
2051
2052 putonputon(ch)
2053 _\bc_\bh_\ba_\br ch; {
2054
2055 _\bs_\bt_\ba_\bt_\bi_\bc _\bi_\bn_\bt lasty, lastx;
2056 reg LOCS *lp;
2057 reg _\bi_\bn_\bt r;
2058 reg LOCS *end;
2059 LOCS temp;
2060
2061 end = &Layout[Numstars];
2062 _\bf_\bo_\br (lp = Layout; lp < end; lp++) {
2063 r = rand() % Numstars;
2064 temp = *lp;
2065 *lp = Layout[r];
2066 Layout[r] = temp;
2067 }
2068
2069 _\bf_\bo_\br (lp = Layout; lp < end; lp++)
2070 /* _\bp_\br_\be_\bv_\be_\bn_\bt _\bs_\bc_\br_\bo_\bl_\bl_\bi_\bn_\bg */
2071 _\bi_\bf (!AM || (lp->y < NLINES - 1 || lp->x < NCOLS - 1)) {
2072 mvcur(lasty, lastx, lp->y, lp->x);
2073 putchar(ch);
2074 lasty = lp->y;
2075 _\bi_\bf ((lastx = lp->x + 1) >= NCOLS)
2076 _\bi_\bf (AM) {
2077 lastx = 0;
2078 lasty++;
2079 }
2080 _\be_\bl_\bs_\be
2081 lastx = NCOLS - 1;
2082 }
2083 }
2084
2085
2086
2087
2088
2089 _\bC_\bo_\bn_\bt_\be_\bn_\bt_\bs
2090
2091 1 Overview ............................................ 1
2092 1.1 Terminology (or, Words You Can Say to Sound
2093 Brilliant) ......................................... 1
2094 1.2 Compiling Things ............................... 1
2095 1.3 Screen Updating ................................ 2
2096 1.4 Naming Conventions ............................. 2
2097 2 Variables ........................................... 3
2098 3 Usage ............................................... 4
2099 3.1 Starting up .................................... 4
2100 3.2 The Nitty-Gritty ............................... 5
2101 3.2.1 Output .................................... 5
2102 3.2.2 Input ..................................... 5
2103 3.2.3 Miscellaneous ............................. 6
2104 3.3 Finishing up ................................... 6
2105 4 Cursor Motion Optimization: Standing Alone .......... 6
2106 4.1 Terminal Information ........................... 7
2107 4.2 Movement Optimizations, or, Getting Over
2108 Yonder ............................................. 8
2109 5 The Functions ....................................... 8
2110 5.1 Output Functions ............................... 9
2111 5.2 Input Functions ................................ 13
2112 5.3 Miscellaneous Functions ........................ 15
2113 5.4 Details ........................................ 18
2114
2115
2116 _\bA_\bp_\bp_\be_\bn_\bd_\bi_\bx_\be_\bs
2117
2118 _\bA_\bp_\bp_\be_\bn_\bd_\bi_\bx _\bA ............................................ 20
2119 1 Capabilities from termcap ........................... 20
2120 1.1 Disclaimer ..................................... 20
2121 1.2 Overview ....................................... 20
2122 1.3 Variables Set By setterm() ..................... 20
2123 1.4 Variables Set By gettmode() .................... 21
2124 _\bA_\bp_\bp_\be_\bn_\bd_\bi_\bx _\bB ............................................ 23
2125 1 The WINDOW structure ................................ 23
2126 _\bA_\bp_\bp_\be_\bn_\bd_\bi_\bx _\bC ............................................ 25
2127 1 Examples ............................................ 25
2128 2 Screen Updating ..................................... 25
2129 2.1 Twinkle ........................................ 25
2130 2.2 Life ........................................... 27
2131 3 Motion optimization ................................. 29
2132 3.1 Twinkle ........................................ 29
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154