I have recently been introduced to ncurses
for asynchronous keyboard key listening, and getting on well with it. One issue i'm facing is that you can only have text on the visible screen, no scrollbars. I was wondering if its possible to keep using ncurses
as it is so lovely, but have the program still keep the scrollbars rather than getting to the last line and staying there.
Asked
Active
Viewed 1.0k times
4

topherg
- 4,203
- 4
- 37
- 72
-
1I assume you mean, making a GUI terminal program apply its own scroll-bars, by extending a curses display taller than the window? (Not, adding scroll-bars within the curses environment?) Don't have a chance to experiment right now, but can't you just adjust `extern int LINES` to the size you'd like…? (Of course, this would probably break your program on physical terminals, e.g. Linux text consoles) – BRPocock Dec 06 '11 at 21:21
-
@BRPocock No, the idea is not to add an element within the curses environment, but to make the program move onto a new line (beyond the range of the terminal window, forcing a scrollbar to appear – topherg Dec 06 '11 at 21:27
1 Answers
11
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)
{
int i = 0;
initscr();
scrollok(stdscr,TRUE);
while(1)
{
printw("%d - lots and lots of lines flowing down the terminal\n", i);
++i;
refresh();
}
endwin();
return 0;
}

Duck
- 26,924
- 5
- 64
- 92