From: Pasi Kallinen Date: Sun, 29 Mar 2015 12:49:01 +0000 (+0300) Subject: Use dark gray color for black glyphs in TTY X-Git-Tag: NetHack-3.6.0_RC01~518 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1e49567937fba71b7272c955595dcd513b7e9788;p=nethack Use dark gray color for black glyphs in TTY This is Michael Deutschmann's use_darkgray -patch. Adds a boolean option use_darkgray, settable in config file. This patch has been in use on NAO for years, and I have heard once someone say their terminal didn't support the dark gray color. --- diff --git a/dat/opthelp b/dat/opthelp index 836e33d87..ce1d743cc 100644 --- a/dat/opthelp +++ b/dat/opthelp @@ -45,6 +45,7 @@ tombstone print tombstone when you die [TRUE] toptenwin print topten in a window rather than stdout [FALSE] travel enable the command to travel to a map location via [TRUE] a shortest-path algorithm, usually invoked by '_'. +use_darkgray use bold black instead of blue for black glyphs. [TRUE] use_inverse display detected monsters in highlighted manner [FALSE] verbose print more commentary during the game [TRUE] diff --git a/doc/Guidebook.mn b/doc/Guidebook.mn index eb340dff5..496d588de 100644 --- a/doc/Guidebook.mn +++ b/doc/Guidebook.mn @@ -2453,6 +2453,8 @@ Specify the name of an alternative tile file to override the default. Specify the preferred height of each tile in a tile capable port. .lp tile_width Specify the preferred width of each tile in a tile capable port +.lp use_darkgray +Use bold black instead of blue for black glyphs (TTY only). .lp use_inverse NetHack should display inverse when the game specifies it. .lp vary_msgcount diff --git a/doc/Guidebook.tex b/doc/Guidebook.tex index 79e39c599..6c3ccbded 100644 --- a/doc/Guidebook.tex +++ b/doc/Guidebook.tex @@ -2964,6 +2964,9 @@ Specify the preferred height of each tile in a tile capable port. \item[\ib{tile\_width}] Specify the preferred width of each tile in a tile capable port %.lp +\item[\ib{use\_darkgray}] +Use bold black instead of blue for black glyphs (TTY only). +%.lp \item[\ib{use\_inverse}] NetHack should display inverse when the game specifies it. %.lp diff --git a/doc/fixes35.0 b/doc/fixes35.0 index 53fac6b5c..0d7fb3cde 100644 --- a/doc/fixes35.0 +++ b/doc/fixes35.0 @@ -1143,6 +1143,7 @@ adopt/adapt/improve the Paranoid_Quit patch; default is paranoid_confirm:pray paranoid_confirm:Remove always pick from inventory for 'R' and 'T' adopt/adapt/improve Dungeon Overview Aardvark Joe's Extended Logfile +Michael Deutschmann's use_darkgray Code Cleanup and Reorganization diff --git a/include/flag.h b/include/flag.h index e7ebafa26..9eb7a68c6 100644 --- a/include/flag.h +++ b/include/flag.h @@ -295,6 +295,7 @@ struct instance_flags { boolean wc2_softkeyboard; /* use software keyboard */ boolean wc2_wraptext; /* wrap text */ boolean wc2_selectsaved; /* display a menu of user's saved games */ + boolean wc2_darkgray; /* try to use dark-gray color for black glyphs */ boolean cmdassist; /* provide detailed assistance for some commands */ boolean clicklook; /* allow right-clicking for look */ boolean obsolete; /* obsolete options can point at this, it isn't used */ diff --git a/include/winprocs.h b/include/winprocs.h index 72dad2315..398ba9cba 100644 --- a/include/winprocs.h +++ b/include/winprocs.h @@ -219,7 +219,8 @@ NEARDATA struct window_procs windowprocs; #define WC2_WRAPTEXT 0x04L /* 03 wrap long lines of text */ #define WC2_HILITE_STATUS 0x08L /* 04 hilite fields in status */ #define WC2_SELECTSAVED 0x10L /* 05 saved game selection menu */ - /* 27 free bits */ +#define WC2_DARKGRAY 0x20L /* 06 use bold black for black glyphs */ + /* 26 free bits */ #define ALIGN_LEFT 1 #define ALIGN_RIGHT 2 diff --git a/src/options.c b/src/options.c index 285603351..e1ff15ff0 100644 --- a/src/options.c +++ b/src/options.c @@ -201,6 +201,7 @@ static struct Bool_Opt {"tombstone",&flags.tombstone, TRUE, SET_IN_GAME}, {"toptenwin",&iflags.toptenwin, FALSE, SET_IN_GAME}, {"travel", &flags.travelcmd, TRUE, SET_IN_GAME}, + {"use_darkgray", &iflags.wc2_darkgray, TRUE, SET_IN_FILE}, #ifdef WIN32CON {"use_inverse", &iflags.wc_inverse, TRUE, SET_IN_GAME}, /*WC*/ #else @@ -4398,6 +4399,7 @@ struct wc_Opt wc2_options[] = { {"fullscreen", WC2_FULLSCREEN}, {"softkeyboard", WC2_SOFTKEYBOARD}, {"wraptext", WC2_WRAPTEXT}, + {"use_darkgray", WC2_DARKGRAY}, #ifdef STATUS_VIA_WINDOWPORT {"hilite_status", WC2_HILITE_STATUS}, #endif diff --git a/win/tty/termcap.c b/win/tty/termcap.c index b06a9abfe..1455bf21a 100644 --- a/win/tty/termcap.c +++ b/win/tty/termcap.c @@ -809,10 +809,9 @@ cl_eos() /* free after Robert Viduya */ extern char *tparm(); #endif -# ifdef COLOR_BLACK /* trust include file */ -#undef COLOR_BLACK -# else +# ifndef COLOR_BLACK /* trust include file */ # ifndef _M_UNIX /* guess BGR */ +#define COLOR_BLACK 0 #define COLOR_BLUE 1 #define COLOR_GREEN 2 #define COLOR_CYAN 3 @@ -821,6 +820,7 @@ extern char *tparm(); #define COLOR_YELLOW 6 #define COLOR_WHITE 7 # else /* guess RGB */ +#define COLOR_BLACK 0 #define COLOR_RED 1 #define COLOR_GREEN 2 #define COLOR_YELLOW 3 @@ -830,43 +830,125 @@ extern char *tparm(); #define COLOR_WHITE 7 # endif # endif -#define COLOR_BLACK COLOR_BLUE -const int ti_map[8] = { - COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, - COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE }; +/* Mapping data for the six terminfo colors that resolve to pairs of nethack + * colors. Black and white are handled specially. + */ +const struct {int ti_color, nh_color, nh_bright_color;} ti_map[6] = +{ + {COLOR_RED,CLR_RED,CLR_ORANGE}, + {COLOR_GREEN,CLR_GREEN,CLR_BRIGHT_GREEN}, + {COLOR_YELLOW,CLR_BROWN,CLR_YELLOW}, + {COLOR_BLUE,CLR_BLUE,CLR_BRIGHT_BLUE}, + {COLOR_MAGENTA,CLR_MAGENTA,CLR_BRIGHT_MAGENTA}, + {COLOR_CYAN,CLR_CYAN,CLR_BRIGHT_CYAN} +}; + static void init_hilite() { register int c; char *setf, *scratch; - - for (c = 0; c < SIZE(hilites); c++) - hilites[c] = nh_HI; - hilites[CLR_GRAY] = hilites[NO_COLOR] = (char *)0; + int md_len; if (tgetnum("Co") < 8 || (MD == NULL) || (strlen(MD) == 0) || ((setf = tgetstr("AF", (char **)0)) == (char *)0 && (setf = tgetstr("Sf", (char **)0)) == (char *)0)) + { + /* Fallback when colors not available + * It's arbitrary to collapse all colors except gray + * together, but that's what the previous code did. + */ + hilites[CLR_BLACK] = nh_HI; + hilites[CLR_RED] = nh_HI; + hilites[CLR_GREEN] = nh_HI; + hilites[CLR_BROWN] = nh_HI; + hilites[CLR_BLUE] = nh_HI; + hilites[CLR_MAGENTA] = nh_HI; + hilites[CLR_CYAN] = nh_HI; + hilites[CLR_GRAY] = ""; + hilites[NO_COLOR] = ""; + hilites[CLR_ORANGE] = nh_HI; + hilites[CLR_BRIGHT_GREEN] = nh_HI; + hilites[CLR_YELLOW] = nh_HI; + hilites[CLR_BRIGHT_BLUE] = nh_HI; + hilites[CLR_BRIGHT_MAGENTA] = nh_HI; + hilites[CLR_BRIGHT_CYAN] = nh_HI; + hilites[CLR_WHITE] = nh_HI; return; - - for (c = 0; c < CLR_MAX / 2; c++) { - scratch = tparm(setf, ti_map[c]); - if (c != CLR_GRAY) { - hilites[c] = (char *) alloc(strlen(scratch) + 1); - Strcpy(hilites[c], scratch); - } - if (c != CLR_BLACK) { - hilites[c|BRIGHT] = (char*) alloc(strlen(scratch)+strlen(MD)+1); - Strcpy(hilites[c|BRIGHT], MD); - Strcat(hilites[c|BRIGHT], scratch); } + md_len = strlen(MD); + + c = 6; + while (c--) { + char *work; + scratch = tparm(setf,ti_map[c].ti_color); + work = (char *) alloc(strlen(scratch) + md_len + 1); + Strcpy(work,MD); + hilites[ti_map[c].nh_bright_color] = work; + work += md_len; + Strcpy(work,scratch); + hilites[ti_map[c].nh_color] = work; } + + scratch = tparm(setf,COLOR_WHITE); + hilites[CLR_WHITE] = (char *) alloc(strlen(scratch) + md_len + 1); + Strcpy(hilites[CLR_WHITE],MD); + Strcat(hilites[CLR_WHITE],scratch); + + hilites[CLR_GRAY] = ""; + hilites[NO_COLOR] = ""; + + if (iflags.wc2_darkgray) { + /* On many terminals, esp. those using classic PC CGA/EGA/VGA + * textmode, specifying "hilight" and "black" simultaneously + * produces a dark shade of gray that is visible against a + * black background. We can use it to represent black objects. + */ + scratch = tparm(setf,COLOR_BLACK); + hilites[CLR_BLACK] = (char *) alloc(strlen(scratch) + md_len + 1); + Strcpy(hilites[CLR_BLACK],MD); + Strcat(hilites[CLR_BLACK],scratch); + } else { + /* But it's concievable that hilighted black-on-black could + * still be invisible on many others. We substitute blue for + * black. + */ + hilites[CLR_BLACK] = hilites[CLR_BLUE]; + } +} + +static void +kill_hilite() +{ + /* if colors weren't available, no freeing needed */ + if (hilites[CLR_BLACK] == nh_HI) + return; + + if (hilites[CLR_BLACK] != hilites[CLR_BLUE]) + free(hilites[CLR_BLACK]); + + /* CLR_BLUE overlaps CLR_BRIGHT_BLUE, do not free */ + /* CLR_GREEN overlaps CLR_BRIGHT_GREEN, do not free */ + /* CLR_CYAN overlaps CLR_BRIGHT_CYAN, do not free */ + /* CLR_RED overlaps CLR_ORANGE, do not free */ + /* CLR_MAGENTA overlaps CLR_BRIGHT_MAGENTA, do not free */ + /* CLR_BROWN overlaps CLR_YELLOW, do not free */ + /* CLR_GRAY is a constant "", do not free */ + /* NO_COLOR is a constant "", do not free */ + free(hilites[CLR_BRIGHT_BLUE]); + free(hilites[CLR_BRIGHT_GREEN]); + free(hilites[CLR_BRIGHT_CYAN]); + free(hilites[CLR_YELLOW]); + free(hilites[CLR_ORANGE]); + free(hilites[CLR_BRIGHT_MAGENTA]); + free(hilites[CLR_WHITE]); } + # else /* UNIX && TERMINFO */ # ifndef TOS @@ -1011,7 +1093,6 @@ init_hilite() # endif # endif /* TOS */ } -# endif /* UNIX */ static void kill_hilite() @@ -1029,6 +1110,7 @@ kill_hilite() # endif return; } +# endif /* UNIX */ #endif /* TEXTCOLOR */ diff --git a/win/tty/wintty.c b/win/tty/wintty.c index afe0e204e..bffce05d7 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -56,7 +56,7 @@ struct window_procs tty_procs = { #if defined(SELECTSAVED) WC2_SELECTSAVED| #endif - 0L, + WC2_DARKGRAY, tty_init_nhwindows, tty_player_selection, tty_askname,