NCurses 刷新

发布于 2024-09-25 15:03:21 字数 618 浏览 0 评论 0原文

我正在运行一个小型 ncurse 程序,但除非我将 wrefresh() 放在 while 循环中,否则输出似乎不会显示。

是不是有缓冲什么的?我尝试了库中的其他 refresh 函数以及使用 stddoutfflush (我认为这没有意义,但值得一试),但是似乎没有什么作用。

第二个小问题:要使 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

澜川若宁 2024-10-02 15:03:21

您不应该混合对 stdscr 和使用 newwin() 创建的窗口进行操作。 getch()stdscr 上运行,所以这就是你的问题。将该调用替换为

wgetch(win);

(getch() 会导致 stdscr 被转储到另一个窗口的顶部,并且由于这种情况发生得太快,看起来其他窗口从未得到过完全显示)。

You are not supposed to mix operations on stdscr and windows created with newwin(). getch() operates on stdscr, so that is your problem. Replace that call with

wgetch(win);

(getch() is causing stdscr 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).

时光礼记 2024-10-02 15:03:21

这就是按设计工作的。这允许您完全重绘下一个屏幕,但只有实际更改的部分才会在刷新时发送到终端。如今,这并不是什么大问题,但当终端连接相对较慢时,就会产生很大的影响。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文