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

StackOverflow https://stackoverflow.com/questions/20860270

문제

I wish to print continous output into a ncurses window. When the bottom of the windows is reached, I would like to have all lines pushed 1 line up (possibly erasing or hiding the 1st line). Having the newest line show in the bottom. This is the behavior I normally expect from any terminal. The reason I need ncurses is that I need to print and get input simultaneously and with a normal terminal this is not well defined.

My current solution is to save all the lines inside a queue and simply re-print the n first lines in the queue. Is this how it is done or is there a way to do the same thing in the API?

도움이 되었습니까?

해결책

scroll(). You have to set scrollok(win, TRUE) first. Actually if you just want to spew data like a normal terminal you only need to set scrollok() by itself.

#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 terminal\n", i);

        refresh();
    }

    getch();

    endwin();
    return 0;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top