From 59ab9658631b766a2316dd35ef512343b30bff5e Mon Sep 17 00:00:00 2001 From: PatR Date: Sun, 24 Mar 2019 19:20:21 -0700 Subject: [PATCH] curses ^P - support msg_window:full curses uses 'reversed' (LIFO) style when displaying previous messages. Use the existing (previously tty-only) 'msg_window' option to also support 'full' (FIFO). The actual code needed as just a couple of lines; tweaking options parsing and the documentation was more work. --- doc/Guidebook.mn | 9 +++--- doc/Guidebook.tex | 9 ++++-- doc/fixes36.2 | 3 +- src/options.c | 72 ++++++++++++++++++++++++------------------- win/curses/cursinit.c | 6 ++++ win/curses/cursmesg.c | 10 +++--- 6 files changed, 66 insertions(+), 43 deletions(-) diff --git a/doc/Guidebook.mn b/doc/Guidebook.mn index 0f67c2b0d..051f61299 100644 --- a/doc/Guidebook.mn +++ b/doc/Guidebook.mn @@ -1,4 +1,4 @@ -.\" $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.300 $ $NHDT-Date: 1553204011 2019/03/21 21:33:31 $ +.\" $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.301 $ $NHDT-Date: 1553480404 2019/03/25 02:20:04 $ .\" .\" This is an excerpt from the 'roff' man page from the 'groff' package. .\" NetHack's Guidebook.mn currently does *not* adhere to these guidelines. @@ -24,7 +24,7 @@ .ds vr "NetHack 3.6 .ds f0 "\*(vr .ds f1 -.ds f2 "March 19, 2019 +.ds f2 "March 24, 2019 . .\" A note on some special characters: .\" \(lq = left double quote @@ -777,7 +777,7 @@ choices but will accept an accessory and attempt to put that on.) Repeat previous message. .lp "" Subsequent \(oq\(haP\(cqs repeat earlier messages. -The behavior can be varied via the +For some interfaces, the behavior can be varied via the .op msg_window option. .lp q @@ -3171,7 +3171,8 @@ with \(oq\(haP\(cq) (default 20). Cannot be set with the \(oqO\(cq command. .lp msg_window Allows you to change the way recalled messages are displayed. -(It is currently implemented for tty only.) +Currently it is only supported for tty (all four choices) and for curses +(\(oq\f(CRf\fP\(cq and \(oq\f(CRr\fP\(cq choices, default \(oq\f(CRr\fP\(cq). The possible values are: .sd .si diff --git a/doc/Guidebook.tex b/doc/Guidebook.tex index ad3fa1ce7..fa1a9872a 100644 --- a/doc/Guidebook.tex +++ b/doc/Guidebook.tex @@ -45,7 +45,7 @@ %.au \author{Original version - Eric S. Raymond\\ (Edited and expanded for 3.6 by Mike Stephenson and others)} -\date{March 19, 2019} +\date{March 24, 2019} \maketitle @@ -883,7 +883,8 @@ choices but will accept an accessory and attempt to put that on.) Repeat previous message.\\ %.lp "" Subsequent {\tt \^{}P}'s repeat earlier messages. -The behavior can be varied via the {\it msg\verb+_+window\/} option. +For some interfaces, the behavior can be varied via the +{\it msg\verb+_+window\/} option. %.lp \item[\tb{q}] Quaff (drink) something (potion, water, etc). @@ -3484,7 +3485,9 @@ Cannot be set with the `{\tt O}' command. %.lp \item[\ib{msg\verb+_+window}] Allows you to change the way recalled messages are displayed. -(It is currently implemented for tty only.) The possible values are: +Currently it is only supported for tty (all four choices) and for curses +(`{\tt f}' and `{\tt r}' choices, default `{\tt r}'). +The possible values are: %.sd %.si diff --git a/doc/fixes36.2 b/doc/fixes36.2 index 405f5bba6..6ddbc7866 100644 --- a/doc/fixes36.2 +++ b/doc/fixes36.2 @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.281 $ $NHDT-Date: 1553475022 2019/03/25 00:50:22 $ +$NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.282 $ $NHDT-Date: 1553480403 2019/03/25 02:20:03 $ This fixes36.2 file is here to capture information about updates in the 3.6.x lineage following the release of 3.6.1 in April 2018. Please note, however, @@ -644,6 +644,7 @@ when healing magic other than unicorn horn cures blindness, cure deafness too curses: status display substantially revamped for both horizontal (via 'align_status:bottom' or 'top') and vertical (via 'align_status:left' or 'right'); 3-line horizontal layout (via 'statuslines:3') added +curses: support msg_window:full; default is still msg_window:reversed NetHack Community Patches (or Variation) Included diff --git a/src/options.c b/src/options.c index 551eca6de..f90cef3bd 100644 --- a/src/options.c +++ b/src/options.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 options.c $NHDT-Date: 1553217909 2019/03/22 01:25:09 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.359 $ */ +/* NetHack 3.6 options.c $NHDT-Date: 1553480404 2019/03/25 02:20:04 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.360 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Michael Allison, 2008. */ /* NetHack may be freely redistributed. See license for details. */ @@ -734,8 +734,13 @@ initoptions_init() flags.pile_limit = PILE_LIMIT_DFLT; /* 5 */ flags.runmode = RUN_LEAP; iflags.msg_history = 20; + /* msg_window has conflicting defaults for multi-interface binary */ #ifdef TTY_GRAPHICS iflags.prevmsg_window = 's'; +#else +#ifdef CURSES_GRAPHICS + iflags.prevmsg_window = 'r'; +#endif #endif iflags.menu_headings = ATR_INVERSE; iflags.getpos_coords = GPCOORDS_NONE; @@ -2412,19 +2417,18 @@ boolean tinitial, tfrom_file; case 's': /* single message history cycle (default if negated) */ iflags.prevmsg_window = 's'; break; - case 'c': /* combination: two singles, then full page reversed */ + case 'c': /* combination: two singles, then full page */ iflags.prevmsg_window = 'c'; break; - case 'f': /* full page (default if no opts) */ + case 'f': /* full page (default if specified without argument) */ iflags.prevmsg_window = 'f'; break; case 'r': /* full page (reversed) */ iflags.prevmsg_window = 'r'; break; - default: { + default: config_error_add("Unknown %s parameter '%s'", fullname, op); - return FALSE; - } + retval = FALSE; } #endif return retval; @@ -4949,32 +4953,38 @@ boolean setinitial, setfromfile; } destroy_nhwindow(tmpwin); } else if (!strcmp("msg_window", optname)) { -#ifdef TTY_GRAPHICS - /* by Christian W. Cooper */ - menu_item *window_pick = (menu_item *) 0; +#if defined(TTY_GRAPHICS) || defined(CURSES_GRAPHICS) + if (WINDOWPORT("tty") || WINDOWPORT("curses")) { + /* by Christian W. Cooper */ + menu_item *window_pick = (menu_item *) 0; - tmpwin = create_nhwindow(NHW_MENU); - start_menu(tmpwin); - any = zeroany; - any.a_char = 's'; - add_menu(tmpwin, NO_GLYPH, &any, 's', 0, ATR_NONE, "single", - MENU_UNSELECTED); - any.a_char = 'c'; - add_menu(tmpwin, NO_GLYPH, &any, 'c', 0, ATR_NONE, "combination", - MENU_UNSELECTED); - any.a_char = 'f'; - add_menu(tmpwin, NO_GLYPH, &any, 'f', 0, ATR_NONE, "full", - MENU_UNSELECTED); - any.a_char = 'r'; - add_menu(tmpwin, NO_GLYPH, &any, 'r', 0, ATR_NONE, "reversed", - MENU_UNSELECTED); - end_menu(tmpwin, "Select message history display type:"); - if (select_menu(tmpwin, PICK_ONE, &window_pick) > 0) { - iflags.prevmsg_window = window_pick->item.a_char; - free((genericptr_t) window_pick); - } - destroy_nhwindow(tmpwin); -#endif + tmpwin = create_nhwindow(NHW_MENU); + start_menu(tmpwin); + any = zeroany; + if (!WINDOWPORT("curses")) { + any.a_char = 's'; + add_menu(tmpwin, NO_GLYPH, &any, 's', 0, ATR_NONE, + "single", MENU_UNSELECTED); + any.a_char = 'c'; + add_menu(tmpwin, NO_GLYPH, &any, 'c', 0, ATR_NONE, + "combination", MENU_UNSELECTED); + } + any.a_char = 'f'; + add_menu(tmpwin, NO_GLYPH, &any, 'f', 0, ATR_NONE, "full", + MENU_UNSELECTED); + any.a_char = 'r'; + add_menu(tmpwin, NO_GLYPH, &any, 'r', 0, ATR_NONE, "reversed", + MENU_UNSELECTED); + end_menu(tmpwin, "Select message history display type:"); + if (select_menu(tmpwin, PICK_ONE, &window_pick) > 0) { + iflags.prevmsg_window = window_pick->item.a_char; + free((genericptr_t) window_pick); + } + destroy_nhwindow(tmpwin); + } else +#endif /* msg_window for tty or curses */ + pline("'%s' option is not supported for '%s'.", + optname, windowprocs.name); } else if (!strcmp("sortloot", optname)) { const char *sortl_name; menu_item *sortl_pick = (menu_item *) 0; diff --git a/win/curses/cursinit.c b/win/curses/cursinit.c index 924f41c8d..19a12c6bc 100644 --- a/win/curses/cursinit.c +++ b/win/curses/cursinit.c @@ -827,6 +827,12 @@ curses_init_options() iflags.wc2_petattr = A_REVERSE; } + /* curses doesn't support 's' (single message at a time; successive + ^P's go back to earlier messages) and 'c' (combination; single + on first and second of consecutive ^P's, full on third) */ + if (iflags.prevmsg_window != 'f') + iflags.prevmsg_window = 'r'; + #ifdef NCURSES_MOUSE_VERSION if (iflags.wc_mouse_support) { mousemask(BUTTON1_CLICKED, NULL); diff --git a/win/curses/cursmesg.c b/win/curses/cursmesg.c index 2323be6cf..98723fcbe 100644 --- a/win/curses/cursmesg.c +++ b/win/curses/cursmesg.c @@ -284,20 +284,22 @@ curses_teardown_messages(void) void curses_prev_mesg() { - int count; + int count, fifo_count; winid wid; long turn = 0; anything Id; nhprev_mesg *mesg; menu_item *selected = NULL; + boolean do_lifo = (iflags.prevmsg_window != 'f'); wid = curses_get_wid(NHW_MENU); curses_create_nhmenu(wid); Id = zeroany; - for (count = 0; count < num_messages; count++) { - mesg = get_msg_line(TRUE, count); - if ((turn != mesg->turn) && (count != 0)) { + for (count = 0, fifo_count = num_messages - 1; count < num_messages; + ++count, --fifo_count) { + mesg = get_msg_line(TRUE, do_lifo ? count : fifo_count); + if (turn != mesg->turn && count != 0) { curses_add_menu(wid, NO_GLYPH, &Id, 0, 0, A_NORMAL, "---", FALSE); } curses_add_menu(wid, NO_GLYPH, &Id, 0, 0, A_NORMAL, mesg->str, FALSE); -- 2.40.0