如何在 ncurses 中模仿 TTY 行为?当我们到达底部时,向上推动屏幕上的所有线条

How to imitate TTY behavior in ncurses? Pushing all lines on screen upwards when we reach the bottom?

本文关键字:上推 屏幕 底部 ncurses TTY 我们 行为      更新时间:2023-10-16

我希望将连续的输出打印到ncurses窗口中。当到达窗口底部时,我希望将所有行向上推 1 行(可能擦除或隐藏第一行)。在底部显示最新的线条。这是我通常期望从任何终端获得的行为。我需要 ncurses 的原因是我需要同时打印和获取输入,而对于普通终端,这没有很好地定义。

我当前的解决方案是将所有行保存在队列中,然后简单地重新打印队列中的前 n 行。是这样完成的,还是有没有办法在 API 中做同样的事情?

scroll(). 您必须先设置 scrollok(win, TRUE)。 实际上,如果您只想像普通终端一样喷出数据,则只需自行设置 scrollok()。

#include <ncurses.h>
int main(void)
{
    initscr();
    scrollok(stdscr,TRUE);
    for (int i = 0; i < 100; ++i)
    {
        printw("%d - lots and lots of lines flowing down the terminaln", i);
        refresh();
    }
    getch();
    endwin();
    return 0;
}