NCurses 刷新
我正在运行一个小型 ncurse 程序,但除非我将 wrefresh()
放在 while 循环中,否则输出似乎不会显示。
是不是有缓冲什么的?我尝试了库中的其他 refresh
函数以及使用 stddout
的 fflush
(我认为这没有意义,但值得一试),但是似乎没有什么作用。
第二个小问题:要使 getch()
非阻塞,我们需要调用 nodelay(win,TRUE)
,对吧?
void main()
{
initscr();
start_color();
init_pair(1,COLOR_YELLOW,COLOR_CYAN);
WINDOW *win = newwin(10,10,1,1);
wbkgd(win,COLOR_PAIR(1));
wprintw(win,"Hello, World.");
wrefresh(win);
getch();
delwin(win);
endwin();
}
I have a small ncurse program I'm running, but the output doesn't seem to show up unless I stick the wrefresh()
in a while loop.
Is there some buffering going on or something? I tried other refresh
functions in the library and fflush
with stddout
(which I don't think makes sense, but worth a try), but nothing seems to work.
A second small question: to make getch()
non-blocking we need to call nodelay(win,TRUE)
, right?
void main()
{
initscr();
start_color();
init_pair(1,COLOR_YELLOW,COLOR_CYAN);
WINDOW *win = newwin(10,10,1,1);
wbkgd(win,COLOR_PAIR(1));
wprintw(win,"Hello, World.");
wrefresh(win);
getch();
delwin(win);
endwin();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应该混合对
stdscr
和使用newwin()
创建的窗口进行操作。getch()
在stdscr
上运行,所以这就是你的问题。将该调用替换为(
getch()
会导致stdscr
被转储到另一个窗口的顶部,并且由于这种情况发生得太快,看起来其他窗口从未得到过完全显示)。You are not supposed to mix operations on
stdscr
and windows created withnewwin()
.getch()
operates onstdscr
, so that is your problem. Replace that call with(
getch()
is causingstdscr
to be dumped over the top of your other window, and because that happens so quickly it looks like the other window never got displayed at all).这就是按设计工作的。这允许您完全重绘下一个屏幕,但只有实际更改的部分才会在刷新时发送到终端。如今,这并不是什么大问题,但当终端连接相对较慢时,就会产生很大的影响。
That's working as designed. That allows you to completely redraw your next screen but only the parts that actually changed get sent to the terminal at refresh time. This isn't such a big deal these days but made a big difference when terminal connections were relatively slow.