curses menu coloring

Have the 'menucolors' option control menu color pattern matching
(instead of curses-specific 'guicolor') for all menus, not just for
the persistent inventory window.
This commit is contained in:
PatR
2019-08-31 23:51:59 -07:00
parent e9aac25922
commit 301a558a9c
6 changed files with 40 additions and 29 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.106 $ $NHDT-Date: 1567273590 2019/08/31 17:46:30 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.107 $ $NHDT-Date: 1567302620 2019/09/01 01:50:20 $
This fixes36.3 file is here to capture information about updates in the 3.6.x This fixes36.3 file is here to capture information about updates in the 3.6.x
lineage following the release of 3.6.2 in May 2019. Please note, however, lineage following the release of 3.6.2 in May 2019. Please note, however,
@@ -219,6 +219,8 @@ curses: disable the attempt to support Ctrl+Left_click as an alternate way
to generate Right_click for systems with one-button mouse or trackpad; to generate Right_click for systems with one-button mouse or trackpad;
the mouse data passed to nethack didn't match the curses (ncurses on the mouse data passed to nethack didn't match the curses (ncurses on
OSX 10.11) documentation and things didn't work as intended OSX 10.11) documentation and things didn't work as intended
curses: menu coloring required that both 'menucolors' and 'guicolor' be On;
for menus, override guicolor with more-specific menucolors
curses+'perm_invent': entries were wrapping without any control; usually not curses+'perm_invent': entries were wrapping without any control; usually not
noticeable because next entry overwrote, but visible for final entry noticeable because next entry overwrote, but visible for final entry
when whole inventory fit within the available height; looked ok with when whole inventory fit within the available height; looked ok with
@@ -232,8 +234,6 @@ curses+'perm_invent': don't highlight inventory letters since nothing is
curses+'perm_invent': could crash during restore if game was saved while curses+'perm_invent': could crash during restore if game was saved while
hero was swallowed (invalid u.ustuck pointer; suppressing attempts to hero was swallowed (invalid u.ustuck pointer; suppressing attempts to
update persistent inventory window during restore hides the problem) update persistent inventory window during restore hides the problem)
curses+'perm_invent': menu coloring required that both 'menucolors' and
'guicolor' be On; override guicolor with more-specific menucolors
curses+'popup_dialog': show the text cursor at the end of prompts for single curses+'popup_dialog': show the text cursor at the end of prompts for single
character input character input
curses+DUMPLOG: pass along old messages from save file and quest message curses+DUMPLOG: pass along old messages from save file and quest message
+1
View File
@@ -143,6 +143,7 @@ extern boolean curses_map_borders(int *sx, int *sy, int *ex, int *ey,
extern int curses_read_char(void); extern int curses_read_char(void);
extern void curses_toggle_color_attr(WINDOW *win, int color, int attr, extern void curses_toggle_color_attr(WINDOW *win, int color, int attr,
int onoff); int onoff);
extern void curses_menu_color_attr(WINDOW *, int, int, int);
extern void curses_bail(const char *mesg); extern void curses_bail(const char *mesg);
extern winid curses_get_wid(int type); extern winid curses_get_wid(int type);
extern char *curses_copy_of(const char *s); extern char *curses_copy_of(const char *s);
+16 -14
View File
@@ -1185,21 +1185,20 @@ menu_display_page(nhmenu *menu, WINDOW * win, int page_num, char *selectors)
start_col += 2; start_col += 2;
} }
#endif #endif
if (iflags.use_menu_color color = NO_COLOR;
&& (menu_color = get_menu_coloring(menu_item_ptr->str, menu_color = iflags.use_menu_color
&color, &attr)) != 0) { && get_menu_coloring(menu_item_ptr->str, &color, &attr);
if (color != NO_COLOR) { if (menu_color) {
curses_toggle_color_attr(win, color, NONE, ON);
}
attr = curses_convert_attr(attr); attr = curses_convert_attr(attr);
if (attr != A_NORMAL) { if (color != NO_COLOR || attr != A_NORMAL)
menu_item_ptr->attr = menu_item_ptr->attr | attr; curses_menu_color_attr(win, color, attr, ON);
} } else {
attr = menu_item_ptr->attr;
if (color != NO_COLOR || attr != A_NORMAL)
curses_toggle_color_attr(win, color, attr, ON);
} }
curses_toggle_color_attr(win, NONE, menu_item_ptr->attr, ON);
num_lines = curses_num_lines(menu_item_ptr->str, entry_cols); num_lines = curses_num_lines(menu_item_ptr->str, entry_cols);
for (count = 0; count < num_lines; count++) { for (count = 0; count < num_lines; count++) {
if (menu_item_ptr->str && *menu_item_ptr->str) { if (menu_item_ptr->str && *menu_item_ptr->str) {
tmpstr = curses_break_str(menu_item_ptr->str, tmpstr = curses_break_str(menu_item_ptr->str,
@@ -1209,10 +1208,13 @@ menu_display_page(nhmenu *menu, WINDOW * win, int page_num, char *selectors)
free(tmpstr); free(tmpstr);
} }
} }
if (menu_color && (color != NO_COLOR)) { if (color != NO_COLOR || attr != A_NORMAL) {
curses_toggle_color_attr(win, color, NONE, OFF); if (menu_color)
curses_menu_color_attr(win, color, attr, OFF);
else
curses_toggle_color_attr(win, color, attr, OFF);
} }
curses_toggle_color_attr(win, NONE, menu_item_ptr->attr, OFF);
menu_item_ptr = menu_item_ptr->next_item; menu_item_ptr = menu_item_ptr->next_item;
} }
+2 -11
View File
@@ -60,7 +60,6 @@ curses_add_inv(int y,
CHAR_P accelerator, attr_t attr, const char *str) CHAR_P accelerator, attr_t attr, const char *str)
{ {
WINDOW *win = curses_get_nhwin(INV_WIN); WINDOW *win = curses_get_nhwin(INV_WIN);
boolean save_guicolor;
int color = NO_COLOR; int color = NO_COLOR;
int x = 0, width, height, available_width, stroffset = 0, int x = 0, width, height, available_width, stroffset = 0,
border = curses_window_has_border(INV_WIN) ? 1 : 0; border = curses_window_has_border(INV_WIN) ? 1 : 0;
@@ -142,16 +141,8 @@ curses_add_inv(int y,
} }
if (color == NO_COLOR) if (color == NO_COLOR)
color = NONE; color = NONE;
/* curses_toggle_color_attr() uses 'guicolor' to decide whether to curses_menu_color_attr(win, color, attr, ON);
honor specified color, but persistent inventory window has its own
more-specific control, 'menucolors', so override with that here */
save_guicolor = iflags.wc2_guicolor;
iflags.wc2_guicolor = iflags.use_menu_color;
curses_toggle_color_attr(win, color, attr, ON);
/* wattron(win, attr); */
wprintw(win, "%.*s", available_width, str + stroffset); wprintw(win, "%.*s", available_width, str + stroffset);
/* wattroff(win, attr); */ curses_menu_color_attr(win, color, attr, OFF);
curses_toggle_color_attr(win, color, attr, OFF);
iflags.wc2_guicolor = save_guicolor;
wclrtoeol(win); wclrtoeol(win);
} }
+16
View File
@@ -163,6 +163,22 @@ curses_toggle_color_attr(WINDOW *win, int color, int attr, int onoff)
#endif /* TEXTCOLOR */ #endif /* TEXTCOLOR */
} }
/* call curses_toggle_color_attr() with 'menucolors' instead of 'guicolor'
as the control flag */
void
curses_menu_color_attr(WINDOW *win, int color, int attr, int onoff)
{
boolean save_guicolor = iflags.wc2_guicolor;
/* curses_toggle_color_attr() uses 'guicolor' to decide whether to
honor specified color, but menu windows have their own
more-specific control, 'menucolors', so override with that here */
iflags.wc2_guicolor = iflags.use_menu_color;
curses_toggle_color_attr(win, color, attr, onoff);
iflags.wc2_guicolor = save_guicolor;
}
/* clean up and quit - taken from tty port */ /* clean up and quit - taken from tty port */
+2 -1
View File
@@ -9,7 +9,8 @@
/* Global declarations */ /* Global declarations */
int curses_read_char(void); int curses_read_char(void);
void curses_toggle_color_attr(WINDOW * win, int color, int attr, int onoff); 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); void curses_bail(const char *mesg);
winid curses_get_wid(int type); winid curses_get_wid(int type);
char *curses_copy_of(const char *s); char *curses_copy_of(const char *s);