]> granicus.if.org Git - nethack/commitdiff
tty ^P message recall
authorPatR <rankin@nethack.org>
Tue, 5 Feb 2019 00:46:04 +0000 (16:46 -0800)
committerPatR <rankin@nethack.org>
Tue, 5 Feb 2019 00:46:04 +0000 (16:46 -0800)
Extend 'putstr(WIN_MESSAGE, attribute, string)'s attribute so that
'custompline(SUPPRESS_HISTORY, ...)' can work with ^P's message
history like DUMPLOG history, in order to keep autodescribe feedback
and intermediate prompts for multi-digit count ('Count: 12', 'Count:
123') prompts out of recall history.  The old autodescribe behavior
could easily push all real messages out of the recall buffer when
moving the cursor around for getpos, and the count behavior looked
silly for a four or five digit gold count if you set the msg_window
option to 'full' or 'combination' and viewed them all at once.

Other interfaces may want to follow suit, but this doesn't force them
to make any changes.  I added a hook for "urgent messages" that might
be rendered in bold or red or some such and/or override the use of
ESC at --More-- from suppressing further messages, but there aren't
any custompline(URGENT_MESSAGE, ...) calls (potentially "You die...",
for instance) to exercise it.  Other people have implemented similar
feature it different ways and I'm not sure whether this one is really
the way to go since the core needs to categorize each message that it
deems to be urgent.  MSG_TYPE:stop may be sufficent, although MSG_TYPE
matching can entail a lot of regexp execution overhead at run-time.

include/hack.h
include/winprocs.h
include/wintty.h
include/wintype.h
src/cmd.c
src/pline.c
win/tty/topl.c
win/tty/wintty.c

index 6dfedf762f14c57dcd836dfd3ca50e3e08fa876e..f686f7a4a178e69355220b1855cd3edec6331e51 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 hack.h  $NHDT-Date: 1547514631 2019/01/15 01:10:31 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.101 $ */
+/* NetHack 3.6 hack.h  $NHDT-Date: 1549327459 2019/02/05 00:44:19 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.102 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Pasi Kallinen, 2017. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -402,6 +402,7 @@ enum explosion_types {
 #define PLINE_NOREPEAT   1
 #define OVERRIDE_MSGTYPE 2
 #define SUPPRESS_HISTORY 4
+#define URGENT_MESSAGE   8
 
 /* Macros for messages referring to hands, eyes, feet, etc... */
 enum bodypart_types {
index 85ece4a7dbfbacdb5d7dcdf962254ed2d81e6745..26512c8ce6230914d3059a6219ac661fff193a5e 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 winprocs.h      $NHDT-Date: 1502141230 2017/08/07 21:27:10 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.38 $ */
+/* NetHack 3.6 winprocs.h      $NHDT-Date: 1549327479 2019/02/05 00:44:39 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.46 $ */
 /* Copyright (c) David Cohrs, 1992                               */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -213,14 +213,20 @@ extern
 #define WC2_DARKGRAY      0x0020L /* 06 use bold black for black glyphs */
 #define WC2_HITPOINTBAR   0x0040L /* 07 show bar representing hit points */
 #define WC2_FLUSH_STATUS  0x0080L /* 08 call status_update(BL_FLUSH)
-                                        after updating status window fields */
-#define WC2_RESET_STATUS  0x0100L /* 09 call status_update(BL_RESET) to indicate
-                                        draw everything */
+                                   *    after updating status window fields */
+#define WC2_RESET_STATUS  0x0100L /* 09 call status_update(BL_RESET) to
+                                   *    indicate 'draw everything'      */
 #define WC2_TERM_SIZE     0x0200L /* 10 support setting terminal size   */
 #define WC2_WINDOWBORDERS 0x0400L /* 11 display borders on nh windows   */
 #define WC2_PETATTR       0x0800L /* 12 attributes for hilite_pet       */
 #define WC2_GUICOLOR      0x1000L /* 13 display colours outside map win */
-                                  /* 19 free bits */
+/* pline() can overload the display attributes argument passed to putstr()
+   with one or more flags and at most one of bold/blink/inverse/&c */
+#define WC2_URGENT_MESG   0x2000L /* 14 putstr(WIN_MESSAGE) supports urgency
+                                   *    via non-display attribute flag  */
+#define WC2_SUPPRESS_HIST 0x4000L /* 15 putstr(WIN_MESSAGE) supports history
+                                   *    suppression via non-disp attr   */
+                                  /* 17 free bits */
 
 #define ALIGN_LEFT   1
 #define ALIGN_RIGHT  2
index 99b560d8258bc5e8d5c403eadfa3d4804de00956..f7e5b061155e67f18b17734a2db7010ddccbf87e 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 wintty.h        $NHDT-Date: 1433806583 2015/06/08 23:36:23 $  $NHDT-Branch: master $:$NHDT-Revision: 1.24 $ */
+/* NetHack 3.6 wintty.h        $NHDT-Date: 1549327485 2019/02/05 00:44:45 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.32 $ */
 /* Copyright (c) David Cohrs, 1991,1992                                  */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -164,6 +164,8 @@ E int FDECL(has_color, (int color));
 
 /* ### topl.c ### */
 
+E void FDECL(show_topl, (const char *));
+E void NDECL(remember_topl);
 E void FDECL(addtopl, (const char *));
 E void NDECL(more);
 E void FDECL(update_topl, (const char *));
index 3bb82347dc880773bdbbc265f635fce5a4a77963..26afbca3f914e319a4c91c836c4f6de2d3a8bcbd 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6  wintype.h       $NHDT-Date: 1461028538 2016/04/19 01:15:38 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.16 $ */
+/* NetHack 3.6  wintype.h       $NHDT-Date: 1549327486 2019/02/05 00:44:46 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.19 $ */
 /* Copyright (c) David Cohrs, 1991                                */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -74,12 +74,16 @@ typedef struct mi {
 #define NHW_TEXT 5
 
 /* attribute types for putstr; the same as the ANSI value, for convenience */
-#define ATR_NONE 0
-#define ATR_BOLD 1
-#define ATR_DIM 2
-#define ATR_ULINE 4
-#define ATR_BLINK 5
-#define ATR_INVERSE 7
+#define ATR_NONE       0
+#define ATR_BOLD       1
+#define ATR_DIM        2
+#define ATR_ULINE      4
+#define ATR_BLINK      5
+#define ATR_INVERSE    7
+/* not a display attribute but passed to putstr() as an attribute;
+   can be masked with one regular display attribute */
+#define ATR_URGENT    16
+#define ATR_NOHISTORY 32
 
 /* nh_poskey() modifier types */
 #define CLICK_1 1
index 5b77eb1a423b91b4a750a91ca182b6118840b116..c3166bd6a579a7f296b7f0ee277d582972b7a774 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -1,4 +1,4 @@
-/* NetHack 3.6 cmd.c   $NHDT-Date: 1548978603 2019/01/31 23:50:03 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.330 $ */
+/* NetHack 3.6 cmd.c   $NHDT-Date: 1549327488 2019/02/05 00:44:48 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.331 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2013. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -5572,9 +5572,7 @@ boolean historical; /* whether to include in message history: True => yes */
                 Sprintf(qbuf, "Count: %ld", cnt);
                 backspaced = FALSE;
             }
-            /* bypassing pline() keeps intermediate prompt out of
-               DUMPLOG message history */
-            putstr(WIN_MESSAGE, 0, qbuf);
+            custompline(SUPPRESS_HISTORY, "%s", qbuf);
             mark_synch();
         }
     }
index ebde8b145eb58f258a2c66f0edb3d7f29bc1c0de..d7db3f43dde757f1eeccd9fc50b517183a33f035 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 pline.c $NHDT-Date: 1541719974 2018/11/08 23:32:54 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.69 $ */
+/* NetHack 3.6 pline.c $NHDT-Date: 1549327495 2019/02/05 00:44:55 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.73 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2018. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -9,6 +9,7 @@
 static unsigned pline_flags = 0;
 static char prevmsg[BUFSZ];
 
+static void FDECL(putmesg, (const char *));
 static char *FDECL(You_buf, (int));
 #if defined(MSGHANDLER) && (defined(POSIX_TYPES) || defined(__GNUC__))
 static void FDECL(execplinehandler, (const char *));
@@ -61,6 +62,23 @@ dumplogfreemessages()
 }
 #endif
 
+/* keeps windowprocs usage out of pline() */
+static void
+putmesg(line)
+const char *line;
+{
+    int attr = ATR_NONE;
+
+    if ((pline_flags & URGENT_MESSAGE) != 0
+        && (windowprocs.wincap2 & WC2_URGENT_MESG) != 0)
+        attr |= ATR_URGENT;
+    if ((pline_flags & SUPPRESS_HISTORY) != 0
+        && (windowprocs.wincap2 & WC2_SUPPRESS_HIST) != 0)
+        attr |= ATR_NOHISTORY;
+
+    putstr(WIN_MESSAGE, attr, line);
+}
+
 /* Note that these declarations rely on knowledge of the internals
  * of the variable argument handling stuff in "tradstdc.h"
  */
@@ -156,8 +174,9 @@ VA_DECL(const char *, line)
     no_repeat = (pline_flags & PLINE_NOREPEAT) ? TRUE : FALSE;
     if ((pline_flags & OVERRIDE_MSGTYPE) == 0) {
         msgtyp = msgtype_type(line, no_repeat);
-        if (msgtyp == MSGTYP_NOSHOW
-            || (msgtyp == MSGTYP_NOREP && !strcmp(line, prevmsg)))
+        if ((pline_flags & URGENT_MESSAGE) == 0
+            && (msgtyp == MSGTYP_NOSHOW
+                || (msgtyp == MSGTYP_NOREP && !strcmp(line, prevmsg))))
             /* FIXME: we need a way to tell our caller that this message
              * was suppressed so that caller doesn't set iflags.last_msg
              * for something that hasn't been shown, otherwise a subsequent
@@ -173,7 +192,7 @@ VA_DECL(const char *, line)
     if (u.ux)
         flush_screen(1); /* %% */
 
-    putstr(WIN_MESSAGE, 0, line);
+    putmesg(line);
 
 #if defined(MSGHANDLER) && (defined(POSIX_TYPES) || defined(__GNUC__))
     execplinehandler(line);
index 5233e1525e0198803786753c6320dc28eb399442..15ed6097f457e3101b4c894bf3bf34a7a0f83e73 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 topl.c  $NHDT-Date: 1540934784 2018/10/30 21:26:24 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.38 $ */
+/* NetHack 3.6 topl.c  $NHDT-Date: 1549327499 2019/02/05 00:44:59 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.43 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Michael Allison, 2009. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -16,7 +16,6 @@
 
 STATIC_DCL void FDECL(redotoplin, (const char *));
 STATIC_DCL void FDECL(topl_putsym, (CHAR_P));
-STATIC_DCL void NDECL(remember_topl);
 STATIC_DCL void FDECL(removetopl, (int));
 STATIC_DCL void FDECL(msghistory_snapshot, (BOOLEAN_P));
 STATIC_DCL void FDECL(free_msghistory_snapshot, (BOOLEAN_P));
@@ -144,7 +143,23 @@ const char *str;
         more();
 }
 
-STATIC_OVL void
+/* for use by tty_putstr() */
+void
+show_topl(str)
+const char *str;
+{
+    struct WinDesc *cw = wins[WIN_MESSAGE];
+
+    if (!(cw->flags & WIN_STOP)) {
+        cw->curx = cw->cury = 0;
+        home();
+        cl_end();
+        addtopl(str);
+    }
+}
+
+/* used by update_topl(); also by tty_putstr() */
+void
 remember_topl()
 {
     register struct WinDesc *cw = wins[WIN_MESSAGE];
@@ -231,7 +246,8 @@ register const char *bp;
     /* If there is room on the line, print message on same line */
     /* But messages like "You die..." deserve their own line */
     n0 = strlen(bp);
-    if ((ttyDisplay->toplin == 1 || (cw->flags & WIN_STOP)) && cw->cury == 0
+    if ((ttyDisplay->toplin == 1 || (cw->flags & WIN_STOP))
+        && cw->cury == 0
         && n0 + (int) strlen(toplines) + 3 < CO - 8 /* room for --More-- */
         && (notdied = strncmp(bp, "You die", 7)) != 0) {
         Strcat(toplines, "  ");
index 0cdb63ab536dcfffcd5f521a1de481f021eabaf3..939a325529e22d9870891c3122dcaa5428593dac 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 wintty.c        $NHDT-Date: 1545705819 2018/12/25 02:43:39 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.190 $ */
+/* NetHack 3.6 wintty.c        $NHDT-Date: 1549327503 2019/02/05 00:45:03 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.193 $ */
 /* Copyright (c) David Cohrs, 1991                                */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -96,7 +96,7 @@ struct window_procs tty_procs = {
      | WC2_HILITE_STATUS | WC2_HITPOINTBAR | WC2_FLUSH_STATUS
      | WC2_RESET_STATUS
 #endif
-     | WC2_DARKGRAY),
+     | WC2_DARKGRAY | WC2_SUPPRESS_HIST),
     tty_init_nhwindows, tty_player_selection, tty_askname, tty_get_nh_event,
     tty_exit_nhwindows, tty_suspend_nhwindows, tty_resume_nhwindows,
     tty_create_nhwindow, tty_clear_nhwindow, tty_display_nhwindow,
@@ -2574,13 +2574,29 @@ const char *str;
     print_vt_code2(AVTC_SELECT_WINDOW, window);
 
     switch (cw->type) {
-    case NHW_MESSAGE:
+    case NHW_MESSAGE: {
+        int suppress_history = (attr & ATR_NOHISTORY);
+
+        /* in case we ever support display attributes for topline
+           messages, clear flag mask leaving only display attr */
+        /*attr &= ~(ATR_URGENT | ATR_NOHISTORY);*/
+
         /* really do this later */
 #if defined(USER_SOUNDS) && defined(WIN32CON)
         play_sound_for_message(str);
 #endif
-        update_topl(str);
+        if (!suppress_history) {
+            /* normal output; add to current top line if room, else flush
+               whatever is there to history and then write this */
+            update_topl(str);
+        } else {
+            /* put anything already on top line into history */
+            remember_topl();
+            /* write to top line without remembering what we're writing */
+            show_topl(str);
+        }
         break;
+    }
 #ifndef STATUS_HILITES
     case NHW_STATUS:
         ob = &cw->data[cw->cury][j = cw->curx];