TTY: add support for the palette config option

For now, terminal colors are not reset back when exiting NetHack.
Depends on CHANGE_COLOR compile-time option.
This commit is contained in:
Pasi Kallinen
2025-12-30 19:24:57 +02:00
parent 6707d3bfba
commit 0dac2b5fa0
2 changed files with 37 additions and 3 deletions

View File

@@ -2337,7 +2337,7 @@ 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+Qt: allow changing default colors with the 'palette' config option
curses+tty+Qt: allow changing default colors with the 'palette' config option
(only if compiled with CHANGE_COLOR)
curses: if messages have been issued during start-up (for instance, warnings
about issues in run-time config file), prompt user to press <return>

View File

@@ -39,6 +39,7 @@ struct tc_lcl_data tc_lcl_data = { 0, 0, 0, 0, 0, 0, 0, FALSE };
static char *nh_VI = (char *) 0; /* cursor_invisible */
static char *nh_VE = (char *) 0; /* cursor_normal */
/*static char *nh_VS = (char *) 0;*/ /* cursor_visible (highlighted cursor) */
static char *nh_Ic = (char *) 0; /* initialize_color */
static char *HO, *CL, *CE, *UP, *XD, *BC, *SO, *SE, *TI, *TE;
static char *VS, *VE;
@@ -290,6 +291,8 @@ term_startup(int *wid, int *hgt)
if (!nh_VI || !nh_VE /*|| !nh_VS*/ )
nh_VI = nh_VE = /*nh_VS =*/ (char *) 0;
nh_Ic = Tgetstr(nhStr("Ic"));
/* Get rid of padding numbers for nh_HI and nh_HE. Hope they
* aren't really needed!!! nh_HI and nh_HE are outputted to the
* pager as a string - so how can you send it NULs???
@@ -1508,9 +1511,40 @@ term_curs_set(int visibility)
#ifdef CHANGE_COLOR
void
tty_change_color(int color UNUSED, long rgb UNUSED, int reverse UNUSED)
tty_change_color(int color, long rgb, int reverse UNUSED)
{
return;
char buf[BUFSZ];
int i;
char *c, *fmt;
/* FIXME: colors are not reset back when exiting NetHack */
if (nh_Ic && *nh_Ic) {
long clr = color, r, g, b;
/* color * 3 seems to work correctly? */
/* this probably depends on the termcap definition */
r = ((rgb >> 16) & 0xFF) * 3;
g = ((rgb >> 8) & 0xFF) * 3;
b = (rgb & 0xFF) * 3;
fmt = tparm(nh_Ic, clr, r, g, b);
c = fmt;
i = 0;
while (*c) {
if (*c == '\033') {
buf[i++] = '\\';
buf[i++] = 'E';
} else {
buf[i++] = *c;
}
c++;
}
buf[i++] = '\0';
xputs(fmt);
}
}
#endif /* CHANGE_COLOR */