Issue
I have recently come across an issue, I can't figure out where it comes from. It appears to be related to an unexpected behavior of the ncurses library when attempting to apply the A_DIM
effect on colors other than the first 9 (they don't get dimmed). Furthermore, when initializing a color to one of the first 9 colors (such as init_color(2,0,100,843)
), the A_DIM
effect seems to result in the dimmed color of the predefined color:
A minimal reproducible example
#include <curses.h>
void draw_lines(int y, int c)
{
char ch = wgetch(stdscr);
init_pair(c, c, COLOR_BLACK);
mvhline(y ,0,'B', COLS);
mvhline(y+1 ,0,'B', COLS);
mvhline(y+2 ,0,'B', COLS);
mvchgat(y , 0, -1, A_BOLD , c, NULL);
mvchgat(y+1, 0, -1, A_NORMAL, c, NULL);
mvchgat(y+2, 0, -1, A_DIM , c, NULL);
}
int main()
{
initscr();
if (!has_colors()) return -1;
int i=0, j=0;
start_color ( );
cbreak ( );
noecho ( );
curs_set (0);
mouseinterval(0);
keypad(stdscr, TRUE);
refresh ( );
for (i=0; i<LINES; i+=3) {
draw_lines(i, j);
j += 1;
}
for (i=1; i<LINES/3; i++) {
init_color(i,0,100,843); // BLUE
draw_lines(i*3, i);
}
endwin();
return 0;
}
(I am using Alacritty and ncurses-6.4-1)
Question
Is this supposed to happen? and if yes, then how should I approch the initialization of colors, if I want to preserve the ability of the user to customize colors in my app but also keep things sane?
But Why
The reason I care so much is this, where my aproach goes something like this. Meaning that I use an offset so that the user can define custom colors for every individual tui-component, but also be able to have the same color-pattern for all of them if he\she wants so.
Outro
Any idea? Thanks in advance for any help.