|
发表于 2008-4-18 13:36:04
|
显示全部楼层
#include <curses.h>
int main()
{
initscr();
// start_color();
cbreak();
noecho();
keypad(stdscr, TRUE);
WINDOW *win1,*win2;
win1 = newwin(10,10,0,0);
win2 = newwin(5,10,0,13);
scrollok(win1, TRUE);
scrollok(win2, TRUE);
keypad(win2, TRUE);
// wsetscrreg(win1, 2, 5);
// idlok(win1,TRUE);
box(win1,0,0);
box(win2,0,0);
refresh();
wrefresh(win1);
wrefresh(win2);
long cur = 0;
long tmp_cur = 0;
int win1_h = 10;
int win2_h = 5;
int x,y;
int old_y = 0;
long win_row = 0;
int ch = 0;
while(ch = wgetch(win2)){
getyx(win1,y,x);
if(old_y < y){
++win_row;
}
switch(ch){
case 'q':
goto end;
case KEY_UP:
if( cur > 0){
--cur;
copywin(win1, win2, cur, 0,0,0,4,9, FALSE);
}
break;
case KEY_DOWN:
if( cur < (win_row+1) - win2_h){
++cur;
copywin(win1, win2, cur, 0,0,0,4,9, FALSE);
}
break;
default:
if(win_row+1 > win2_h)
cur = (win_row+1) - win2_h;
//copywin(win1, win2, cur, 0,0,0,4,9, FALSE);
waddch(win1, ch);
waddch(win2, ch);
}
old_y = y;
//waddch(win2, ch);
//waddch(win1, ch);
//wrefresh(win1);
}
wrefresh(win2);
//getch();
end:
endwin();
} |
|