Reputation: 73
I'm currently creating a program using the ncurses library, but have ran into a problem while starting to implement colors.
When I use the start_color() functions from ncurses, the default text color becomes a grey (close to #CCC) rather than the regular white.
Code I'm using to compare:
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
/* Converts a str to a string of chtype. */
chtype* str_to_chtype(char* str) {
int i;
chtype* chstr;
chstr = malloc(sizeof(chtype) * (strlen(str)+1));
for(i = 0; *str; ++str, ++i) {
chstr[i] = (chtype) *str;
}
chstr[i] = 0;
return chstr;
}
int main() {
/* Without color */
initscr();
addchstr(str_to_chtype("Testing"));
getch();
endwin();
/* With color */
initscr();
start_color();
addchstr(str_to_chtype("Testing"));
getch();
endwin();
return 0;
}
Images:
Any ideas as to why this would be happening/how to fix it?
Upvotes: 2
Views: 1268
Reputation: 54465
That's an FAQ (see Ncurses resets my colors to white/black). What is happening is that the 8 ANSI colors which define white and black do not necessarily match your default terminal foreground and background colors. Generally those are chosen to be more intense. So ANSI white looks like a light gray. (On some terminals, ANSI black turns out to be a different shade of gray).
This issue occurs whether your terminal has 8, 16, 88, 256 colors, since all of terminals which you will encounter for larger numbers of colors follow aixterm (16) or xterm (88, 256), which use the same first set of 8 ANSI colors (black is number 0, white is number 7).
As noted, use_default_colors is an extension (not part of X/Open curses) provided to work around this problem.
Upvotes: 3