tty prompting fix and DUMPLOG of prompts+answers
Update DUMPLOG's message history to include player responses to most queries. For tty, both getlin() and yn_function(). For other interfaces, only yn_function() is covered. (It's intercepted by a core routine that can take care of the logging; getlin() isn't.) Also includes saved messages from previous session(s), for the interfaces which support that (tty), to fill out the logging when a game ends shortly after a save/restore cycle. The tty interface was using pline() to display prompt strings. Having 'MSGTYPE=hide "#"' or 'MSGTYPE=hide "yn"' in .nethackrc would suppress many prompt strings (in the two examples mentioned, entering extended commands or the vast majority of yes/no questions, respectively) and generally lead to substantial confusion even if done intentionally, so switch to putstr(WIN_MESSAGE) instead.
This commit is contained in:
+33
-7
@@ -14,6 +14,7 @@
|
||||
#include "func_tab.h"
|
||||
|
||||
char morc = 0; /* tell the outside world what char you chose */
|
||||
STATIC_VAR boolean suppress_history;
|
||||
STATIC_DCL boolean FDECL(ext_cmd_getlin_hook, (char *));
|
||||
|
||||
typedef boolean FDECL((*getlin_hook_proc), (char *));
|
||||
@@ -35,6 +36,7 @@ tty_getlin(query, bufp)
|
||||
const char *query;
|
||||
register char *bufp;
|
||||
{
|
||||
suppress_history = FALSE;
|
||||
hooked_tty_getlin(query, bufp, (getlin_hook_proc) 0);
|
||||
}
|
||||
|
||||
@@ -48,13 +50,20 @@ getlin_hook_proc hook;
|
||||
register int c;
|
||||
struct WinDesc *cw = wins[WIN_MESSAGE];
|
||||
boolean doprev = 0;
|
||||
char tmpbuf[BUFSZ]; /* [QBUFSZ+1] should suffice */
|
||||
|
||||
if (ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP))
|
||||
more();
|
||||
cw->flags &= ~WIN_STOP;
|
||||
ttyDisplay->toplin = 3; /* special prompt state */
|
||||
ttyDisplay->inread++;
|
||||
pline("%s ", query);
|
||||
/*
|
||||
* This used to use pline("%s ", query), but that made getline
|
||||
* prompts be susceptible to suppression via the MSGTYPE mechanism.
|
||||
* Having 'MSGTYPE=hide "# "' was particularly confusing.
|
||||
*/
|
||||
Sprintf(tmpbuf, "%s ", query);
|
||||
tty_putstr(WIN_MESSAGE, 0, tmpbuf);
|
||||
*obufp = 0;
|
||||
for (;;) {
|
||||
(void) fflush(stdout);
|
||||
@@ -82,6 +91,7 @@ getlin_hook_proc hook;
|
||||
if (c == '\020') { /* ctrl-P */
|
||||
if (iflags.prevmsg_window != 's') {
|
||||
int sav = ttyDisplay->inread;
|
||||
|
||||
ttyDisplay->inread = 0;
|
||||
(void) tty_doprev_message();
|
||||
ttyDisplay->inread = sav;
|
||||
@@ -136,9 +146,9 @@ getlin_hook_proc hook;
|
||||
#endif /* not NEWAUTOCOMP */
|
||||
break;
|
||||
} else if (' ' <= (unsigned char) c && c != '\177'
|
||||
/* avoid isprint() - some people don't have it
|
||||
' ' is not always a printing char */
|
||||
&& (bufp - obufp < BUFSZ - 1 && bufp - obufp < COLNO)) {
|
||||
/* avoid isprint() - some people don't have it
|
||||
' ' is not always a printing char */
|
||||
#ifdef NEWAUTOCOMP
|
||||
char *i = eos(bufp);
|
||||
|
||||
@@ -166,7 +176,7 @@ getlin_hook_proc hook;
|
||||
#endif /* NEWAUTOCOMP */
|
||||
}
|
||||
} else if (c == kill_char || c == '\177') { /* Robert Viduya */
|
||||
/* this test last - @ might be the kill_char */
|
||||
/* this test last - @ might be the kill_char */
|
||||
#ifndef NEWAUTOCOMP
|
||||
while (bufp != obufp) {
|
||||
bufp--;
|
||||
@@ -185,6 +195,17 @@ getlin_hook_proc hook;
|
||||
ttyDisplay->toplin = 2; /* nonempty, no --More-- required */
|
||||
ttyDisplay->inread--;
|
||||
clear_nhwindow(WIN_MESSAGE); /* clean up after ourselves */
|
||||
|
||||
if (suppress_history) {
|
||||
/* prevent next message from pushing current query+answer into
|
||||
tty message history */
|
||||
*toplines = '\0';
|
||||
#ifdef DUMPLOG
|
||||
} else {
|
||||
/* needed because we've bypassed pline() */
|
||||
dumplogmsg(toplines);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -267,9 +288,14 @@ tty_get_ext_cmd()
|
||||
|
||||
if (iflags.extmenu)
|
||||
return extcmd_via_menu();
|
||||
/* maybe a runtime option? */
|
||||
/* hooked_tty_getlin("#", buf, flags.cmd_comp ? ext_cmd_getlin_hook :
|
||||
* (getlin_hook_proc) 0); */
|
||||
|
||||
suppress_history = TRUE;
|
||||
/* maybe a runtime option?
|
||||
* hooked_tty_getlin("#", buf,
|
||||
* (flags.cmd_comp && !in_doagain)
|
||||
* ? ext_cmd_getlin_hook
|
||||
* : (getlin_hook_proc) 0);
|
||||
*/
|
||||
hooked_tty_getlin("#", buf, in_doagain ? (getlin_hook_proc) 0
|
||||
: ext_cmd_getlin_hook);
|
||||
(void) mungspaces(buf);
|
||||
|
||||
+32
-9
@@ -331,6 +331,7 @@ register int n;
|
||||
|
||||
extern char erase_char; /* from xxxtty.c; don't need kill_char */
|
||||
|
||||
/* returns a single keystroke; also sets 'yn_number' */
|
||||
char
|
||||
tty_yn_function(query, resp, def)
|
||||
const char *query, *resp;
|
||||
@@ -354,6 +355,7 @@ char def;
|
||||
boolean doprev = 0;
|
||||
char prompt[BUFSZ];
|
||||
|
||||
yn_number = 0L;
|
||||
if (ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP))
|
||||
more();
|
||||
cw->flags &= ~WIN_STOP;
|
||||
@@ -383,11 +385,14 @@ char def;
|
||||
/* not pline("%s ", prompt);
|
||||
trailing space is wanted here in case of reprompt */
|
||||
Strcat(prompt, " ");
|
||||
pline("%s", prompt);
|
||||
/* pline("%s", prompt); -- see comment in hooked_tty_getlin() */
|
||||
tty_putstr(WIN_MESSAGE, 0, prompt);
|
||||
} else {
|
||||
/* no restriction on allowed response, so always preserve case */
|
||||
/* preserve_case = TRUE; -- moot since we're jumping to the end */
|
||||
pline("%s ", query);
|
||||
/* pline("%s ", query); -- see above about tty_getlin() */
|
||||
Sprintf(prompt, "%s ", query);
|
||||
tty_putstr(WIN_MESSAGE, 0, prompt);
|
||||
q = readchar();
|
||||
goto clean_up;
|
||||
}
|
||||
@@ -444,6 +449,7 @@ char def;
|
||||
char z, digit_string[2];
|
||||
int n_len = 0;
|
||||
long value = 0;
|
||||
|
||||
addtopl("#"), n_len++;
|
||||
digit_string[1] = '\0';
|
||||
if (q != '#') {
|
||||
@@ -491,11 +497,16 @@ char def;
|
||||
}
|
||||
} while (!q);
|
||||
|
||||
if (q != '#') {
|
||||
Sprintf(rtmp, "%c", q);
|
||||
addtopl(rtmp);
|
||||
}
|
||||
clean_up:
|
||||
clean_up:
|
||||
if (yn_number)
|
||||
Sprintf(rtmp, "#%ld", yn_number);
|
||||
else
|
||||
(void) key2txt(q, rtmp);
|
||||
/* addtopl(rtmp); -- rewrite toplines instead */
|
||||
Sprintf(toplines, "%s%s", prompt, rtmp);
|
||||
#ifdef DUMPLOG
|
||||
dumplogmsg(toplines);
|
||||
#endif
|
||||
ttyDisplay->inread--;
|
||||
ttyDisplay->toplin = 2;
|
||||
if (ttyDisplay->intr)
|
||||
@@ -636,6 +647,9 @@ boolean restoring_msghist;
|
||||
{
|
||||
static boolean initd = FALSE;
|
||||
int idx;
|
||||
#ifdef DUMPLOG
|
||||
extern unsigned saved_pline_index; /* pline.c */
|
||||
#endif
|
||||
|
||||
if (restoring_msghist && !initd) {
|
||||
/* we're restoring history from the previous session, but new
|
||||
@@ -645,18 +659,27 @@ boolean restoring_msghist;
|
||||
restored ones are being put into place */
|
||||
msghistory_snapshot(TRUE);
|
||||
initd = TRUE;
|
||||
#ifdef DUMPLOG
|
||||
/* this suffices; there's no need to scrub saved_pline[] pointers */
|
||||
saved_pline_index = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (msg) {
|
||||
/* move most recent message to history, make this become most recent
|
||||
*/
|
||||
/* move most recent message to history, make this become most recent */
|
||||
remember_topl();
|
||||
Strcpy(toplines, msg);
|
||||
#ifdef DUMPLOG
|
||||
dumplogmsg(toplines);
|
||||
#endif
|
||||
} else if (snapshot_mesgs) {
|
||||
/* done putting arbitrary messages in; put the snapshot ones back */
|
||||
for (idx = 0; snapshot_mesgs[idx]; ++idx) {
|
||||
remember_topl();
|
||||
Strcpy(toplines, snapshot_mesgs[idx]);
|
||||
#ifdef DUMPLOG
|
||||
dumplogmsg(toplines);
|
||||
#endif
|
||||
}
|
||||
/* now release the snapshot */
|
||||
free_msghistory_snapshot(TRUE);
|
||||
|
||||
Reference in New Issue
Block a user