refresh(3NCURSES)
β¨ refresh β bestie edition β¨
okay so this is the refresh(3NCURSES) page from the ncurses library calls girlies π it's literally the one that makes stuff actually show up on your terminal instead of just vibing in memory. come sit with me.
πΈ NAME πΈ
doupdate, redrawwin, refresh, wnoutrefresh, wredrawln, wrefresh β the lil squad that refreshes curses windows, or just the lines on top of them π«Ά
π 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
so here's the tea bestie: refresh and wrefresh (or, alternatively, wnoutrefresh and doupdate) are the ones you must call to get actual output to the terminal. every other routine is just out here manipulating data structures, being fake, not showing up on screen π no cap.
wrefresh copies the named window to the physical screen, and it's smart about it β it takes into account what's already there so it can do optimizations. refresh is literally the same thing except it uses stdscr as the default window. and unless leaveok(3NCURSES) has been enabled, the physical cursor of the terminal gets left at the location of the cursor for that window. iconic behavior tbh.
π¦ wnoutrefresh, doupdate
wnoutrefresh and doupdate are the glow-up: they let you do multiple updates with way more efficiency than wrefresh alone ever could. π
on top of all the window structures, curses keeps two data structures that represent the terminal screen:
- a physical screen, describing what is actually on the screen rn, and
- a virtual screen, describing what the programmer wants to have on the screen (the dream, the vision, the main character energy β¨).
the way wrefresh works is literally:
- first it calls
wnoutrefresh, which copies the named window to the virtual screen, and then - it calls
doupdate, which compares the virtual screen to the physical screen and does the actual update.
so if you wanna output several windows at once β bestie, listen β a series of calls to wrefresh results in alternating calls to wnoutrefresh and doupdate, which causes several bursts of output to the screen. not the vibe. but by first calling wnoutrefresh for each window, you can then call doupdate once, resulting in only one burst of output, with fewer total characters transmitted and less CPU time used. ate. π₯
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. full reset, no notes.
okay so the phrase "copies the named window to the virtual screen" above is ambiguous, ngl. 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, bestie, I'm serious π)
π§ wredrawln, redrawwin
wredrawln is the one you call when you're like "these screen lines are corrupted and I cannot deal". it 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). and redrawwin? it touches the entire window. whole thing. no half measures. π
β 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. sneaky little things. iykyk.
π 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". vague of them honestly.
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). so 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. do that. protect yourself. π«Ά
π SEE ALSO π
ncurses(3NCURSES), outopts(3NCURSES), curses_variables(3NCURSES)
and that's the whole page, bestie π this was ncurses 6.6, dated 2025-01-18, and no cap it's giving reference manual excellence. go refresh something. slay. πβ¨
π¦ where this page comes from
- ubuntu resolute: ncurses-doc 6.6+20251231-1 Β· MIT/X11
- ubuntu stonking: ncurses-doc 6.6+20260608-2 Β· MIT/X11
- 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