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