0
關於如何在ncurses中滾動有很多問題,但我沒有找到任何明確的答案。所以,這是我的情況。我有兩個分割屏幕兩部分的對象,如分屏。現在我正在實現我的應用程序的一部分,就像文件管理器一樣。第一個窗口包含文件名,第二個窗口包含當前目錄中文件的擴展名。我想讓它滾動,我知道,我可以用墊片實現它。唯一的線索,我能找到的是this。這是我的嘗試使用這種方法:如何使用ncurses實現滾動?
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;
}
}
問題是,代碼的最後一部分根本不起作用。