1 diff -durpN nethack-3.4.3/README.gray nethack-gray/README.gray
2 --- nethack-3.4.3/README.gray 1969-12-31 16:00:00.000000000 -0800
3 +++ nethack-gray/README.gray 2003-12-09 18:37:21.000000000 -0800
5 +This copy of the nethack source includes a patch to allow black objects
6 +(orcish daggers, ravens, pits, etc.) to be represented using a dark shade
7 +of gray on some terminals. Normally, nethack shows them as blue to avoid
8 +printing unreadable black-on-black text, but this confuses them with with
9 +objects that are actually blue (cornuthaums, sapphires, soldier ants,
12 +The patch works by specifying "black foreground" and "boldface" at the
13 +same time. On terminals that simulate bold with brighter colors, this
14 +produces a distinct color. Terminal emulators based on PC CGA/EGA/VGA
15 +textmode generally have this property.
17 +However, on terminals that implement actual bolding -- thickening the
18 +font without changing the color, it will result in invisible text. So,
19 +the feature is not enabled by default. It must be activated with the new
20 +option "use_darkgray".
23 + * This patch is only effective in when TERMINFO is defined in unixconf.h
25 + * Highlights added by the existing "use_inverse" and/or "hilite_pet"
26 +options will probably not be visible when applied to black objects.
28 + * nethack doesn't properly follow the rules for using the tputs()
29 +function of termcap/curses. The first argument is supposed to be a string
30 +obtained from the termcap/terminfo functions. Nethack assumes it can
31 +provide a null pointer to do nothing, and can string-concatenate two codes
32 +(boldface and a color select) and use them as one.
33 + My code does not fix this -- although it uses "" instead of a null
34 +pointer, which is less likely to crash on a less permissive
35 +termcap/terminfo implementation.
37 + * I'm aware of a seperate patch to add darkgray support -- but it was
38 +unconditional at runtime, and had to change the color numbers in
39 +includes/color.h to work. My patch makes the TTY code independent of the
40 +actual value of the CLR_* defines.
42 + * I personally believe the correct spelling of the color involved is
43 +"grey", however I have adopted the popular misspelling "gray" throughout
44 +to be consistent with the rest of nethack. :)
46 +---- Michael Deutschmann <michael@talamasca.ocis.net>
47 diff -durpN nethack-3.4.3/include/flag.h nethack-gray/include/flag.h
48 --- nethack-3.4.3/include/flag.h 2003-12-07 15:39:13.000000000 -0800
49 +++ nethack-gray/include/flag.h 2003-12-09 18:37:21.000000000 -0800
50 @@ -263,6 +263,8 @@ struct instance_flags {
51 boolean wc2_fullscreen; /* run fullscreen */
52 boolean wc2_softkeyboard; /* use software keyboard */
53 boolean wc2_wraptext; /* wrap text */
54 + boolean wc2_darkgray; /* try to use PC dark-gray color
55 + * to represent black object */
57 boolean cmdassist; /* provide detailed assistance for some commands */
58 boolean obsolete; /* obsolete options can point at this, it isn't used */
59 diff -durpN nethack-3.4.3/include/winprocs.h nethack-gray/include/winprocs.h
60 --- nethack-3.4.3/include/winprocs.h 2003-12-07 15:39:13.000000000 -0800
61 +++ nethack-gray/include/winprocs.h 2003-12-09 18:37:21.000000000 -0800
62 @@ -176,8 +176,9 @@ extern NEARDATA struct window_procs wind
64 #define WC2_FULLSCREEN 0x01L /* 01 display full screen */
65 #define WC2_SOFTKEYBOARD 0x02L /* 02 software keyboard */
66 -#define WC2_WRAPTEXT 0x04L /* 04 wrap long lines of text */
68 +#define WC2_WRAPTEXT 0x04L /* 03 wrap long lines of text */
69 +#define WC2_DARKGRAY 0x08L /* 04 try to use "bright black" color */
74 diff -durpN nethack-3.4.3/src/options.c nethack-gray/src/options.c
75 --- nethack-3.4.3/src/options.c 2003-12-07 15:39:13.000000000 -0800
76 +++ nethack-gray/src/options.c 2003-12-09 18:37:21.000000000 -0800
77 @@ -188,6 +188,7 @@ static struct Bool_Opt
78 {"tombstone",&flags.tombstone, TRUE, SET_IN_GAME},
79 {"toptenwin",&flags.toptenwin, FALSE, SET_IN_GAME},
80 {"travel", &iflags.travelcmd, TRUE, SET_IN_GAME},
81 + {"use_darkgray", &iflags.wc2_darkgray, FALSE, SET_IN_FILE},
83 {"use_inverse", &iflags.wc_inverse, TRUE, SET_IN_GAME}, /*WC*/
85 @@ -3593,6 +3594,7 @@ struct wc_Opt wc2_options[] = {
86 {"fullscreen", WC2_FULLSCREEN},
87 {"softkeyboard", WC2_SOFTKEYBOARD},
88 {"wraptext", WC2_WRAPTEXT},
89 + {"use_darkgray", WC2_DARKGRAY},
93 diff -durpN nethack-3.4.3/win/tty/termcap.c nethack-gray/win/tty/termcap.c
94 --- nethack-3.4.3/win/tty/termcap.c 2003-12-07 15:39:14.000000000 -0800
95 +++ nethack-gray/win/tty/termcap.c 2003-12-09 18:37:21.000000000 -0800
96 @@ -839,10 +839,9 @@ cl_eos() /* free after Robert Viduya *
100 -# ifdef COLOR_BLACK /* trust include file */
103 +# ifndef COLOR_BLACK /* trust include file */
104 # ifndef _M_UNIX /* guess BGR */
105 +#define COLOR_BLACK 0
107 #define COLOR_GREEN 2
109 @@ -851,6 +850,7 @@ extern char *tparm();
110 #define COLOR_YELLOW 6
111 #define COLOR_WHITE 7
112 # else /* guess RGB */
113 +#define COLOR_BLACK 0
115 #define COLOR_GREEN 2
116 #define COLOR_YELLOW 3
117 @@ -860,42 +860,123 @@ extern char *tparm();
118 #define COLOR_WHITE 7
121 -#define COLOR_BLACK COLOR_BLUE
123 -const int ti_map[8] = {
124 - COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW,
125 - COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE };
126 +/* Mapping data for the six terminfo colors that resolve to pairs of nethack
127 + * colors. Black and white are handled specially.
129 +const struct {int ti_color, nh_color, nh_bright_color;} ti_map[6] =
131 + {COLOR_RED,CLR_RED,CLR_ORANGE},
132 + {COLOR_GREEN,CLR_GREEN,CLR_BRIGHT_GREEN},
133 + {COLOR_YELLOW,CLR_BROWN,CLR_YELLOW},
134 + {COLOR_BLUE,CLR_BLUE,CLR_BRIGHT_BLUE},
135 + {COLOR_MAGENTA,CLR_MAGENTA,CLR_BRIGHT_MAGENTA},
136 + {COLOR_CYAN,CLR_CYAN,CLR_BRIGHT_CYAN}
143 char *setf, *scratch;
145 - for (c = 0; c < SIZE(hilites); c++)
146 - hilites[c] = nh_HI;
147 - hilites[CLR_GRAY] = hilites[NO_COLOR] = (char *)0;
150 if (tgetnum("Co") < 8
151 || ((setf = tgetstr("AF", (char **)0)) == (char *)0
152 && (setf = tgetstr("Sf", (char **)0)) == (char *)0))
154 + /* Fallback when colors not available
155 + * It's arbitrary to collapse all colors except gray
156 + * together, but that's what the previous code did.
158 + hilites[CLR_BLACK] = nh_HI;
159 + hilites[CLR_RED] = nh_HI;
160 + hilites[CLR_GREEN] = nh_HI;
161 + hilites[CLR_BROWN] = nh_HI;
162 + hilites[CLR_BLUE] = nh_HI;
163 + hilites[CLR_MAGENTA] = nh_HI;
164 + hilites[CLR_CYAN] = nh_HI;
165 + hilites[CLR_GRAY] = "";
166 + hilites[NO_COLOR] = "";
167 + hilites[CLR_ORANGE] = nh_HI;
168 + hilites[CLR_BRIGHT_GREEN] = nh_HI;
169 + hilites[CLR_YELLOW] = nh_HI;
170 + hilites[CLR_BRIGHT_BLUE] = nh_HI;
171 + hilites[CLR_BRIGHT_MAGENTA] = nh_HI;
172 + hilites[CLR_BRIGHT_CYAN] = nh_HI;
173 + hilites[CLR_WHITE] = nh_HI;
177 - for (c = 0; c < CLR_MAX / 2; c++) {
178 - scratch = tparm(setf, ti_map[c]);
179 - if (c != CLR_GRAY) {
180 - hilites[c] = (char *) alloc(strlen(scratch) + 1);
181 - Strcpy(hilites[c], scratch);
183 - if (c != CLR_BLACK) {
184 - hilites[c|BRIGHT] = (char*) alloc(strlen(scratch)+strlen(MD)+1);
185 - Strcpy(hilites[c|BRIGHT], MD);
186 - Strcat(hilites[c|BRIGHT], scratch);
188 + length_md = strlen(MD);
195 + scratch = tparm(setf,ti_map[c].ti_color);
196 + work = (char *) alloc(strlen(scratch) + length_md + 1);
198 + hilites[ti_map[c].nh_bright_color] = work;
200 + Strcpy(work,scratch);
201 + hilites[ti_map[c].nh_color] = work;
204 + hilites[CLR_WHITE] = MD;
205 + hilites[CLR_GRAY] = "";
206 + hilites[NO_COLOR] = "";
208 + if (iflags.wc2_darkgray)
210 + /* On many terminals, esp. those using classic PC CGA/EGA/VGA
211 + * textmode, specifying "hilight" and "black" simultaneously
212 + * produces a dark shade of gray that is visible against a
213 + * black background. We can use it to represent black objects.
215 + scratch = tparm(setf,COLOR_BLACK);
216 + hilites[CLR_BLACK] = (char *) alloc(strlen(scratch) + length_md + 1);
217 + Strcpy(hilites[CLR_BLACK],MD);
218 + Strcat(hilites[CLR_BLACK],scratch);
222 + /* But it's concievable that hilighted black-on-black could
223 + * still be invisible on many others. We substitute blue for
226 + hilites[CLR_BLACK] = hilites[CLR_BLUE];
233 + /* if colors weren't usable, no freeing needed */
234 + if (hilites[CLR_BLACK] == nh_HI)
237 + if (hilites[CLR_BLACK] != hilites[CLR_BLUE])
238 + free(hilites[CLR_BLACK]);
240 + /* CLR_BLUE overlaps CLR_BRIGHT_BLUE, do not free */
241 + /* CLR_GREEN overlaps CLR_BRIGHT_GREEN, do not free */
242 + /* CLR_CYAN overlaps CLR_BRIGHT_CYAN, do not free */
243 + /* CLR_RED overlaps CLR_ORANGE, do not free */
244 + /* CLR_MAGENTA overlaps CLR_BRIGHT_MAGENTA, do not free */
245 + /* CLR_BROWN overlaps CLR_YELLOW, do not free */
246 + /* CLR_GRAY is a constant "", do not free */
247 + /* NO_COLOR is a constant "", do not free */
248 + free(hilites[CLR_BRIGHT_BLUE]);
249 + free(hilites[CLR_BRIGHT_GREEN]);
250 + free(hilites[CLR_BRIGHT_CYAN]);
251 + free(hilites[CLR_YELLOW]);
252 + free(hilites[CLR_ORANGE]);
253 + free(hilites[CLR_BRIGHT_MAGENTA]);
254 + /* CLR_WHITE is the common variable MD, do not free */
257 # else /* UNIX && TERMINFO */
260 @@ -1040,7 +1121,6 @@ init_hilite()
268 @@ -1058,6 +1138,7 @@ kill_hilite()
273 #endif /* TEXTCOLOR */
276 diff -durpN nethack-3.4.3/win/tty/wintty.c nethack-gray/win/tty/wintty.c
277 --- nethack-3.4.3/win/tty/wintty.c 2003-12-07 15:39:14.000000000 -0800
278 +++ nethack-gray/win/tty/wintty.c 2003-12-09 18:37:21.000000000 -0800
279 @@ -50,7 +50,11 @@ struct window_procs tty_procs = {
282 WC_COLOR|WC_HILITE_PET|WC_INVERSE|WC_EIGHT_BIT_IN,
289 tty_player_selection,