diff --git a/win/curses/cursinit.c b/win/curses/cursinit.c index 1135d0eb8..523ae92d3 100644 --- a/win/curses/cursinit.c +++ b/win/curses/cursinit.c @@ -7,6 +7,7 @@ #include "hack.h" #include "wincurs.h" #include "cursinit.h" +#include "cursmisc.h" /* Initialization and startup functions for curses interface */ @@ -334,18 +335,18 @@ curses_init_nhcolors(void) /* 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] = { + static const int basic_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] = { + static const int bg_clr[CURSES_NUM_BACKGROUND_COLORS] = { -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 maxc = curses_has_256color() ? 256 : (COLORS >= 16) ? 16 : 8; if (!has_colors()) return; @@ -353,8 +354,9 @@ curses_init_nhcolors(void) use_default_colors(); 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]); + for (bg = 0; bg < CURSES_NUM_BACKGROUND_COLORS; bg++) { + int fg_color = (nhclr < 16) ? basic_fg_clr[nhclr] : nhclr; + init_pair((maxc * bg) + nhclr + 1, fg_color, bg_clr[bg]); } } diff --git a/win/curses/cursmisc.c b/win/curses/cursmisc.c index efa5da83a..30e782411 100644 --- a/win/curses/cursmisc.c +++ b/win/curses/cursmisc.c @@ -91,6 +91,12 @@ curses_read_char(void) return ch; } +boolean +curses_has_256color(void) +{ + return (COLORS >= 256) && (COLOR_PAIRS >= 256 * CURSES_NUM_BACKGROUND_COLORS); +} + /* Turn on or off the specified color and / or attribute */ void @@ -147,7 +153,7 @@ curses_toggle_color_attr(WINDOW *win, int color, int attr, int onoff) if (use_bold) { wattron(win, A_BOLD); } - wattron(win, COLOR_PAIR(curses_color)); + wcolor_set(win, curses_color, &curses_color); } if (attr != NONE) { diff --git a/win/curses/cursmisc.h b/win/curses/cursmisc.h index dc79ebfbe..81c34135d 100644 --- a/win/curses/cursmisc.h +++ b/win/curses/cursmisc.h @@ -8,8 +8,11 @@ /* Global declarations */ +#define CURSES_NUM_BACKGROUND_COLORS 8 + int curses_getch(void); int curses_read_char(void); +boolean curses_has_256color(void); void curses_toggle_color_attr(WINDOW *win, int color, int attr, int onoff); void curses_menu_color_attr(WINDOW *win, int color, int attr, int onoff); void curses_bail(const char *mesg); diff --git a/win/curses/curswins.c b/win/curses/curswins.c index 6ce123c34..a09b3f3f0 100644 --- a/win/curses/curswins.c +++ b/win/curses/curswins.c @@ -769,7 +769,11 @@ static int get_framecolor(int nhcolor, int framecolor) { /* curses_toggle_color_attr() adds the +1 and takes care of COLORS < 16 */ - return (16 * (framecolor % 8)) + (nhcolor % 16); + if (curses_has_256color()) { + return (256 * (framecolor % 8)) + (nhcolor % 256); + } else + return (16 * (framecolor % 8)) + (nhcolor % 16); + } static void