tty autocomplete

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.
This commit is contained in:
cohrs
2002-12-12 06:16:39 +00:00
parent d013f95679
commit ed39497b21
2 changed files with 20 additions and 8 deletions
+1
View 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 tty: object selection at --More-- prompt after '?' didn't work anymore
unix: install recover command into GAMEDIR by default unix: install recover command into GAMEDIR by default
vms: prevent error() from indirectly triggering hangup save during forced exit 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 General New Features
+19 -8
View File
@@ -59,7 +59,6 @@ getlin_hook_proc hook;
Sprintf(toplines, "%s ", query); Sprintf(toplines, "%s ", query);
Strcat(toplines, obufp); Strcat(toplines, obufp);
if((c = Getchar()) == EOF) { if((c = Getchar()) == EOF) {
*bufp = 0;
break; break;
} }
if(c == '\033') { if(c == '\033') {
@@ -101,34 +100,46 @@ getlin_hook_proc hook;
} }
if(c == erase_char || c == '\b') { if(c == erase_char || c == '\b') {
if(bufp != obufp) { if(bufp != obufp) {
char *i;
bufp--; 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(); } else tty_nhbell();
#if defined(apollo) #if defined(apollo)
} else if(c == '\n' || c == '\r') { } else if(c == '\n' || c == '\r') {
#else #else
} else if(c == '\n') { } else if(c == '\n') {
#endif #endif
*bufp = 0;
break; break;
} else if(' ' <= (unsigned char) c && c != '\177' && } else if(' ' <= (unsigned char) c && c != '\177' &&
(bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO)) { (bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO)) {
/* avoid isprint() - some people don't have it /* avoid isprint() - some people don't have it
' ' is not always a printing char */ ' ' is not always a printing char */
char *i = eos(bufp);
*bufp = c; *bufp = c;
bufp[1] = 0; bufp[1] = 0;
putsyms(bufp); putsyms(bufp);
bufp++; bufp++;
if (hook && (*hook)(obufp)) { if (hook && (*hook)(obufp)) {
putsyms(bufp); 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 */ } else if(c == kill_char || c == '\177') { /* Robert Viduya */
/* this test last - @ might be the kill_char */ /* this test last - @ might be the kill_char */
while(bufp != obufp) { for (; *bufp; ++bufp) putsyms(" ");
bufp--; for (; bufp != obufp; --bufp) putsyms("\b \b");
putsyms("\b \b"); *bufp = 0;
}
} else } else
tty_nhbell(); tty_nhbell();
} }