]> granicus.if.org Git - nethack/commitdiff
tty autocomplete
authorcohrs <cohrs>
Thu, 12 Dec 2002 06:16:39 +0000 (06:16 +0000)
committercohrs <cohrs>
Thu, 12 Dec 2002 06:16:39 +0000 (06:16 +0000)
Change tty extended command autocomplete, based loosely on <Someone>'s
patch, to allow you to type autocompleted characters.  That is, you can type
characters the autocompleter inserted without invalidating the command.
I haven't looked closely, but at least some other windowport extended
command readers seem to already behave similarly.

doc/fixes34.1
win/tty/getline.c

index 69d39ee535f5a5882d665a1d129b45138b02c3ce..09c926a55e5dff11eb0e5c9da3ff787830549aae 100644 (file)
@@ -371,6 +371,7 @@ tty: support terms where turning off inverse video turns off color too
 tty: object selection at --More-- prompt after '?' didn't work anymore
 unix: install recover command into GAMEDIR by default
 vms: prevent error() from indirectly triggering hangup save during forced exit
+tty: ext command autocomplete now lets you enter auto-completed characters
 
 
 General New Features
index 7dd3dbf3b2c3bb2099c8cdb59c20d04f6474e222..a62f8764c66bdc3dc130b7035153fb488d7cd2d1 100644 (file)
@@ -59,7 +59,6 @@ getlin_hook_proc hook;
                Sprintf(toplines, "%s ", query);
                Strcat(toplines, obufp);
                if((c = Getchar()) == EOF) {
-                       *bufp = 0;
                        break;
                }
                if(c == '\033') {
@@ -101,34 +100,46 @@ getlin_hook_proc hook;
                }
                if(c == erase_char || c == '\b') {
                        if(bufp != obufp) {
+                               char *i;
+
                                bufp--;
-                               putsyms("\b \b");/* putsym converts \b */
+                               putsyms("\b");
+                               for (i = bufp; *i; ++i) putsyms(" ");
+                               for (; i > bufp; --i) putsyms("\b");
+                               *bufp = 0;
                        } else  tty_nhbell();
 #if defined(apollo)
                } else if(c == '\n' || c == '\r') {
 #else
                } else if(c == '\n') {
 #endif
-                       *bufp = 0;
                        break;
                } else if(' ' <= (unsigned char) c && c != '\177' &&
                            (bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO)) {
                                /* avoid isprint() - some people don't have it
                                   ' ' is not always a printing char */
+                       char *i = eos(bufp);
+
                        *bufp = c;
                        bufp[1] = 0;
                        putsyms(bufp);
                        bufp++;
                        if (hook && (*hook)(obufp)) {
                            putsyms(bufp);
-                           bufp = eos(bufp);
+                           /* pointer and cursor left where they were */
+                           for (i = bufp; *i; ++i) putsyms("\b");
+                       } else if (i > bufp) {
+                           char *s = i;
+
+                           /* erase rest of prior guess */
+                           for (; i > bufp; --i) putsyms(" ");
+                           for (; s > bufp; --s) putsyms("\b");
                        }
                } else if(c == kill_char || c == '\177') { /* Robert Viduya */
                                /* this test last - @ might be the kill_char */
-                       while(bufp != obufp) {
-                               bufp--;
-                               putsyms("\b \b");
-                       }
+                       for (; *bufp; ++bufp) putsyms(" ");
+                       for (; bufp != obufp; --bufp) putsyms("\b \b");
+                       *bufp = 0;
                } else
                        tty_nhbell();
        }