From: Sam Dennis Newsgroups: rec.games.roguelike.nethack Subject: [Patch] More intelligent autocomplete Date: Fri, 8 Nov 2002 23:59:17 +0000 (UTC) Organization: A (very) poorly-installed InterNetNews site Lines: 109 Message-ID: References: <3dc9a4b0$1@duster.adelaide.on.net> User-Agent: slrn/0.9.7.4 (Linux) NNTP-Posting-Host: dial-62-64-208-73.access.uk.tiscali.com X-Trace: 9 Nov 2002 00:03:13 GMT, dial-62-64-208-73.access.uk.tiscali.com Path: reader1.news.jippii.net!feeder1.news.jippii.net!news.cc.tut.fi!newsfeed.media.kyoto-u.ac.jp!newsfeed.gamma.ru!Gamma.RU!kibo.news.demon.net!demon!mk-nntp-1.news.uk.worldonline.com!localhost.loopback!not-for-mail Xref: reader1.news.jippii.net rec.games.roguelike.nethack:111455 Jukka Lahtinen wrote: > Seraph writes: >> Jukka Lahtinen wrote in >> > It completes the command when there's only one possible command that >> > begins with what you already typed after the #. >> >> My point was that if I type in "#ad" the program shouldnt spit out >> "#adjustd" it should have the brains to not enter characters if they are >> the next ones in sequence after the autocomplete feature does its thing. > > Yes, the autocomplete could be improved there. > (Anybody out there to write a patch..?) Your wish is my command: (tty only, because that's all I ever use) Index: nethack/win/tty/getline.c diff -u nethack/win/tty/getline.c:1.3 nethack/win/tty/getline.c:1.3.6.2 --- nethack/win/tty/getline.c:1.3 Sat Oct 19 03:21:54 2002 +++ nethack/win/tty/getline.c Fri Nov 8 23:55:46 2002 @@ -59,6 +59,7 @@ Sprintf(toplines, "%s ", query); Strcat(toplines, obufp); if((c = Getchar()) == EOF) { + bufp = eos(bufp); *bufp = 0; break; } @@ -101,30 +102,43 @@ } if(c == erase_char || c == '\b') { if(bufp != obufp) { + int i; + bufp--; - putsyms("\b \b");/* putsym converts \b */ + putsyms("\b"); + for (i = bufp; i < eos(bufp); i++) + putsyms(" "); + for (i = eos(bufp); 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 = eos(bufp); *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 */ + int i; + *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 = eos(bufp); i > bufp; i--) + putsyms("\b"); } } else if(c == kill_char || c == '\177') { /* Robert Viduya */ /* this test last - @ might be the kill_char */ + bufp = eos(bufp); while(bufp != obufp) { bufp--; putsyms("\b \b"); @@ -162,7 +176,7 @@ /* * Implement extended command completion by using this hook into - * tty_getlin. Check the characters already typed, if they uniquely + * tty_getlin. Check the characters already typed, if they * identify an extended command, expand the string to the whole * command. * @@ -176,20 +190,13 @@ ext_cmd_getlin_hook(base) char *base; { - int oindex, com_index; + int oindex; - com_index = -1; for (oindex = 0; extcmdlist[oindex].ef_txt != (char *)0; oindex++) { if (!strncmpi(base, extcmdlist[oindex].ef_txt, strlen(base))) { - if (com_index == -1) /* no matches yet */ - com_index = oindex; - else /* more than 1 match */ - return FALSE; + Strcpy(base, extcmdlist[oindex].ef_txt); + return TRUE; } - } - if (com_index >= 0) { - Strcpy(base, extcmdlist[com_index].ef_txt); - return TRUE; } return FALSE; /* didn't match anything */ -- ++acr@,ka"