There are many questions about how to make a scrolling in ncurses, but I didn't found any clear answer on them. So, here is my case. I have two WINDOW* objects that bisects the screen on two parts, like a split-screen. Now I'm implementing the part of my app which is like a file manager. The first window holds a files names and the second window holds the extensions of the files in current directory. I want to make it scrollable and I know, that I can achieve it with pads . The only clue, I could find is this . Here's my try using this approach:
WINDOW *win1, *win2;
int maxx, maxy, halfx;
getmaxyx(stdscr, maxy, maxx);
halfx = maxx >> 1;
win1 = newpad(maxy, halfx);
wprintw(win1, "File name: \n");
wrefresh(win1);
//don't pay much attention on this part of
//code, now it's just a window, then it will be pad too
win2 = newwin(maxy, halfx, 0, halfx);
wprintw(win2, "Extension: \n");
wrefresh(win2);
curs_set(0);//cursor off
int rowcount = 0;
//filling the windows with file data
for(directory_iterator beg(dir); beg != directory_iterator{}; ++beg)
{
wprintw(win1, "%s\n", beg->path().stem().string().c_str());
wrefresh(win1);
wprintw(win2, "%s\n", beg->path().extension().string().c_str());
wrefresh(win2);
rowcount++;
}
//##############################
keypad(win1, TRUE);//SOLUTION
//##############################
int mypadpos = 0;
prefresh(win1, mypadpos, 0, 0, 0, maxy, maxx);
//spaghetti-code from the above question that I tried to adapt
while ((ch = wgetch(win1)) != 'q')
{
switch (ch)
{
case KEY_UP:
if (mypadpos >= 0)
mypadpos--;
prefresh(win1, mypadpos, 0, 0, 0, maxy, maxx);
break;
case KEY_DOWN:
if (mypadpos <= rowcount+1)
mypadpos++;
prefresh(win1, mypadpos, 0, 0, 0, maxy-1, maxx);
break;
}
}
The problem is that the last part of code doesn't work at all.
Ah, the answer is easy. I forgot about the keypad() function. For those, who trying to make a scrolling in ncurses, this is the right solution.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.