xref: /freebsd/contrib/ncurses/man/curs_refresh.3x (revision 96190b4fef3b4a0cc3ca0606b0c4e3e69a5e6717)
***************************************************************************
Copyright 2018-2023,2024 Thomas E. Dickey *
Copyright 1998-2010,2016 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_refresh.3x,v 1.46 2024/04/20 21:20:07 tom Exp $
curs_refresh 3X 2024-04-20 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "Library calls"
.\} .\} . ..
NAME
\%doupdate, \%redrawwin, \%refresh, \%wnoutrefresh, \%wredrawln, \%wrefresh - refresh curses windows or lines thereupon
SYNOPSIS
#include <curses.h>

int refresh(void); int wrefresh(WINDOW *win); int wnoutrefresh(WINDOW *win); int doupdate(void);

int redrawwin(WINDOW *win); int wredrawln(WINDOW *win, int beg_line, int num_lines);

DESCRIPTION
"refresh, wrefresh"
The refresh and wrefresh routines (or wnoutrefresh and doupdate) must be called to get actual output to the terminal, as other routines merely manipulate data structures. The routine wrefresh copies the named window to the physical screen, taking into account what is already there to do optimizations. The refresh routine is the same, using stdscr as the default window. Unless leaveok(3X) has been enabled, the physical cursor of the terminal is left at the location of the cursor for that window.
"wnoutrefresh, doupdate"
The wnoutrefresh and doupdate routines allow multiple updates with more efficiency than wrefresh alone. In addition to all the window structures, curses keeps two data structures representing the terminal screen: .bP a physical screen, describing what is actually on the screen, and .bP a virtual screen, describing what the programmer wants to have on the screen.

The routine wrefresh works by .bP first calling wnoutrefresh, which copies the named window to the virtual screen, and .bP then calling doupdate, which compares the virtual screen to the physical screen and does the actual update.

If the programmer wishes to output several windows at once, a series of calls to wrefresh results in alternating calls to wnoutrefresh and doupdate, causing several bursts of output to the screen. By first calling wnoutrefresh for each window, it is then possible to call doupdate once, resulting in only one burst of output, with fewer total characters transmitted and less CPU time used.

If the win argument to wrefresh is the physical screen (i.e., the global variable curscr), the screen is immediately cleared and repainted from scratch.

The phrase \*(``copies the named window to the virtual screen\*('' above is ambiguous. What actually happens is that all touched (changed) lines in the window are copied to the virtual screen. This affects programs that use overlapping windows; it means that if two windows overlap, you can refresh them in either order and the overlap region will be modified only when it is explicitly changed. (But see the section on PORTABILITY below for a warning about exploiting this behavior.)

"wredrawln, redrawwin"
The wredrawln routine indicates to curses that some screen lines are corrupted and should be thrown away before anything is written over them. It touches the indicated lines (marking them changed). The routine redrawwin touches the entire window.
RETURN VALUE
These routines return the integer ERR upon failure and OK (SVr4 specifies only \*(``an integer value other than ERR\*('') upon successful completion.

X/Open Curses does not specify any error conditions. In this implementation

5 wnoutrefresh returns an error if the window pointer is null, or if the window is really a pad.

5 wredrawln returns an error if the associated call to touchln returns an error.

NOTES
Note that refresh and redrawwin may be macros.
PORTABILITY
X/Open Curses, Issue 4 describes these functions.

Whether wnoutrefresh copies to the virtual screen the entire contents of a window or just its changed portions has never been well-documented in historic curses versions (including SVr4). It might be unwise to rely on either behavior in programs that might have to be linked with other curses implementations. Instead, you can do an explicit touchwin before the wnoutrefresh call to guarantee an entire-contents copy anywhere.

SEE ALSO
\%curses(3X), \%curs_outopts(3X) \%curs_variables(3X)