Curses: add support for the palette config option

Depends on CHANGE_COLOR compile-time option.

Also allow multiple palette-definitions in the config file.
This commit is contained in:
Pasi Kallinen
2024-04-13 12:01:40 +03:00
parent ebd200ecc2
commit a57d0e6f4f
8 changed files with 48 additions and 11 deletions

View File

@@ -2080,6 +2080,8 @@ curses: if user's terminal was set to 'application keypad mode' (DEC VTxxx
"ESC SPC G"), nethack wasn't recognizing number pad keys
curses: change petattr attributes, dropping support for curses-only ones
curses: swap the grey and no-color color initialization
curses: allow changing default colors with the 'palette' config option
(only if compiled with CHANGE_COLOR)
macOS: Xcode project was failing to build if the path to the NetHack source
tree contained a space; the issue was within some shell script code
contained within the project

View File

@@ -327,6 +327,7 @@ extern boolean onlyhexdigits(const char *buf);
extern uint32 get_nhcolor_from_256_index(int idx);
#ifdef CHANGE_COLOR
extern int count_alt_palette(void);
extern int alternative_palette(char *);
extern void change_palette(void);
#endif

View File

@@ -536,11 +536,11 @@ static int optfn_##a(int, int, boolean, char *, char *);
#ifdef CHANGE_COLOR
#ifndef MAC /* not old Mac OS9 */
NHOPTC(palette, Advanced, 15, opt_in, set_gameview,
No, Yes, No, No, "hicolor",
No, Yes, Yes, No, "hicolor",
"palette (adjust an RGB color in palette (color/R-G-B)")
#else
NHOPTC(palette, Advanced, 15, opt_in, set_in_game,
No, Yes, No, No, "hicolor",
No, Yes, Yes, No, "hicolor",
"palette (00c/880/-fff is blue/yellow/reverse white)")
#endif
#endif

View File

@@ -790,7 +790,7 @@ hup_cliparound(int x UNUSED, int y UNUSED)
#ifdef CHANGE_COLOR
/*ARGSUSED*/
staticfn void
hup_change_color(int color, long rgb, int reverse)
hup_change_color(int color UNUSED, long rgb UNUSED, int reverse UNUSED)
{
return;
}
@@ -798,7 +798,7 @@ hup_change_color(int color, long rgb, int reverse)
#ifdef MAC
/*ARGSUSED*/
staticfn short
hup_set_font_name(winid window, char *fontname)
hup_set_font_name(winid window UNUSED, char *fontname UNUSED)
{
return 0;
}

View File

@@ -141,6 +141,7 @@ NHCFLAGS+=-DCOMPRESS=\"/bin/gzip\" -DCOMPRESS_EXTENSION=\".gz\"
#NHCFLAGS+=-DTTY_SOUND_ESCCODES
#NHCFLAGS+=-DNO_CHRONICLE
#NHCFLAGS+=-DLIVELOG
#NHCFLAGS+=-DCHANGE_COLOR
NHCFLAGS+=-DSELF_RECOVER
ifdef WANT_WIN_CURSES
ifeq "$(HAVE_NCURSESW)" "1"

View File

@@ -44,8 +44,8 @@ extern glyph_info mesg_gi;
static void dummy_update_position_bar(char *);
#endif
#ifdef CHANGE_COLOR
static void dummy_change_color(int, long, int);
static char *dummy_get_color_string(void);
static void curses_change_color(int, long, int);
static char *curses_get_color_string(void);
#endif
/* Public functions for curses NetHack interface */
@@ -119,12 +119,12 @@ struct window_procs curses_procs = {
curses_number_pad,
curses_delay_output,
#ifdef CHANGE_COLOR
dummy_change_color,
curses_change_color,
#ifdef MAC /* old OS 9, not OSX */
(void (*)(int)) 0,
(short (*)(winid, char *)) 0,
#endif
dummy_get_color_string,
curses_get_color_string,
#endif
curses_start_screen,
curses_end_screen,
@@ -1278,13 +1278,21 @@ dummy_update_position_bar(char *arg UNUSED)
#ifdef CHANGE_COLOR
static void
dummy_change_color(int a1 UNUSED, long a2 UNUSED, int a3 UNUSED)
curses_change_color(int color, long rgb, int reverse UNUSED)
{
return;
short r, g, b;
if (!can_change_color())
return;
r = (rgb >> 16) & 0xFF;
g = (rgb >> 8) & 0xFF;
b = rgb & 0xFF;
init_color(color % 16, r * 4, g * 4, b * 4);
}
static char *
dummy_get_color_string(void)
curses_get_color_string(void)
{
return (char *) 0;
}

View File

@@ -1495,6 +1495,15 @@ term_curs_set(int visibility)
xputs(nh_VE);
}
#ifdef CHANGE_COLOR
void
tty_change_color(int color UNUSED, long rgb UNUSED, int reverse UNUSED)
{
return;
}
#endif /* CHANGE_COLOR */
#ifndef SEP2
#define tcfmtstr "\033[38;2;%ld;%ld;%ldm"
#ifdef UNIX

View File

@@ -803,6 +803,14 @@ tty_resume_nhwindows(void)
docrt();
}
#ifdef CHANGE_COLOR
char *
tty_get_color_string(void)
{
return (char *) 0;
}
#endif /* CHANGE_COLOR */
void
tty_exit_nhwindows(const char *str)
{
@@ -3941,6 +3949,14 @@ term_curs_set(int visibility UNUSED)
/* nothing */
}
#ifdef CHANGE_COLOR
void
tty_change_color(int color UNUSED, long rgb UNUSED, int reverse UNUSED)
{
/* nothing */
}
#endif /* CHANGE_COLOR */
#endif /* NO_TERMS */
void