Refresh Behaviour (nCurses)

给你一囗甜甜゛ 提交于 2019-12-24 16:54:35

问题


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??


回答1:


The getch function calls refresh, which is probably confusing you as you move the explicit call for refresh 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).



来源:https://stackoverflow.com/questions/53251589/refresh-behaviour-ncurses

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!