Question

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?

Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top