curses EDIT_GETLIN - discarding preloaded answer

EDIT_GETLIN is more complicated on curses than on tty due to way that
long lines are handled....

Using ESC to get rid of the default response removed it from the
answer buffer but didn't erase back to the end of actual prompt,
making it look as if it was still there.  Fixing that for a one-line
prompt+answer was needed and would have been easy but it also needs to
be prepared to go back to prior lines.  Both the prompt and the answer
could conceivably span lines although in practice it will usually just
be one line or else prompt+answer combined spanning to a second line.

This hasn't been exhaustively tested been seems to be working correctly.
This commit is contained in:
PatR
2019-06-09 07:07:34 -07:00
parent 56d16fc7ee
commit 319dcf4746
2 changed files with 27 additions and 4 deletions

View File

@@ -469,7 +469,7 @@ curses_message_win_getline(const char *prompt, char *answer, int buffer)
int maxy, maxx; /* linewrap / scroll */
int ch;
int border_space = 0;
int len; /* of answer string */
int ltmp, len; /* of answer string */
boolean border = curses_window_has_border(MESSAGE_WIN);
WINDOW *win = curses_get_nhwin(MESSAGE_WIN);
@@ -531,9 +531,30 @@ curses_message_win_getline(const char *prompt, char *answer, int buffer)
my--;
}
}
mvwaddstr(win, my, mx, linestarts[nlines - 1]);
mx = promptx = (int) strlen(linestarts[nlines - 1]) + border_space;
promptline = nlines - 1;
mvwaddstr(win, my, mx, linestarts[promptline]);
ltmp = (int) strlen(linestarts[promptline]);
mx = promptx = ltmp + border_space;
#ifdef EDIT_GETLIN
if (len <= ltmp) {
/* preloaded answer fits on same line as [last line of] prompt */
promptx -= len;
} else {
int ltmp2 = len;
/* preloaded answer spans lines so will be trickier to erase
if that is called for; find where the end of the prompt will
be without the answer appended */
while (ltmp2 > 0) {
ltmp2 -= ltmp;
promptline -= 1;
ltmp = (int) strlen(linestarts[promptline]);
}
if (ltmp2 < 0)
ltmp = -ltmp2;
promptx = ltmp + border_space;
}
#endif
while (1) {
mx = (int) strlen(linestarts[nlines - 1]) + border_space;