Curses: simplify color handling

The map frame (background) colors were all over the place; the
code should be much cleaner now, and still work exactly the same
as before.

I tested this with terminals with 8, 16, and 256 COLORS.
This commit is contained in:
Pasi Kallinen
2024-03-15 20:36:56 +02:00
parent 96a74ccfbf
commit 243f6410d2
3 changed files with 47 additions and 81 deletions
+29 -55
View File
@@ -301,66 +301,40 @@ curses_create_main_windows(void)
void
curses_init_nhcolors(void)
{
if (has_colors()) {
use_default_colors();
init_pair(1, COLOR_BLACK, -1);
init_pair(2, COLOR_RED, -1);
init_pair(3, COLOR_GREEN, -1);
init_pair(4, COLOR_YELLOW, -1);
init_pair(5, COLOR_BLUE, -1);
init_pair(6, COLOR_MAGENTA, -1);
init_pair(7, COLOR_CYAN, -1);
init_pair(8, COLOR_WHITE, -1);
/* COLOR_foo + 8 means COLOR | A_BOLD when COLORS < 16 */
/* otherwise assume the terminal has least 16 different colors */
/* these map to the NetHack CLR_ defines */
static const int fg_clr[16] = {
COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW,
COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE,
-1, COLOR_RED + 8, COLOR_GREEN + 8, COLOR_YELLOW + 8,
COLOR_BLUE + 8, COLOR_MAGENTA + 8, COLOR_CYAN + 8, COLOR_WHITE + 8
};
static const int bg_clr[8] = {
-1, COLOR_RED, COLOR_GREEN, COLOR_YELLOW,
COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE
};
int bg, nhclr;
int maxc = (COLORS >= 16) ? 16 : 8;
{
int i;
boolean hicolor = FALSE;
if (!has_colors())
return;
static const int clr_remap[16] = {
COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW,
COLOR_BLUE,
COLOR_MAGENTA, COLOR_CYAN, -1, COLOR_WHITE,
COLOR_RED + 8, COLOR_GREEN + 8, COLOR_YELLOW + 8,
COLOR_BLUE + 8,
COLOR_MAGENTA + 8, COLOR_CYAN + 8, COLOR_WHITE + 8
};
use_default_colors();
for (i = 0; i < (COLORS >= 16 ? 16 : 8); i++) {
init_pair(17 + (i * 2) + 0, clr_remap[i], COLOR_RED);
init_pair(17 + (i * 2) + 1, clr_remap[i], COLOR_BLUE);
}
if (COLORS >= 16)
hicolor = TRUE;
/* Work around the crazy definitions above for more background
colors... */
for (i = 0; i < (COLORS >= 16 ? 16 : 8); i++) {
init_pair((hicolor ? 49 : 9) + i, clr_remap[i], COLOR_GREEN);
init_pair((hicolor ? 65 : 33) + i, clr_remap[i], COLOR_YELLOW);
init_pair((hicolor ? 81 : 41) + i, clr_remap[i], COLOR_MAGENTA);
init_pair((hicolor ? 97 : 49) + i, clr_remap[i], COLOR_CYAN);
init_pair((hicolor ? 113 : 57) + i, clr_remap[i], COLOR_WHITE);
}
}
if (COLORS >= 16) {
# ifdef USE_DARKGRAY
if (iflags.wc2_darkgray) {
init_pair(1, COLOR_BLACK + 8, -1);
}
# endif
init_pair(9, -1, -1);
init_pair(10, COLOR_RED + 8, -1);
init_pair(11, COLOR_GREEN + 8, -1);
init_pair(12, COLOR_YELLOW + 8, -1);
init_pair(13, COLOR_BLUE + 8, -1);
init_pair(14, COLOR_MAGENTA + 8, -1);
init_pair(15, COLOR_CYAN + 8, -1);
init_pair(16, COLOR_WHITE + 8, -1);
for (nhclr = CLR_BLACK; nhclr < maxc; nhclr++) {
for (bg = 0; bg < 8; bg++) {
init_pair((maxc * bg) + nhclr + 1, fg_clr[nhclr], bg_clr[bg]);
}
}
#ifdef USE_DARKGRAY
if (COLORS >= 16) {
if (iflags.wc2_darkgray) {
init_pair(CLR_BLACK + 1, COLOR_BLACK + 8, -1);
}
}
#endif
}
#if 0 /* curses_choose_character + curses_character_dialog no longer used */