From 2ff96797a8a52d0917529f68f1a3e38dca2668e8 Mon Sep 17 00:00:00 2001 From: Tung Nguyen Date: Thu, 17 Mar 2016 14:20:17 +1100 Subject: [PATCH 1/3] Omit accel and select char from menu colors e.g. When there's "a - whatever", color the "whatever" part and leave the "a - " part unformatted. This matches the behavior of menu colors in NAO343. --- win/tty/wintty.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 199474869..9c33a11b1 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -1777,6 +1777,15 @@ struct WinDesc *cw; page_lines++, curr = curr->next) { int color = NO_COLOR, attr = ATR_NONE; boolean menucolr = FALSE; + int select_pos = -1; /* -/+/# position for selectables */ + int format_start_pos = 0; /* menu color/attr start pos */ + + if (curr->identifier.a_void != 0) { + /* "a - whatever" */ + select_pos = 2; /* '-' */ + format_start_pos = 4; /* start of "whatever" */ + } + if (curr->selector) *rp++ = curr->selector; @@ -1793,27 +1802,31 @@ struct WinDesc *cw; * actually output the character. We're faster doing * this. */ - if (iflags.use_menu_color - && (menucolr = get_menu_coloring(curr->str, &color, - &attr))) { - term_start_attr(attr); -#ifdef TEXTCOLOR - if (color != NO_COLOR) - term_start_color(color); -#endif - } else - term_start_attr(curr->attr); for (n = 0, cp = curr->str; #ifndef WIN32CON *cp && (int) ++ttyDisplay->curx < (int) ttyDisplay->cols; - cp++, n++) + cp++, n++ #else *cp && (int) ttyDisplay->curx < (int) ttyDisplay->cols; - cp++, n++, ttyDisplay->curx++) + cp++, n++, ttyDisplay->curx++ #endif - if (n == 2 && curr->identifier.a_void != 0 + ) { + if (n == format_start_pos) { + if (iflags.use_menu_color + && (menucolr = get_menu_coloring(curr->str, + &color, + &attr))) { + term_start_attr(attr); +#ifdef TEXTCOLOR + if (color != NO_COLOR) + term_start_color(color); +#endif + } else + term_start_attr(curr->attr); + } + if (n == select_pos && curr->identifier.a_void != 0 && curr->selected) { if (curr->count == -1L) (void) putchar('+'); /* all selected */ @@ -1821,6 +1834,7 @@ struct WinDesc *cw; (void) putchar('#'); /* count selected */ } else (void) putchar(*cp); + } if (iflags.use_menu_color && menucolr) { #ifdef TEXTCOLOR if (color != NO_COLOR) From cfb0a075525148767845d7905d758e57679e3b6c Mon Sep 17 00:00:00 2001 From: Tung Nguyen Date: Thu, 17 Mar 2016 14:46:59 +1100 Subject: [PATCH 2/3] Stop `>` from closing TTY menus on the last page Pages can now be freely and safely scrolled with the `<` and `>` keys. Space still dismisses menus if it's used on the last page. --- win/tty/wintty.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 9c33a11b1..e99418d7f 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -360,9 +360,6 @@ char **argv UNUSED; (void) signal(SIGWINCH, (SIG_RET_TYPE) winch_handler); #endif - /* add one a space forward menu command alias */ - add_menu_cmd_alias(' ', MENU_NEXT_PAGE); - tty_clear_nhwindow(BASE_WINDOW); tty_putstr(BASE_WINDOW, 0, ""); @@ -1863,6 +1860,7 @@ struct WinDesc *cw; /* set extra chars.. */ Strcat(resp, default_menu_cmds); + Strcat(resp, " "); /* next page or end */ Strcat(resp, "0123456789\033\n\r"); /* counts, quit */ Strcat(resp, gacc); /* group accelerators */ Strcat(resp, mapped_menu_cmds); @@ -1946,12 +1944,15 @@ struct WinDesc *cw; break; } /* else fall through */ + case ' ': case MENU_NEXT_PAGE: if (cw->npages > 0 && curr_page != cw->npages - 1) { curr_page++; page_start = 0; - } else - finished = TRUE; /* questionable behavior */ + } else if (morc == ' ') { + /* ' ' finishes menus here, but stop '>' doing the same. */ + finished = TRUE; + } break; case MENU_PREVIOUS_PAGE: if (cw->npages > 0 && curr_page != 0) { From 0508b981a29d0afad9791772c657f13692224ac7 Mon Sep 17 00:00:00 2001 From: Tung Nguyen Date: Wed, 23 Mar 2016 19:33:42 +1100 Subject: [PATCH 3/3] Revert "Omit accel and select char from menu colors" This reverts commit 2ff96797a8a52d0917529f68f1a3e38dca2668e8. Since this pull request was made to the DevTeam, a commit has appeared in the official repo's NetHack-3.6.0 branch which effectively does the same thing: NetHack commit 98b5f58 (tty menu coloring) by PatR. --- win/tty/wintty.c | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/win/tty/wintty.c b/win/tty/wintty.c index e99418d7f..73166b7db 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -1774,15 +1774,6 @@ struct WinDesc *cw; page_lines++, curr = curr->next) { int color = NO_COLOR, attr = ATR_NONE; boolean menucolr = FALSE; - int select_pos = -1; /* -/+/# position for selectables */ - int format_start_pos = 0; /* menu color/attr start pos */ - - if (curr->identifier.a_void != 0) { - /* "a - whatever" */ - select_pos = 2; /* '-' */ - format_start_pos = 4; /* start of "whatever" */ - } - if (curr->selector) *rp++ = curr->selector; @@ -1799,31 +1790,27 @@ struct WinDesc *cw; * actually output the character. We're faster doing * this. */ + if (iflags.use_menu_color + && (menucolr = get_menu_coloring(curr->str, &color, + &attr))) { + term_start_attr(attr); +#ifdef TEXTCOLOR + if (color != NO_COLOR) + term_start_color(color); +#endif + } else + term_start_attr(curr->attr); for (n = 0, cp = curr->str; #ifndef WIN32CON *cp && (int) ++ttyDisplay->curx < (int) ttyDisplay->cols; - cp++, n++ + cp++, n++) #else *cp && (int) ttyDisplay->curx < (int) ttyDisplay->cols; - cp++, n++, ttyDisplay->curx++ + cp++, n++, ttyDisplay->curx++) #endif - ) { - if (n == format_start_pos) { - if (iflags.use_menu_color - && (menucolr = get_menu_coloring(curr->str, - &color, - &attr))) { - term_start_attr(attr); -#ifdef TEXTCOLOR - if (color != NO_COLOR) - term_start_color(color); -#endif - } else - term_start_attr(curr->attr); - } - if (n == select_pos && curr->identifier.a_void != 0 + if (n == 2 && curr->identifier.a_void != 0 && curr->selected) { if (curr->count == -1L) (void) putchar('+'); /* all selected */ @@ -1831,7 +1818,6 @@ struct WinDesc *cw; (void) putchar('#'); /* count selected */ } else (void) putchar(*cp); - } if (iflags.use_menu_color && menucolr) { #ifdef TEXTCOLOR if (color != NO_COLOR)