fixes github issue #190 - EDIT_GETLIN for curses

Fixes #190

Add EDIT_GETLIN support for curses.  It remains disabled by default.
This commit is contained in:
PatR
2019-05-18 23:52:04 -07:00
parent 8aac36c073
commit d1ce0aac89
3 changed files with 28 additions and 10 deletions
+3 -1
View File
@@ -1,4 +1,4 @@
$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.7 $ $NHDT-Date: 1558234580 2019/05/19 02:56:20 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.8 $ $NHDT-Date: 1558248715 2019/05/19 06:51:55 $
This fixes36.3 file is here to capture information about updates in the 3.6.x This fixes36.3 file is here to capture information about updates in the 3.6.x
lineage following the release of 3.6.2 in May 2019. Please note, however, lineage following the release of 3.6.2 in May 2019. Please note, however,
@@ -33,6 +33,8 @@ curses: when all available lines in the message window are in use,
leaving part of longer underlying line's text visible leaving part of longer underlying line's text visible
curses: if message window is only one line, cancelling some prompts with ESC curses: if message window is only one line, cancelling some prompts with ESC
left the prompts visible on the message line instead of erasing them left the prompts visible on the message line instead of erasing them
curses: support EDIT_GETLIN (but like with tty, it's disabled by default) to
pre-load an earlier response as the default answer for some prompts
Windows: some startup error messages were not being delivered successfully Windows: some startup error messages were not being delivered successfully
+10 -4
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 config.h $NHDT-Date: 1447728911 2015/11/17 02:55:11 $ $NHDT-Branch: master $:$NHDT-Revision: 1.91 $ */ /* NetHack 3.6 config.h $NHDT-Date: 1558248715 2019/05/19 06:51:55 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.122 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2016. */ /*-Copyright (c) Robert Patrick Rankin, 2016. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -526,9 +526,15 @@ typedef unsigned char uchar;
* probably not useful for normal play */ * probably not useful for normal play */
/* #define EXTRA_SANITY_CHECKS */ /* #define EXTRA_SANITY_CHECKS */
/* EDIT_GETLIN makes the string input in TTY, Qt4, and X11 /* EDIT_GETLIN makes the string input in TTY, curses, Qt4, and X11
so some prompts will remember the previously input text for some prompts be pre-loaded with previously input text (from
(within the same session) */ a previous instance of the same prompt) as the default response.
In some cases, the previous instance can only be within the same
session; in others, such as #annotate, the previous input can be
from any session because the response is saved and restored with
the map. The 'edit' capability is just <delete> or <backspace>
to strip off characters at the end, or <escape> to discard the
whole thing, then type a new end for the text. */
/* #define EDIT_GETLIN */ /* #define EDIT_GETLIN */
/* #define DUMPLOG */ /* End-of-game dump logs */ /* #define DUMPLOG */ /* End-of-game dump logs */
+15 -5
View File
@@ -448,15 +448,14 @@ curses_message_win_getline(const char *prompt, char *answer, int buffer)
int ch; int ch;
WINDOW *win = curses_get_nhwin(MESSAGE_WIN); WINDOW *win = curses_get_nhwin(MESSAGE_WIN);
int border_space = 0; int border_space = 0;
int len = 0; /* of answer string */ int len; /* of answer string */
boolean border = curses_window_has_border(MESSAGE_WIN); boolean border = curses_window_has_border(MESSAGE_WIN);
*answer = '\0';
orig_cursor = curs_set(0); orig_cursor = curs_set(0);
curses_get_window_size(MESSAGE_WIN, &height, &width); curses_get_window_size(MESSAGE_WIN, &height, &width);
if (border) { if (border) {
height -= 2, width -= 2; /* height -= 2, width -= 2; -- sizes already account for border */
border_space = 1; border_space = 1;
if (mx < 1) if (mx < 1)
mx = 1; mx = 1;
@@ -470,10 +469,21 @@ curses_message_win_getline(const char *prompt, char *answer, int buffer)
maxlines = buffer / width * 2; maxlines = buffer / width * 2;
Strcpy(tmpbuf, prompt); Strcpy(tmpbuf, prompt);
Strcat(tmpbuf, " "); Strcat(tmpbuf, " ");
p_answer = tmpbuf + strlen(tmpbuf);
#ifdef EDIT_GETLIN
len = (int) strlen(answer);
if (len >= buffer) {
len = buffer - 1;
answer[len] = '\0';
}
Strcpy(p_answer, answer);
#else
len = 0;
*answer = '\0';
#endif
nlines = curses_num_lines(tmpbuf, width); nlines = curses_num_lines(tmpbuf, width);
maxlines += nlines * 2; maxlines += nlines * 2;
linestarts = (char **) alloc((unsigned) (maxlines * sizeof (char *))); linestarts = (char **) alloc((unsigned) (maxlines * sizeof (char *)));
p_answer = tmpbuf + strlen(tmpbuf);
linestarts[0] = tmpbuf; linestarts[0] = tmpbuf;
if (mx > border_space) { /* newline */ if (mx > border_space) { /* newline */
@@ -531,7 +541,7 @@ curses_message_win_getline(const char *prompt, char *answer, int buffer)
wmove(win, my, mx); wmove(win, my, mx);
curs_set(1); curs_set(1);
wrefresh(win); wrefresh(win);
curses_got_input(); /* despite its name, before rathre than after... */ curses_got_input(); /* despite its name, before rather than after... */
#ifdef PDCURSES #ifdef PDCURSES
ch = wgetch(win); ch = wgetch(win);
#else #else