Getch behaves as key is previous key.
I Wrote a little text-viewer for linux (using curses) this morning, but my problem is that it seems to belive that the key I feed getch() with was the previous key.
For now- I just have keys for scrolling upp and down
So - when I scroll down 10 lies, and then I scroll up 1 line - it scroll down one line more before it begins to scroll up. The same in the other direction.
please be kind to me, this is the first program I have written in 10 years - and i wa sn't even a good programmer back then.
Of course I have read a file to the strings and done proper errorchecking while
open the file etcetera....before I come here. I just moved the variable definations
from top of main for you to see the picture.
Code:
char rgsz[500+1][160+1]; //Array of strings which contains up to the 500 first
//Lines from the file.
int n_sz; //How many lines contains the array of strings.
int w_top=0, w_bot=LINES; //Window Top and Bottom.
int key; //For getch()
bool f_upd_w=TRUE; //Flag for Updating the Window
i=0;
while (key != 27 ) {
key=getch();
if (f_upd_w == TRUE){
for ( i=w_top; i<w_bot-1; i++ ){
if ( (i <= 0) || (i >= n_sz ) ){
break;
}
if (i < n_sz){
if (strlen (rgsz[ i ]) > COLS) { //Not yet implantated, needs
w_bot--; //more work
}
printw("%d, %d, %d, %s",i, w_top, w_bot, rgsz[ i ]);
}
f_upd_w=FALSE;
}
}
switch (key){
case KEY_DOWN:
if ( w_bot <= n_sz ){
w_top++;
w_bot++;
f_upd_w=TRUE;
}
break;
case KEY_UP:
w_top--;
w_bot--;
f_upd_w=TRUE;
break;
}
}