tty EDIT_GETLIN fix for wrapped prompt

When a getlin() response is being typed, it wraps to second line if
the cursor tries to go past COLNO-1, but if a previous response is
treated as part of the prompt, using pline() to write prompt+space+text
wraps at a whole word boundary.  tty's getlin() assumes that the screen
position can be derived from that prompt+space+text_so_far but that
doesn't match if wrapping at a word boundary leaves blank space at end
of the top line.

When a prompt is accompanied by default answer, output the answer
separately instead of pretending it is part of the prompt.  Line-wrap
should occur at same point as when it was originally typed and avoid
the confusion about how far to back up when deleting characters.

This hasn't been exhaustively tested but it seems to work correctly
for ordinary input, input erased one character at a time, and input
killed all at once.  One thing which definitely hasn't been tested is
having the prompt itself be so long that it needs to wrap.
This commit is contained in:
PatR
2018-04-13 04:32:05 -07:00
parent 22cc37ed61
commit 77da2fdc65
2 changed files with 14 additions and 4 deletions

View File

@@ -632,6 +632,10 @@ gas spore explosion killing a gas spore which triggers a recursive explosion
if multiple bands of blank lines were squeezed out of DUMPLOG's map, spurious
blank lines appeared in the final map output
cursor positioning autodescribe of a statue while hallucinating was blank
tty+EDIT_GETLIN: if prompt plus existing output buffer contents (result of
a prior getlin() used as default input) was long enough to wrap to
second line, the wrap point could be different from when the previous
input was typed, resulting it strange erase-char/kill-chars behavior
Platform- and/or Interface-Specific Fixes

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 getline.c $NHDT-Date: 1522796701 2018/04/03 23:05:01 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.34 $ */
/* NetHack 3.6 getline.c $NHDT-Date: 1523619111 2018/04/13 11:31:51 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.35 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -56,13 +56,19 @@ getlin_hook_proc hook;
cw->flags &= ~WIN_STOP;
ttyDisplay->toplin = 3; /* special prompt state */
ttyDisplay->inread++;
/* issue the prompt */
custompline(OVERRIDE_MSGTYPE | SUPPRESS_HISTORY, "%s ", query);
#ifdef EDIT_GETLIN
custompline(OVERRIDE_MSGTYPE | SUPPRESS_HISTORY, "%s %s", query, bufp);
/* bufp is input/output; treat current contents (presumed to be from
previous getlin()) as default input */
addtopl(obufp);
bufp = eos(obufp);
#else
custompline(OVERRIDE_MSGTYPE | SUPPRESS_HISTORY, "%s ", query);
*obufp = 0;
/* !EDIT_GETLIN: bufp is output only; init it to empty */
*bufp = '\0';
#endif
for (;;) {
(void) fflush(stdout);
Strcat(strcat(strcpy(toplines, query), " "), obufp);