from scratch; add Berkeley specific header
[unix-history] / usr / src / lib / libcurses / PSD.doc / intro.3
CommitLineData
9c6a28be
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.\"
1268a632 5.\" @(#)intro.3 6.1 (Berkeley) %G%
9c6a28be
KM
6.\"
7.sh 1 Usage
8.pp
9This is a description of how to actually use the screen package.
10In it, we assume all updating, reading, etc.
11is applied to
12.Vn stdscr .
13All instructions will work on any window,
14with changing the function name and parameters as mentioned above.
15.sh 2 "Starting up"
16.pp
17In order to use the screen package,
18the routines must know about terminal characteristics,
19and the space for
20.Vn curscr
21and
22.Vn stdscr
23must be allocated.
24These functions are performed by
25.Fn initscr .
26Since it must allocate space for the windows,
27it can overflow core when attempting to do so.
28On this rather rare occasion,
29.Fn initscr
30returns ERR.
31.Fn initscr
32must
33.bi always
34be called before any of the routines which affect windows are used.
35If it is not,
36the program will core dump as soon as either
37.Vn curscr
38or
39.Vn stdscr
40are referenced.
41However, it is usually best to wait to call it
42until after you are sure you will need it,
43like after checking for startup errors.
44Terminal status changing routines
45like
46.Fn nl
47and
1268a632 48.Fn cbreak
9c6a28be
KM
49should be called after
50.Fn initscr .
51.pp
52Now that the screen windows have been allocated,
53you can set them up for the run.
54If you want to, say, allow the window to scroll,
55use
56.Fn scrollok .
57If you want the cursor to be left after the last change, use
58.Fn leaveok .
59If this isn't done,
60.Fn refresh
61will move the cursor to the window's current \*y after updating it.
62New windows of your own can be created, too, by using the functions
63.Fn newwin
64and
65.Fn subwin .
66.Fn delwin
67will allow you to get rid of old windows.
68If you wish to change the official size of the terminal by hand,
69just set the variables
70.Vn LINES
71and
72.Vn COLS
73to be what you want,
74and then call
75.Fn initscr .
76This is best done before,
77but can be done either before or after,
78the first call to
79.Fn initscr ,
80as it will always delete any existing
81.Vn stdscr
82and/or
83.Vn curscr
84before creating new ones.
85.pp
86.sh 2 "The Nitty-Gritty"
87.sh 3 Output
88.pp
89Now that we have set things up,
90we will want to actually update the terminal.
91The basic functions
92used to change what will go on a window are
93.Fn addch
94and
95.Fn move .
96.Fn addch
97adds a character at the current \*y,
98returning ERR if it would cause the window to illegally scroll,
1268a632 99.i i.e. ,
9c6a28be
KM
100printing a character in the lower right-hand corner
101of a terminal which automatically scrolls
102if scrolling is not allowed.
103.Fn move
104changes the current \*y to whatever you want them to be.
105It returns ERR if you try to move off the window when scrolling is not allowed.
106As mentioned above, you can combine the two into
107.Fn mvaddch
108to do both things in one fell swoop.
109.pp
110The other output functions,
111such as
112.Fn addstr
113and
114.Fn printw ,
115all call
116.Fn addch
117to add characters to the window.
118.pp
119After you have put on the window what you want there,
120when you want the portion of the terminal covered by the window
121to be made to look like it,
122you must call
123.Fn refresh .
124In order to optimize finding changes,
125.Fn refresh
126assumes that any part of the window not changed
127since the last
128.Fn refresh
129of that window has not been changed on the terminal,
1268a632 130.i i.e. ,
9c6a28be
KM
131that you have not refreshed a portion of the terminal
132with an overlapping window.
133If this is not the case,
1268a632
KM
134the routines
135.Fn touchwin ,
136.Fn touchline ,
137and
138.Fn touchoverlap
139are provided to make it look like a desired part of window has been changed,
140thus forcing
9c6a28be 141.Fn refresh
1268a632 142check that whole subsection of the terminal for changes.
9c6a28be
KM
143.pp
144If you call
145.Fn wrefresh
146with
147.Vn curscr ,
148it will make the screen look like
149.Vn curscr
150thinks it looks like.
151This is useful for implementing a command
152which would redraw the screen in case it get messed up.
153.sh 3 Input
154.pp
155Input is essentially a mirror image of output.
156The complementary function to
157.Fn addch
158is
159.Fn getch
160which,
161if echo is set,
162will call
163.Fn addch
164to echo the character.
165Since the screen package needs to know what is on the terminal at all times,
166if characters are to be echoed,
167the tty must be in raw or cbreak mode.
168If it is not,
169.Fn getch
170sets it to be cbreak,
171and then reads in the character.
172.sh 3 Miscellaneous
173.pp
174All sorts of fun functions exists for maintaining and changing information
175about the windows.
176For the most part,
177the descriptions in section 5.4. should suffice.
178.sh 2 "Finishing up"
179.pp
180In order to do certain optimizations,
181and,
182on some terminals,
183to work at all,
184some things must be done
185before the screen routines start up.
186These functions are performed in
187.Fn getttmode
188and
189.Fn setterm ,
190which are called by
191.Fn initscr .
192In order to clean up after the routines,
193the routine
194.Fn endwin
195is provided.
196It restores tty modes to what they were
197when
198.Fn initscr
199was first called.
200Thus,
201anytime after the call to initscr,
202.Fn endwin
203should be called before exiting.