The following code should be self-explanatory if compiled (when
USE_STANDOUT is defined) and run. In my case, the OS is Linux
using ncurses 1.9.9e, with TERM=linux and the terminfo capabilities
for such as provided in that ncurses package:
/*
Attempt to understand why ncurses 1.9.9e exhibits a problem with
downward scrolling when color is also involved.
- The problem is apparent when the cursor is placed on line 16 (shown
initially with a bright red attribute) and then moved to line 17.
At this point, the A_STANDOUT attribute that should be applied when
on the cursor line is not set. The problem is not evident when the
cursor is moved from line 18 to 17 and then to line 16.
- The problem is not evident if an explicit color pair attribute is
set instead of using A_STANDOUT.
*/
#include <stdio.h>
#include <ncurses.h>
static void update_display(int curs_line)
{
int i, n, attr;
char *curs_line_str;
for(i = 0; i < LINES; i++) {
curs_line_str = "";
if(i != curs_line && i == 15) {
attr = COLOR_PAIR(1)|A_BOLD;
}
else if(i == curs_line) {
#ifdef USE_STANDOUT
attr = A_STANDOUT;
#else
attr = COLOR_PAIR(2);
#endif
curs_line_str = " cursor";
}
else {
attr = A_BOLD;
}
move(i, 0);
attron(attr);
printw(" Current%s line number: %d (Attr: %d)%n",
curs_line_str, i + 1, attr, &n);
printw("%*s", COLS - n, "");
attroff(attr);
}
refresh();
static void handle_keys(void)Quote:}
{
int key = 0, curs_line = 0;
do {
switch(key) {
case 0:
break;
case 'j':
case KEY_DOWN:
if(curs_line < LINES - 1)
curs_line++;
else
goto fetch;
break;
case 'k':
case KEY_UP:
if(curs_line > 0)
curs_line--;
else
goto fetch;
break;
default:
goto fetch;
}
update_display(curs_line);
fetch:
} while((key = getch()) != 'q' && key != 'Q');
int main(void)Quote:}
{
initscr();
nonl();
noecho();
cbreak();
curs_set(0);
keypad(stdscr, TRUE);
leaveok(stdscr, TRUE);
if(has_colors()) {
start_color();
init_pair(1, COLOR_RED, COLOR_BLACK);
#ifndef USE_STANDOUT
init_pair(2, COLOR_BLUE, COLOR_WHITE);
#endif
}
handle_keys();
endwin();
return 0;
--Quote:}
===========================================================================
linux for fun, M$ for $$$...and the NFL for what really counts!
===========================================================================