Use black instead of grey with ncurses colors on Gnome Terminal Ubuntu Gnome 14.04

546 views Asked by At

If I use the use_default_colors() function, when I start_color() the background color of the terminal is not grey anymore, but black (The same I set in profile preferences), this is what I want because I don't like the grey. The problem is when I print something with color, the background color of the char I print is still the same grey. It is not noticeable if I don't use the use_default_colors() function, because everything is grey. But you can see it clearly if I use it. See screens

Is there a way to remove this grey and have it black, having a portable code? I want other people to see the same colors i set. For this reason I shouldn't be using use_default_colors() anyway, or maybe I can use it and change manually the background color with bkgd(); but I have the same problem. COLOR_BLACK is not actually black.

With use_default_colors()
Without default colors

#include <curses.h>

int main (){
    int maxx,maxy;
    char test = '*';
    char test2 = '#';

    initscr();
    noecho();
    curs_set(0);

    start_color();
    //use_default_colors();

    init_pair(1, COLOR_RED, COLOR_BLACK);
    init_pair(2, COLOR_CYAN, COLOR_BLACK);

    getmaxyx(stdscr,maxy,maxx);

    do{
        attron(COLOR_PAIR(1));
        mvaddch(10,10,test);
        attroff(COLOR_PAIR(1));

        attron(COLOR_PAIR(2));
        mvaddch(10,12,test2);
        attroff(COLOR_PAIR(2));

    }while(getch() != 'q');

    endwin();
    return;
}
1

There are 1 answers

3
William McBrine On

After invoking use_default_colors(), use -1 in init_pair() to get the background color of the cells to match the default, instead of COLOR_BLACK:

init_pair(1, COLOR_RED, -1);
init_pair(2, COLOR_CYAN, -1);

On the other hand, if you want COLOR_BLACK to be really black, you could try redefining it via init_color():

init_color(COLOR_BLACK, 0, 0, 0);

This isn't supported by all terminals, but should give pretty similar results where it is.