]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_kernel.3x
ncurses 6.5 - patch 20240622
[ncurses.git] / man / curs_kernel.3x
1 .\"***************************************************************************
2 .\" Copyright 2018-2023,2024 Thomas E. Dickey                                *
3 .\" Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
4 .\"                                                                          *
5 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
6 .\" copy of this software and associated documentation files (the            *
7 .\" "Software"), to deal in the Software without restriction, including      *
8 .\" without limitation the rights to use, copy, modify, merge, publish,      *
9 .\" distribute, distribute with modifications, sublicense, and/or sell       *
10 .\" copies of the Software, and to permit persons to whom the Software is    *
11 .\" furnished to do so, subject to the following conditions:                 *
12 .\"                                                                          *
13 .\" The above copyright notice and this permission notice shall be included  *
14 .\" in all copies or substantial portions of the Software.                   *
15 .\"                                                                          *
16 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23 .\"                                                                          *
24 .\" Except as contained in this notice, the name(s) of the above copyright   *
25 .\" holders shall not be used in advertising or otherwise to promote the     *
26 .\" sale, use or other dealings in this Software without prior written       *
27 .\" authorization.                                                           *
28 .\"***************************************************************************
29 .\"
30 .\" $Id: curs_kernel.3x,v 1.67 2024/06/22 21:24:26 tom Exp $
31 .TH curs_kernel 3X 2024-06-22 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "Library calls"
32 .ie \n(.g \{\
33 .ds `` \(lq
34 .ds '' \(rq
35 .\}
36 .el \{\
37 .ie t .ds `` ``
38 .el   .ds `` ""
39 .ie t .ds '' ''
40 .el   .ds '' ""
41 .\}
42 .
43 .de bP
44 .ie n  .IP \(bu 4
45 .el    .IP \(bu 2
46 ..
47 .SH NAME
48 \fB\%def_prog_mode\fP,
49 \fB\%def_shell_mode\fP,
50 \fB\%reset_prog_mode\fP,
51 \fB\%reset_shell_mode\fP,
52 \fB\%resetty\fP,
53 \fB\%savetty\fP,
54 \fB\%getsyx\fP,
55 \fB\%setsyx\fP,
56 \fB\%curs_set\fP,
57 \fB\%mvcur\fP,
58 \fB\%napms\fP,
59 \fB\%ripoffline\fP \-
60 low-level \fIcurses\fR routines
61 .SH SYNOPSIS
62 .nf
63 \fB#include <curses.h>
64 .PP
65 \fBint def_prog_mode(void);
66 \fBint def_shell_mode(void);
67 .PP
68 \fBint reset_prog_mode(void);
69 \fBint reset_shell_mode(void);
70 .PP
71 \fBint resetty(void);
72 \fBint savetty(void);
73 .PP
74 \fBvoid getsyx(int \fIy\fP, int \fIx\fP);
75 \fBvoid setsyx(int \fIy\fP, int \fIx\fP);
76 .PP
77 \fBint curs_set(int \fIvisibility\fP);
78 \fBint mvcur(int \fIoldrow\fP, int \fIoldcol\fP, int \fInewrow\fP, int \fInewcol\fP);
79 \fBint napms(int \fIms\fP);
80 \fBint ripoffline(int \fIline\fP, int (*\fIinit\fP)(WINDOW *, int));
81 .fi
82 .SH DESCRIPTION
83 The following routines give low-level access
84 to various \fBcurses\fP capabilities.
85 These routines typically are used inside library routines.
86 .SS "def_prog_mode, def_shell_mode"
87 The \fBdef_prog_mode\fP and \fBdef_shell_mode\fP routines save the
88 current terminal modes as the \*(``program\*(''
89 (in \fBcurses\fP) or \*(``shell\*(''
90 (not in \fBcurses\fP) state for use by the \fBreset_prog_mode\fP and
91 \fBreset_shell_mode\fP routines.
92 This is done automatically by \fBinitscr\fP.
93 There is one such save area for each screen context
94 allocated by \fBnewterm\fP.
95 .SS "reset_prog_mode, reset_shell_mode"
96 The \fBreset_prog_mode\fP and \fBreset_shell_mode\fP routines restore
97 the terminal to \*(``program\*('' (in \fBcurses\fP) or \*(``shell\*('' (out of
98 \fBcurses\fP) state.
99 These are done automatically by \fBendwin\fP(3X) and,
100 after an \fBendwin\fP, by \fBdoupdate\fP,
101 so they normally are not called.
102 .SS "resetty, savetty"
103 The \fBresetty\fP and \fBsavetty\fP routines save and restore the
104 state of the terminal modes.
105 \fBsavetty\fP saves the current state in
106 a buffer and \fBresetty\fP restores the state to what it was at the
107 last call to \fBsavetty\fP.
108 .SS getsyx
109 .B \%getsyx
110 stores the coordinates of virtual screen
111 .RB \%( newscr )
112 cursor in
113 .I y
114 and
115 .IR x "."
116 If
117 .BR \%newscr 's
118 \fB\%leaveok\fP(3X) output option is
119 .BR TRUE ","
120 .B \%getsyx
121 stores
122 .B \-1
123 in both
124 .I y
125 and
126 .IR x "."
127 If lines have been removed from the top of the screen using
128 .BR \%ripoffline ","
129 .I y
130 includes these lines;
131 therefore,
132 .I y
133 and
134 .I x
135 populated by
136 .B \%getsyx
137 should be used only as arguments for
138 .BR \%setsyx "."
139 .PP
140 Few applications use this feature;
141 most call \fB\%getyx\fP(3X) instead.
142 .SS setsyx
143 .B \%setsyx
144 sets the virtual screen
145 .RB \%( newscr )
146 cursor location to
147 .RI ( y ,
148 .IR x ")."
149 .B "\%setsyx(\-1, \-1)"
150 is equivalent to
151 .BR "\%leaveok(newscr, TRUE)" "."
152 .PP
153 .B \%getsyx
154 and
155 .B \%setsyx
156 are designed to be used by a function that manipulates
157 .I curses
158 windows but seeks to avoid changing the cursor position.
159 Such a function would first call
160 .BR \%getsyx ","
161 modify its windows' content,
162 call \fB\%wnoutrefresh\fP(3X) on them,
163 call
164 .BR \%setsyx ","
165 then call \fB\%doupdate\fP(3X).
166 .PP
167 Few applications use this feature;
168 most call \fB\%wmove\fP(3X) instead.
169 .SS curs_set
170 The \fBcurs_set\fP routine sets the cursor state to invisible,
171 normal, or very visible for \fBvisibility\fP equal to \fB0\fP,
172 \fB1\fP, or \fB2\fP respectively.
173 If the terminal supports the \fIvisibility\fP requested,
174 the previous \fIcursor\fP state is returned;
175 otherwise, \fBERR\fP is returned.
176 .SS mvcur
177 .B \%mvcur
178 provides low-level cursor motion.
179 It takes effect immediately,
180 rather than at the next refresh.
181 Unlike the other low-level output functions,
182 which either write to the standard output stream
183 or are passed a function pointer to perform output,
184 .B \%mvcur
185 uses a file descriptor derived from the output stream parameter of
186 \fB\%newterm\fP(3X).
187 .PP
188 One application of
189 .B \%mvcur
190 accompanies the temporary use of another program to write to the
191 terminal screen.
192 For example,
193 first call \fB\%refresh\fP(3X) to ensure that the screen and the
194 library's model of it is up to date;
195 then call
196 .BR \%reset_shell_mode ";"
197 write to the screen with the external application;
198 call
199 .BR \%reset_prog_mode ";"
200 and finally call
201 .BR \%mvcur( ".\|.\|." ,
202 .RB .\|.\|. ,
203 .B \-1, \-1)
204 to move the terminal cursor to where
205 .I \%curses
206 thinks it is,
207 since the library has no knowledge of how the external application
208 moved it.
209 .\" https://lists.gnu.org/archive/html/bug-ncurses/2016-10/msg00002.html
210 .SS napms
211 .B \%napms
212 sleeps for
213 .I ms
214 milliseconds.
215 If
216 .I ms
217 exceeds 30,000
218 (thirty seconds),
219 it is capped at that value.
220 .SS ripoffline
221 .B \%ripoffline
222 provides access to the same facility that \fB\%slk_init\fP(3X) uses to
223 reduce the size of the screen.
224 \fB\%ripoffline\fP must be called before \fBinitscr\fP or
225 \fBnewterm\fP is called, to prepare these initial actions:
226 .bP
227 If \fIline\fP is positive, a line is removed from the top of \fBstdscr\fP.
228 .bP
229 if \fIline\fP is negative, a line is removed from the bottom.
230 .PP
231 When the resulting initialization is done inside \fBinitscr\fP, the
232 routine \fBinit\fP (supplied by the user) is called with two
233 arguments:
234 .bP
235 a window pointer to the one-line window that has been
236 allocated and
237 .bP
238 an integer with the number of columns in the window.
239 .PP
240 Inside this initialization routine, the integer variables \fBLINES\fP
241 and \fBCOLS\fP (defined in \fB<curses.h>\fP) are not guaranteed to be
242 accurate and \fBwrefresh\fP or \fBdoupdate\fP must not be called.
243 It is allowable to call \fBwnoutrefresh\fP during the initialization routine.
244 .PP
245 \fBripoffline\fP can be called up to five times before calling \fBinitscr\fP or
246 \fBnewterm\fP.
247 .SH RETURN VALUE
248 Except for \fBcurs_set\fP, these routines always return \fBOK\fP.
249 .PP
250 \fBcurs_set\fP
251 returns the previous cursor state, or \fBERR\fP if the
252 requested \fIvisibility\fP is not supported.
253 .PP
254 X/Open defines no error conditions.
255 In this implementation
256 .TP 5
257 \fBdef_prog_mode\fP, \fBdef_shell_mode\fP, \fBreset_prog_mode\fP, \fBreset_shell_mode\fP
258 return
259 .B ERR
260 if the terminal was not initialized, or
261 if the I/O call to obtain the terminal settings fails.
262 .TP 5
263 \fBripoffline\fP
264 returns
265 .B ERR
266 if the maximum number of ripped-off lines
267 exceeds the maximum (5).
268 .SH NOTES
269 Note that \fBgetsyx\fP is a macro, so \fB&\fP is not necessary before
270 the variables \fIy\fP and \fIx\fP.
271 .PP
272 Older SVr4 man pages warn that the return value
273 of \fBcurs_set\fP \*(``is currently incorrect\*(''.
274 This implementation gets it right, but it may be unwise to count
275 on the correctness of the return value anywhere else.
276 .PP
277 Both \fI\%ncurses\fP and SVr4 will call \fBcurs_set\fP in \fBendwin\fP
278 if \fBcurs_set\fP
279 has been called to make the cursor other than normal, i.e., either
280 invisible or very visible.
281 There is no way for \fI\%ncurses\fP to determine the initial cursor
282 state to restore that.
283 .SH EXTENSIONS
284 In
285 .IR \%ncurses ","
286 .B \%mvcur
287 accepts
288 .B \-1
289 for either or both old coordinates.
290 This value tells
291 .I \%ncurses
292 that the old location is unknown,
293 and that it must use only absolute motion,
294 as with the
295 .B \%cursor_address
296 .RB ( cup )
297 capability,
298 rather than the least costly combination of absolute and relative
299 motion.
300 .SH PORTABILITY
301 Applications employing
302 .I \%ncurses
303 extensions should condition their use on the visibility of the
304 .B \%NCURSES_VERSION
305 preprocessor macro.
306 .PP
307 The \fIvirtual screen\fP functions \fBsetsyx\fP and \fBgetsyx\fP
308 are not described in X/Open Curses, Issue 4.
309 All other functions are as described in X/Open Curses.
310 .PP
311 The SVr4 documentation describes \fBsetsyx\fP and \fBgetsyx\fP
312 as having return type int.
313 This is misleading, as they are macros with no documented semantics
314 for the return value.
315 .PP
316 X/Open Curses notes:
317 .RS
318 .PP
319 \*(``After use of
320 .IR \%mvcur "(),"
321 the model Curses maintains of the state of the terminal might not
322 match the actual state of the terminal.
323 An application should touch and refresh the window before
324 resuming conventional use of Curses.\*(''
325 .RE
326 .PP
327 Both
328 .I \%ncurses
329 and SVr4
330 .I curses
331 implement
332 .B \%mvcur
333 using the
334 .I SCREEN
335 data allocated in either \fB\%initscr\fP(3X) or \fB\%newterm\fP(3X).
336 X/Open Curses states that the old location must be given for
337 .B \%mvcur
338 to accommodate terminals that lack absolute cursor positioning.
339 .\" X/Open Curses Issue 7, p. 161
340 .PP
341 If interrupted, \fI\%ncurses\fP restarts \fBnapms\fP.
342 That, and the limitation to 30 seconds,
343 are different from other implementations.
344 .SH SEE ALSO
345 \fB\%curses\fP(3X),
346 \fB\%curs_initscr\fP(3X),
347 \fB\%curs_outopts\fP(3X),
348 \fB\%curs_refresh\fP(3X),
349 \fB\%curs_scr_dump\fP(3X),
350 \fB\%curs_slk\fP(3X),
351 \fB\%curs_variables\fP(3X)