From ed39497b2159ca664c165dc3896be20bfb626d54 Mon Sep 17 00:00:00 2001 From: cohrs Date: Thu, 12 Dec 2002 06:16:39 +0000 Subject: [PATCH] tty autocomplete Change tty extended command autocomplete, based loosely on '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 | 1 + win/tty/getline.c | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/doc/fixes34.1 b/doc/fixes34.1 index 69d39ee53..09c926a55 100644 --- a/doc/fixes34.1 +++ b/doc/fixes34.1 @@ -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 diff --git a/win/tty/getline.c b/win/tty/getline.c index 7dd3dbf3b..a62f8764c 100644 --- a/win/tty/getline.c +++ b/win/tty/getline.c @@ -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(); } -- 2.40.0