刷新行为(nCurses) [英] Refresh Behaviour (nCurses)
问题描述
我最近正在研究ncurses,一个疑问刚好打了我:刷新功能到底能做什么?
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??
推荐答案
getch
函数调用 refresh
,这可能会使您感到困惑>将移动到 refresh
的显式调用.
The getch
function calls refresh
, which is probably confusing you as you move the explicit call for refresh
to different places.
curses函数写入虚拟屏幕(即非真实),而 refresh
更新 physical 屏幕(真实屏幕)比较两者并进行一些小的更改(如果可能的话).
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).
这篇关于刷新行为(nCurses)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!