curs_refresh(3X)
β¨ curs_refresh β refresh curses windows or lines thereupon β¨
okay bestie, pull up a chair because this one is literally the glow-up routine for your terminal π
this page lives in the curs_refresh(3X) corner of the library-calls section, and it's all about getting your carefully arranged window data to actually show up on screen.
πΈ 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 π
okay so here's the tea: refresh and wrefresh (or wnoutrefresh and doupdate) are the ones you must call to get actual output to the terminal. everything else is just vibes and data structures, no cap β the other routines merely manipulate data structures and nothing hits the screen until you refresh. π
wrefresh copies the named window to the physical screen, and it's smart about it: it takes into account what is already there to do optimizations. refresh is the exact same thing but using stdscr as the default window. and unless leaveok(3X) has been enabled, the physical cursor of the terminal is left at the location of the cursor for that window. iconic behavior honestly.
β¨ wnoutrefresh, doupdate β¨
wnoutrefresh and doupdate let you do multiple updates with more efficiency than wrefresh alone. main character energy fr fr. in addition to all the window structures, curses keeps two data structures representing the terminal screen:
- a physical screen, describing what is actually on the screen, and
- a virtual screen, describing what the programmer wants to have on the screen.
the way that wrefresh works is:
- first calling
wnoutrefresh, which copies the named window to the virtual screen, and - then calling
doupdate, which compares the virtual screen to the physical screen and does the actual update.
so 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. not the move. π 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. efficiency slay. π₯
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. fresh start, no baggage. π§
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 π
wredrawln tells 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). and redrawwin touches the entire window. full reset, full send. π
π RETURN VALUE π
these routines return the integer ERR upon failure and OK
in this implementation
wnoutrefreshβ returnsERRif the window pointer is null, or if the window is really a pad.wredrawlnβ returnERRif the associated call totouchlnreturnsERR.
π NOTES π
refresh and redrawwin may be implemented as macros. (iykyk β so don't go taking their address, bestie.)
π PORTABILITY π
X/Open Curses Issue 4 describes these functions. it specifies no error conditions for them.
SVr4 describes a successful return value only as "an integer value other than ERR".
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. no cap, do that. π«Ά
π SEE ALSO π
curses(3X)curs_outopts(3X)curs_variables(3X)
and that's the whole page, bestie!! this was brought to you by ncurses 6.6, dated 2025-01-18 β go forth and refresh responsibly πβ¨
π¦ where this page comes from
- alpine 3.24: ncurses-doc 6.6_p20260516-r0 Β· X11
- arch rolling: ncurses 6.6-2 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 1998-2010,2016 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms