X11's yn_function() echoing its response

X11_yn_function() issues a pline() to put the prompt and player's
response into the message window.  Change it to use visctrl() to
make sure that the response character is ledgible when something
like the '&' command allows an arbitrary answer.

This patch adds a leading space and two extra trailing spaces
to the prompt when it's being issued via popup, but that hasn't
affected the issue mentioned next....

The popup prompting when the 'slow' resource is False doesn't
always resize properly.  I saw both too wide and too narrow
[What do you want to throw? [abc] ]b
[       In what direction?        ]
and
[Really quit? [yn] (n) ]y
[Dump core? [ynq] (q) ]n   (size seemed right, but hard to tell)
[Do you want your posses]  (might have shown one more letter;
                            resize doodad in window's bottom right
                            corner on OSX oscures the rightmost
                            column--which is ordinarily a space)
The truncated one did accept responses.  If I answered 'n' then
the next question was truncated too, but for 'y' (plus ensuing
feedback) it would be sized correctly for the question after that.

To be clear:  the popup width issue was present before this change
and is still present after it.  The code already has a hack that's
intended to deal with this but it doesn't do the job for me.
This commit is contained in:
PatR
2021-02-15 19:09:00 -08:00
parent 8fff588ab3
commit 31b0847bd7
3 changed files with 44 additions and 19 deletions

View File

@@ -1,4 +1,4 @@
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.453 $ $NHDT-Date: 1613292825 2021/02/14 08:53:45 $
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.454 $ $NHDT-Date: 1613444931 2021/02/16 03:08:51 $
General Fixes and Modified Features
-----------------------------------
@@ -533,6 +533,8 @@ X11: for text map without color, add support for black&white ice; draw it in
inverse video to distinguish from ordinary floor
X11: if perm_invent is set in NETHACKOPTIONS or config file, start with the
persistent inventory window displayed
X11: use visctrl(response) when X11_yn_function() echoes prompt+response in
message window
X11+OSX: after the "bad Atom" fix (below), the persistent inventory window
crept downward every time it got updated

View File

@@ -7,3 +7,9 @@ When persistent inventory window is displayed, an update that ought to
make it grow won't do so even if there is room on the screen for that.
It will add scrollbar(s) when not already there, and it can be resized
manually.
When the 'slow' resource is off, popup yn_function sometimes doesn't
resize to fit the prompt properly. There's a hack to set the label
text twice with comment suggesting that it's there to deal with this,
but it isn't adequate to fix the problem.

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 winX.c $NHDT-Date: 1613292827 2021/02/14 08:53:47 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.97 $ */
/* NetHack 3.7 winX.c $NHDT-Date: 1613444929 2021/02/16 03:08:49 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.98 $ */
/* Copyright (c) Dean Luick, 1992 */
/* NetHack may be freely redistributed. See license for details. */
@@ -2123,9 +2123,10 @@ release_yn_widgets(void)
/* X11-specific edition of yn_function(), the routine called by the core
to show a prompt and get a single keystroke answer, often 'y' vs 'n' */
char
X11_yn_function(const char *ques,
const char *choices, /* string of possible response chars; any char if Null */
char def) /* default response if user hits <space> or <return> */
X11_yn_function(
const char *ques, /* prompt text */
const char *choices, /* allowed response chars; any char if Null */
char def) /* default if user hits <space> or <return> */
{
char buf[BUFSZ];
Arg args[4];
@@ -2161,11 +2162,15 @@ X11_yn_function(const char *ques,
if ((cb = index(choicebuf, '\033')) != 0)
*cb = '\0';
/* ques [choices] (def) */
if ((int) (1 + strlen(ques) + 2 + strlen(choicebuf) + 4) >= BUFSZ)
panic("X11_yn_function: question too long");
(void) strncpy(buf, ques, QBUFSZ - 1);
buf[QBUFSZ - 1] = '\0';
Sprintf(eos(buf), " [%s]", choicebuf);
int ln = ((int) strlen(ques) /* prompt text */
+ 3 /* " []" */
+ (int) strlen(choicebuf) /* choices within "[]" */
+ 4 /* " (c)" */
+ 1 /* a trailing space */
+ 1); /* \0 terminator */
if (ln >= BUFSZ)
panic("X11_yn_function: question too long (%d)", ln);
Snprintf(buf, sizeof buf, "%.*s [%s]", QBUFSZ - 1, ques, choicebuf);
if (def)
Sprintf(eos(buf), " (%c)", def);
Strcat(buf, " ");
@@ -2175,11 +2180,23 @@ X11_yn_function(const char *ques,
: index(choices, 'n') ? 'n'
: def);
} else {
if ((int) (1 + strlen(ques) + 1) >= BUFSZ)
panic("X11_yn_function: question too long");
int ln = ((int) strlen(ques) /* prompt text */
+ 1 /* a trailing space */
+ 1); /* \0 terminator */
if (ln >= BUFSZ)
panic("X11_yn_function: question too long (%d)", ln);
Strcpy(buf, ques);
Strcat(buf, " ");
}
/* for popup-style, add some extra elbow room to the prompt to
enhance its visibility; there's no cursor shown, just the text */
if (!appResources.slow) {
char buf2[BUFSZ];
/* insert one leading space and two extra trailing spaces */
Strcpy(buf2, buf);
Snprintf(buf, sizeof buf, " %s ", buf2);
}
/*
* The 'slow' resource is misleadingly named. When it is True, we
@@ -2245,19 +2262,19 @@ X11_yn_function(const char *ques,
yn_getting_num = FALSE;
(void) x_event(EXIT_ON_EXIT); /* get keystroke(s) */
/* erase and then remove the prompt */
num_args = 0;
XtSetArg(args[num_args], XtNlabel, " "); num_args++;
XtSetValues(yn_label, args, num_args);
if (appResources.slow) {
/* keystrokes now belong to the map */
input_func = 0;
/* erase the prompt */
num_args = 0;
XtSetArg(args[num_args], XtNlabel, " "); num_args++;
XtSetValues(yn_label, args, num_args);
input_func = 0; /* keystrokes now belong to the map */
highlight_yn(FALSE); /* disguise yn_label as part of map */
} else {
nh_XtPopdown(yn_popup); /* this removes the event grab */
}
pline("%s%c", buf, (yn_return != '\033') ? yn_return : '\0');
char *p = trimspaces(buf); /* remove !slow's extra whitespace */
pline("%s %s", p, (yn_return == '\033') ? "ESC" : visctrl(yn_return));
return yn_return;
}