[英]How to implement a scrolling using ncurses?
There are many questions about how to make a scrolling in ncurses, but I didn't found any clear answer on them. 关于如何使ncurses滚动有很多问题,但是我没有找到明确的答案。 So, here is my case.
所以,这是我的情况。 I have two WINDOW* objects that bisects the screen on two parts, like a split-screen.
我有两个WINDOW *对象,它们将屏幕分为两部分,例如拆分屏幕。 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 .
我想使其可滚动,并且我知道可以使用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.
我忘记了keyboard()函数。 For those, who trying to make a scrolling in ncurses, this is the right solution.
对于那些试图在ncurses中滚动的人来说,这是正确的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.