]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libcurses/PSD.doc/intro.3
Add $Id$, to make it simpler for members of the translation teams to
[FreeBSD/FreeBSD.git] / lib / libcurses / PSD.doc / intro.3
1 .\" Copyright (c) 1980, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)intro.3     8.1 (Berkeley) 6/4/93
33 .\"     $Id$
34 .\"
35 .sh 1 Usage
36 .pp
37 This is a description of how to actually use the screen package.
38 For simplicity, we assume all updating, reading, etc.
39 is applied to
40 .Vn stdscr , 
41 although a different window can of course be specified.
42 .sh 2 "Initialization"
43 .pp
44 In order to use the screen package,
45 the routines must know about terminal characteristics,
46 and the space for
47 .Vn curscr
48 and
49 .Vn stdscr
50 must be allocated.
51 These functions are performed by
52 .Fn initscr .
53 Since it must allocate space for the windows,
54 it can overflow core when attempting to do so.
55 On this rather rare occasion,
56 .Fn initscr
57 returns ERR.
58 .Fn Initscr
59 must
60 .bi always
61 be called before any of the routines which affect windows are used.
62 If it is not,
63 the program will core dump as soon as either
64 .Vn curscr
65 or
66 .Vn stdscr
67 are referenced.
68 However, it is usually best to wait to call it
69 until after you are sure you will need it,
70 like after checking for startup errors.
71 Terminal status changing routines
72 like
73 .Fn nl
74 and
75 .Fn cbreak
76 should be called after
77 .Fn initscr .
78 .pp
79 After the initial window allocation done by 
80 .Fn initscr ,
81 specific window characteristics can be set.
82 Scrolling can be enabled by calling
83 .Fn scrollok .
84 If you want the cursor to be left after the last change, use
85 .Fn leaveok .
86 If this isn't done,
87 .Fn refresh
88 will move the cursor to the window's current \*y after updating it.
89 Additional windows can be created by using the functions
90 .Fn newwin
91 and
92 .Fn subwin .
93 .Fn Delwin
94 allows you to delete an exisiting window.
95 The variables
96 .Vn LINES
97 and
98 .Vn COLS
99 control the size of the terminal.  They are initially implicitly set by 
100 .Fn initscr ,
101 but can be altered explicitly by the user followed by a call to 
102 .Fn initscr .
103 Note that any call to 
104 .Fn initscr ,
105 will always delete any existing
106 .Vn stdscr
107 and/or
108 .Vn curscr
109 before creating new ones so this change is best done before the initial call to
110 .Fn initscr .
111 .pp
112 .sh 2 "Output"
113 .pp
114 The basic functions
115 used to change what will go on a window are
116 .Fn addch
117 and
118 .Fn move .
119 .Fn Addch
120 adds a character at the current \*y,
121 returning ERR if it would cause the window to illegally scroll,
122 .i i.e. ,
123 printing a character in the lower right-hand corner
124 of a terminal which automatically scrolls
125 if scrolling is not allowed.
126 .Fn Move
127 changes the current \*y to whatever you want them to be.
128 It returns ERR if you try to move off the window.
129 As mentioned above, you can combine the two into
130 .Fn mvaddch
131 to do both things in one call.
132 .pp
133 The other output functions 
134 (such as
135 .Fn addstr
136 and
137 .Fn printw )
138 all call
139 .Fn addch
140 to add characters to the window.
141 .pp
142 After a change has been made to the window,
143 you must call 
144 .Fn refresh .
145 when you want the portion of the terminal covered by the window
146 to reflect the change.
147 In order to optimize finding changes,
148 .Fn refresh
149 assumes that any part of the window not changed
150 since the last
151 .Fn refresh
152 of that window has not been changed on the terminal,
153 .i i.e. ,
154 that you have not refreshed a portion of the terminal
155 with an overlapping window.
156 If this is not the case,
157 the routines
158 .Fn touchwin ,
159 .Fn touchline ,
160 and
161 .Fn touchoverlap
162 are provided to make it look like a desired part of window has been changed,
163 thus forcing
164 .Fn refresh
165 to check that whole subsection of the terminal for changes.
166 .pp
167 If you call
168 .Fn wrefresh
169 with
170 .Vn curscr ,
171 it will make the screen look like the image of 
172 .Vn curscr .
173 This is useful for implementing a command
174 which would redraw the screen in case it got messed up.
175 .sh 2 Input
176 .pp
177 Input is essentially a mirror image of output.
178 The complementary function to
179 .Fn addch
180 is
181 .Fn getch
182 which,
183 if echo is set,
184 will call
185 .Fn addch
186 to echo the character.
187 Since the screen package needs to know what is on the terminal at all times,
188 if characters are to be echoed,
189 the tty must be in raw or cbreak mode.
190 If it is not,
191 .Fn getch
192 sets it to be cbreak,
193 and then reads in the character.
194 .sh 2 "Termination"
195 .pp
196 In order to perform certain optimizations,
197 and, 
198 on some terminals,
199 to work at all,
200 some things must be done
201 before the screen routines start up.
202 These functions are performed in
203 .Fn getttmode
204 and
205 .Fn setterm ,
206 which are called by
207 .Fn initscr .
208 In order to clean up after the routines,
209 the routine
210 .Fn endwin
211 is provided.
212 It restores tty modes to what they were
213 when
214 .Fn initscr
215 was first called.
216 The terminal state module uses the variable 
217 .Vn curses_termios
218 to save the original terminal state which is then restored upon a call to 
219 .Fn endwin .
220 Thus,
221 anytime after the call to initscr,
222 .Fn endwin
223 should be called before exiting.  Note however, that 
224 .Fn endwin 
225 should always be called 
226 .b before
227 the final calls to
228 .Fn delwin ,
229 which free the storage of the windows.