I recently was studying ncurses and a doubt just hit me: What EXACTLY does the refresh function does?
I searched a little about it, read some tutorials and even a documentation and my conclusion was that it "refreshes" the actual screen with the format done on the "buffer screen" (it just updates the output on the screen).
Doing some tests I clearly realized I was wrong since the output appeared with and without the refresh function! Below there's a simple program I did just to test it and I can't realize the actual functionality of this function.
#include <ncurses.h>
#include <string.h>
int main() {
char mesg[] = "Just a String";
int row, col;
initscr();
getmaxyx(stdscr, row, col);
while(true) {
refresh();
mvprintw(row/2, (col - strlen(mesg))/2, "%s", mesg);
mvprintw(row-2, 0, "This screen has %d rows and %d columns\n", row, col);
char c = getch();
if (c == 'e') { row++; }
else if (c == 'q') { row--; }
else if (c == 'a') { col--; }
else if (c == 'd') { col++; }
}
getch();
endwin();
return 0;
}
I moved the refresh all over the program, I removed it and nothing seems to change. What exactly it does??
The
getch
function callsrefresh
, which is probably confusing you as you move the explicit call forrefresh
to different places.Curses functions write to a virtual screen (i.e., not real) and
refresh
updates the physical screen (the real one) by comparing the two and making small changes (if possible).