curs_kernel(3X)
π curs_kernel(3X) β low-level curses routines π
okay so bestie. this is curs_kernel(3X), a page from the Library calls shelf of your friendly neighbourhood ncurses manual. it's the backstage-pass page: all the low-level, under-the-hood curses routines that the fancy library functions use when nobody's watching. no cap, these are the plumbing of curses and they are lowkey iconic for it. π«Ά
β¨ SYNOPSIS β¨
#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));
πΈ DESCRIPTION πΈ
so the whole vibe of this page is: low-level access to various curses capabilities. these routines typically get used inside library routines β like, they're the ones doing the work behind the curtain while the main character functions take the applause. π
π§ def_prog_mode, def_shell_mode
def_prog_mode and def_shell_mode save the terminal's current modes as either the βprogramβ state (that's the in-curses one) or the βshellβ state (the not-in-curses one), so that reset_prog_mode and reset_shell_mode can bring them back later.
initscr does this for you automatically, bestie. and heads up: there's one such save area for each screen context allocated by newterm. so it's not one shared lil box, it's one per screen context. π
π¦ reset_prog_mode, reset_shell_mode
reset_prog_mode and reset_shell_mode do the reverse β they restore the terminal to βprogramβ state (in curses) or βshellβ state (out of curses).
these get done automatically by endwin(3X) and, after an endwin, by doupdate β so like, normally you do not call these. they handle themselves. main character energy, honestly. β¨
π resetty, savetty
resetty and savetty save and restore the state of the terminal modes.
savettysaves the current state into a buffer πΎresettyrestores the state to whatever it was at the last call tosavettyβͺ
π getsyx
getsyx stores the coordinates of the virtual screen (newscr) cursor in y and x.
if newscr's leaveok(3X) output option is TRUE, then getsyx stores -1 in both y and x. and if lines have been removed from the top of the screen using ripoffline, then y includes those lines β which is why the y and x you get out of getsyx should be used only as arguments for setsyx. don't go repurposing them, they're not for that. π«
few applications use this feature; most call getyx(3X) instead.
πΈ setsyx
setsyx sets the virtual screen (newscr) cursor location to (y, x). and setsyx(-1, -1) is equivalent to leaveok(newscr, TRUE). cute, right?
getsyx and setsyx are designed to be used by a function that manipulates curses windows but wants 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.
β curs_set
curs_set adjusts cursor visibility to βinvisibleβ, βvisibleβ, or βvery visibleβ, depending on whether its argument is 0, 1, or 2, respectively.
it returns the previous visibility if the requested one is supported, and ERR otherwise. periodt. π
π« mvcur
mvcur provides low-level cursor motion. it takes effect immediately, rather than at the next refresh. iconic behaviour honestly.
unlike the other low-level output functions β which either write to the standard output stream or get passed a function pointer to perform output β mvcur uses a file descriptor derived from the output stream parameter of newterm(3X). so it's built different. π¦
one application of mvcur accompanies the temporary use of another program to write to the terminal screen. for example, you'd:
- first call
refresh(3X)to ensure 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 π
π napms
napms sleeps for ms milliseconds. and if ms exceeds 30,000 (thirty seconds), ncurses caps it at that value. so no, you cannot nap forever. sadly. π
π ripoffline
ripoffline gives you access to the same facility that slk_init(3X) uses to reduce the size of the screen.
the application must call ripoffline before initscr(3X) or newterm(3X) β that way those functions prepare a stdscr of the correct size. timing matters, bestie.
- if
lineis positive,ripofflineremoves a line from the top of what will becomestdscr. - if
lineis negative,ripofflineremoves a line from the bottom of what will becomestdscr.
when initscr initializes curses, it calls the init function supplied to ripoffline by the application, with two arguments:
- a pointer to the one-line
WINDOWthat it allocates, and - 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 β so don't trust them there. and it must not call wrefresh(3X) or doupdate(3X). a wnoutrefresh(3X) call is permissible though. πΈ
ripoffline can be called up to five times before initscr or newterm.
π RETURN VALUE π
except for curs_set, these functions return OK on success and ERR on failure.
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:
def_prog_mode,def_shell_mode,reset_prog_mode, andreset_shell_modereturnERRif the terminal was not initialized, or if the operating system's function for obtaining terminal settings fails.ripofflinereturnsERRif the accumulated quantity of ripped-off lines would exceed the maximum (5).
π NOTES π
getsyx is a macro β so using the & operator before its arguments is unnecessary. don't do it, it's giving unnecessary effort. π
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. it simply cannot know. π
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. it's giving "we asked for a return value but we're not reading it." π
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.
okay that one is a real one, bestie β null pointer checks are not optional here. check it. π¨
π EXTENSIONS π
in ncurses, mvcur accepts -1 for either or both old coordinates. this value tells ncurses that the old location is unknown, and that it must use only absolute motion β as with the cursor_address (cup) capability β rather than the least costly combination of absolute and relative motion.
π¦ PORTABILITY π¦
applications employing ncurses extensions should condition their use on the visibility of the NCURSES_VERSION preprocessor macro.
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. so like, don't count on that. π«
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.
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 β and we quote:
β[c]alls to ripoffline above this limit [five lines] have no effect but report successβ
X/Open Curses notes:
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.
if interrupted by a signal, ncurses restarts napms. that, and the limitation to 30 seconds, differ from other implementations. π
π SEE ALSO π
curses(3X)curs_initscr(3X)curs_outopts(3X)curs_refresh(3X)curs_scr_dump(3X)curs_slk(3X)curs_variables(3X)
and that's the whole page, bestie!! you now know the low-level curses routines better than like, most people. slay. π β¨
this has been curs_kernel(3X) from ncurses 6.6, dated 2025-08-16 β go forth and mvcur responsibly, mwah π«Άπ
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 1998-2016,2017 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms