]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_kernel.3x
ncurses 6.5 - patch 20240608
[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.65 2024/06/08 21:00:58 tom Exp $
31 .TH curs_kernel 3X 2024-06-08 "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 .B \%mvcur
202 to set the cursor's location to where
203 .I \%curses
204 thinks it is,
205 since the library has no knowledge of how the external application
206 moved it.
207 .\" https://lists.gnu.org/archive/html/bug-ncurses/2016-10/msg00002.html
208 .SS napms
209 .B \%napms
210 sleeps for
211 .I ms
212 milliseconds.
213 If
214 .I ms
215 exceeds 30,000
216 (thirty seconds),
217 it is capped at that value.
218 .SS ripoffline
219 .B \%ripoffline
220 provides access to the same facility that \fB\%slk_init\fP(3X) uses to
221 reduce the size of the screen.
222 \fB\%ripoffline\fP must be called before \fBinitscr\fP or
223 \fBnewterm\fP is called, to prepare these initial actions:
224 .bP
225 If \fIline\fP is positive, a line is removed from the top of \fBstdscr\fP.
226 .bP
227 if \fIline\fP is negative, a line is removed from the bottom.
228 .PP
229 When the resulting initialization is done inside \fBinitscr\fP, the
230 routine \fBinit\fP (supplied by the user) is called with two
231 arguments:
232 .bP
233 a window pointer to the one-line window that has been
234 allocated and
235 .bP
236 an integer with the number of columns in the window.
237 .PP
238 Inside this initialization routine, the integer variables \fBLINES\fP
239 and \fBCOLS\fP (defined in \fB<curses.h>\fP) are not guaranteed to be
240 accurate and \fBwrefresh\fP or \fBdoupdate\fP must not be called.
241 It is allowable to call \fBwnoutrefresh\fP during the initialization routine.
242 .PP
243 \fBripoffline\fP can be called up to five times before calling \fBinitscr\fP or
244 \fBnewterm\fP.
245 .SH RETURN VALUE
246 Except for \fBcurs_set\fP, these routines always return \fBOK\fP.
247 .PP
248 \fBcurs_set\fP
249 returns the previous cursor state, or \fBERR\fP if the
250 requested \fIvisibility\fP is not supported.
251 .PP
252 X/Open defines no error conditions.
253 In this implementation
254 .TP 5
255 \fBdef_prog_mode\fP, \fBdef_shell_mode\fP, \fBreset_prog_mode\fP, \fBreset_shell_mode\fP
256 return
257 .B ERR
258 if the terminal was not initialized, or
259 if the I/O call to obtain the terminal settings fails.
260 .TP 5
261 \fBripoffline\fP
262 returns
263 .B ERR
264 if the maximum number of ripped-off lines
265 exceeds the maximum (5).
266 .SH NOTES
267 Note that \fBgetsyx\fP is a macro, so \fB&\fP is not necessary before
268 the variables \fIy\fP and \fIx\fP.
269 .PP
270 Older SVr4 man pages warn that the return value
271 of \fBcurs_set\fP \*(``is currently incorrect\*(''.
272 This implementation gets it right, but it may be unwise to count
273 on the correctness of the return value anywhere else.
274 .PP
275 Both \fI\%ncurses\fP and SVr4 will call \fBcurs_set\fP in \fBendwin\fP
276 if \fBcurs_set\fP
277 has been called to make the cursor other than normal, i.e., either
278 invisible or very visible.
279 There is no way for \fI\%ncurses\fP to determine the initial cursor
280 state to restore that.
281 .SH EXTENSIONS
282 In
283 .IR \%ncurses ","
284 .B \%mvcur
285 accepts
286 .B \-1
287 for either or both old coordinates.
288 This value tells
289 .I \%ncurses
290 that the old location is unknown,
291 and that it must use only absolute motion,
292 as with the
293 .B \%cursor_address
294 .RB ( cup )
295 capability,
296 rather than the least costly combination of absolute and relative
297 motion.
298 .SH PORTABILITY
299 Applications employing
300 .I \%ncurses
301 extensions should condition their use on the visibility of the
302 .B \%NCURSES_VERSION
303 preprocessor macro.
304 .PP
305 The \fIvirtual screen\fP functions \fBsetsyx\fP and \fBgetsyx\fP
306 are not described in X/Open Curses, Issue 4.
307 All other functions are as described in X/Open Curses.
308 .PP
309 The SVr4 documentation describes \fBsetsyx\fP and \fBgetsyx\fP
310 as having return type int.
311 This is misleading, as they are macros with no documented semantics
312 for the return value.
313 .PP
314 X/Open Curses notes:
315 .RS
316 .PP
317 \*(``After use of
318 .IR \%mvcur "(),"
319 the model Curses maintains of the state of the terminal might not
320 match the actual state of the terminal.
321 An application should touch and refresh the window before
322 resuming conventional use of Curses.\*(''
323 .RE
324 .PP
325 Both
326 .I \%ncurses
327 and SVr4
328 .I curses
329 implement
330 .B \%mvcur
331 using the
332 .I SCREEN
333 data allocated in either \fB\%initscr\fP(3X) or \fB\%newterm\fP(3X).
334 X/Open Curses states that the old location must be given for
335 .B \%mvcur
336 to accommodate terminals that lack absolute cursor positioning.
337 .\" X/Open Curses Issue 7, p. 161
338 .PP
339 If interrupted, \fI\%ncurses\fP restarts \fBnapms\fP.
340 That, and the limitation to 30 seconds,
341 are different from other implementations.
342 .SH SEE ALSO
343 \fB\%curses\fP(3X),
344 \fB\%curs_initscr\fP(3X),
345 \fB\%curs_outopts\fP(3X),
346 \fB\%curs_refresh\fP(3X),
347 \fB\%curs_scr_dump\fP(3X),
348 \fB\%curs_slk\fP(3X),
349 \fB\%curs_variables\fP(3X)