Copyright 2018-2024,2025 Thomas E. Dickey *
Copyright 1998-2016,2017 Free Software Foundation, Inc. *
*
Permission is hereby granted, free of charge, to any person obtaining a *
copy of this software and associated documentation files (the *
"Software"), to deal in the Software without restriction, including *
without limitation the rights to use, copy, modify, merge, publish, *
distribute, distribute with modifications, sublicense, and/or sell *
copies of the Software, and to permit persons to whom the Software is *
furnished to do so, subject to the following conditions: *
*
The above copyright notice and this permission notice shall be included *
in all copies or substantial portions of the Software. *
*
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
*
Except as contained in this notice, the name(s) of the above copyright *
holders shall not be used in advertising or otherwise to promote the *
sale, use or other dealings in this Software without prior written *
authorization. *
***************************************************************************
$Id: curs_kernel.3x,v 1.89 2025/08/16 19:50:07 tom Exp $
#include <curses.h>int def_prog_mode(void); int def_shell_mode(void);
int reset_prog_mode(void); int reset_shell_mode(void);
int resetty(void); int savetty(void);
void getsyx(int y, int x); void setsyx(int y, int x);
int curs_set(int visibility); int mvcur(int oldrow, int oldcol, int newrow, int newcol); int napms(int ms); int ripoffline(int line, int (*init)(WINDOW *, int));
Few applications use this feature; most call \%getyx(3X) instead.
\%getsyx and \%setsyx are designed to be used by a function that manipulates curses windows but seeks to avoid changing the cursor position. Such a function would first call \%getsyx "," modify its windows' content, call \%wnoutrefresh(3X) on them, call \%setsyx "," then call \%doupdate(3X).
Few applications use this feature; most call \%wmove(3X) instead.
One application of
\%mvcur accompanies the temporary use of another program to write to the
terminal screen.
For example,
first call \%refresh(3X) to ensure that the screen and the
library's model of it are up to date;
then call
\%reset_shell_mode ";" write to the screen with the external application;
call
\%reset_prog_mode ";" and finally call
\%mvcur( ".\|.\|." , .\|.\|. , -1, -1) to move the terminal cursor to where
\%curses thinks it is,
since the library has no knowledge of how the external application
moved it.
https://lists.gnu.org/archive/html/bug-ncurses/2016-10/msg00002.html
When \%initscr initializes curses "," it calls the init function supplied to \%ripoffline by the application with two arguments: .bP a pointer to the one-line \%WINDOW that it allocates, and .bP an integer with the number of columns in the window.
Inside this init function, the values of the integer variables LINES and COLS (see \%curs_variables(3X)) are not guaranteed to be reliable; it must not call \%wrefresh(3X) or \%doupdate(3X). A \%wnoutrefresh(3X) call is permissible.
\%ripoffline can be called up to five times before \%initscr or \%newterm "."
\%curs_set returns the previous cursor visibility, and returns ERR if the terminal type does not support the requested visibility "."
\%napms always succeeds.
\%mvcur fails if the position ( newrow , newcol ) is outside the screen boundaries.
In \%ncurses "," .bP \%def_prog_mode "," \%def_shell_mode "," \%reset_prog_mode "," and \%reset_shell_mode return ERR if the terminal was not initialized, or if the operating system's function for obtaining terminal settings fails. .bP \%ripoffline returns ERR if the accumulated quantity of ripped-off lines would exceed the maximum (5).
The \%endwin function of both \%ncurses and SVr4 curses calls \%curs_set if the latter has previously been called to set the cursor visibility to a value other than normal; that is, either invisible or very visible. There is no way for \%ncurses to determine the initial cursor visibility to restore it.
\%ncurses imposes a limit of 30 seconds on a delay requested of \%napms .
While the init function called by \%ripoffline is specified to return an int "," \%ncurses pays no attention to its return value.
If \%ripoffline cannot allocate memory for the required \%WINDOW structure backing the ripped-off line, it stores a null pointer to the \%WINDOW pointer argument supplied by the init function the application specifies. The application must check this argument for validity after calling \%initscr and prior to performing curses operations on that window.
The "virtual screen" functions \%setsyx and \%getsyx are not described in X/Open Curses Issue 4. SVr4 documents each of them as returning an int "." This is misleading, as they are macros with no documented semantics for returning values.
All other functions are as described in X/Open Curses. It specifies no error conditions for them, except as described for \%curs_set in section \*(``RETURN VALUE\*('' above.
The System V Interface Definition,
Version 4 (1995),
specified all of these functions except
\%curs_set as returning
OK "." SVID 4, vol 3., p. 518
Older SVr4 man pages warn that the return value of \%curs_set \*(``is currently incorrect\*(''. This implementation gets it right, but counting on its correctness anywhere else may be unwise.
X/Open Curses specifies \%ripoffline as returning OK with no possibility of failure (\*(``[c]alls to \%ripoffline above this limit [five lines] have no effect but report success\*('').
After use of \%mvcur "()," the model Curses maintains of the state of the terminal might not match the actual state of the terminal. An application should touch and refresh the window before resuming conventional use of Curses.
Both
\%ncurses and SVr4
curses implement
\%mvcur using the
SCREEN object allocated in either \%initscr(3X) or \%newterm(3X).
X/Open Curses states that the old location must be given for
\%mvcur to accommodate terminals that lack absolute cursor positioning.
X/Open Curses Issue 7, p. 161
If interrupted by a signal, \%ncurses restarts \%napms "." That, and the limitation to 30 seconds, differ from other implementations.