Behavior of refresh (ncurses)

Asked

Viewed 56 times

2

I was recently studying the ncurses library and I came across a question: What exactly should the refresh function do?

Researching a little I understood that she should update the screen, showing the formatted output. Basically it would make all the changes in the "screen" in buffer and only after the refresh that actually the output would eventually appear.

But doing some tests, I noticed that output appears with or without the refresh. In the program below it is quite simple to test inputs and position manipulation in mvprintw:

#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;
}

Removing the refresh or placing it in any part of the code, being inside the loop or outside, apparently does not change anything at the output of the program.

What exactly is refresh functionality()??

  • my guess is that when getch is called is made an automatic refresh

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.