]> granicus.if.org Git - nethack/commitdiff
fixes github issue #190 - EDIT_GETLIN for curses
authorPatR <rankin@nethack.org>
Sun, 19 May 2019 06:52:04 +0000 (23:52 -0700)
committerPatR <rankin@nethack.org>
Sun, 19 May 2019 06:52:04 +0000 (23:52 -0700)
Fixes #190

Add EDIT_GETLIN support for curses.  It remains disabled by default.

doc/fixes36.3
include/config.h
win/curses/cursmesg.c

index 28a908a0681c7a93aa3f18317d5c27f71669e68d..8d5c223768ede4a5bac5b18023cf75126f22c89d 100644 (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
 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
 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
+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
 
 
index 3177512e1697a2cbf6a70730c03c6ceaa5ca9db2..1fa760d90e50a771b251699aeda31f0ad1ad8888 100644 (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) Robert Patrick Rankin, 2016. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -526,9 +526,15 @@ typedef unsigned char uchar;
  * probably not useful for normal play */
 /* #define EXTRA_SANITY_CHECKS */
 
-/* EDIT_GETLIN makes the string input in TTY, Qt4, and X11
-   so some prompts will remember the previously input text
-   (within the same session) */
+/* EDIT_GETLIN makes the string input in TTY, curses, Qt4, and X11
+   for some prompts be pre-loaded with previously input text (from
+   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 DUMPLOG */  /* End-of-game dump logs */
index a32b6824bf6e9cb12430682d690e7d46603fcc01..4daf1784bfcf60960eb86c0502a3788cffa2bd06 100644 (file)
@@ -448,15 +448,14 @@ curses_message_win_getline(const char *prompt, char *answer, int buffer)
     int ch;
     WINDOW *win = curses_get_nhwin(MESSAGE_WIN);
     int border_space = 0;
-    int len = 0; /* of answer string */
+    int len; /* of answer string */
     boolean border = curses_window_has_border(MESSAGE_WIN);
 
-    *answer = '\0';
     orig_cursor = curs_set(0);
 
     curses_get_window_size(MESSAGE_WIN, &height, &width);
     if (border) {
-        height -= 2, width -= 2;
+        /* height -= 2, width -= 2; -- sizes already account for border */
         border_space = 1;
         if (mx < 1)
             mx = 1;
@@ -470,10 +469,21 @@ curses_message_win_getline(const char *prompt, char *answer, int buffer)
     maxlines = buffer / width * 2;
     Strcpy(tmpbuf, prompt);
     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);
     maxlines += nlines * 2;
     linestarts = (char **) alloc((unsigned) (maxlines * sizeof (char *)));
-    p_answer = tmpbuf + strlen(tmpbuf);
     linestarts[0] = tmpbuf;
 
     if (mx > border_space) { /* newline */
@@ -531,7 +541,7 @@ curses_message_win_getline(const char *prompt, char *answer, int buffer)
         wmove(win, my, mx);
         curs_set(1);
         wrefresh(win);
-        curses_got_input(); /* despite its name, before rathre than after... */
+        curses_got_input(); /* despite its name, before rather than after... */
 #ifdef PDCURSES
         ch = wgetch(win);
 #else