From 6b0a4ed26a9197b18f983317c5deed53d2206f43 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sat, 16 Mar 2019 06:09:59 -0400 Subject: nick completion with Tab key --- src/features.h | 4 +++ src/fujichat.atr | Bin 92176 -> 92176 bytes src/fujichat.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++----- src/fujitest.atr | Bin 92176 -> 92176 bytes 4 files changed, 85 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/features.h b/src/features.h index 90f0cd9..822d8e7 100644 --- a/src/features.h +++ b/src/features.h @@ -28,6 +28,7 @@ #undef FEAT_ATRACT_AWAY #undef FEAT_KEYBOARD_BUFFER #undef FEAT_COLOR_COMMAND +#undef FEAT_NICK_COMPLETE #elif defined(FEAT_COL80_HACK) @@ -37,6 +38,7 @@ // #define FEAT_TRAFFIC_INDICATOR #define FEAT_KEYBOARD_BUFFER #define FEAT_COLOR_COMMAND +#undef FEAT_NICK_COMPLETE /* COL80 hack uses 9K of high RAM, so let's disable some bells & whistles. */ @@ -101,5 +103,7 @@ /* End of features */ +#define FEAT_NICK_COMPLETE + #endif #endif diff --git a/src/fujichat.atr b/src/fujichat.atr index df4ebd6..8a2a997 100644 Binary files a/src/fujichat.atr and b/src/fujichat.atr differ diff --git a/src/fujichat.c b/src/fujichat.c index 3d61a09..5d47387 100644 --- a/src/fujichat.c +++ b/src/fujichat.c @@ -136,6 +136,13 @@ struct telnet_state *tstate; /* ../apps/telnet.h */ struct timer vbell_timer; #endif +#ifdef FEAT_NICK_COMPLETE +#define NICK_LIST_SIZE 20 +void nick_completion(void); +void add_to_nick_list(char *); +static char nick_list[NICK_LIST_SIZE][NICKLEN+1]; +#endif + /*---------------------------------------------------------------------------*/ void main(void) { #ifdef FEAT_DYNAMIC_VERSION @@ -194,6 +201,8 @@ void main(void) { if(strcasecmp(cmdbuf, "d") == 0) { exit(0); + } else if(strcasecmp(cmdbuf, "r") == 0) { + (void)atari_exec("D:FUJICHAT.COM"); } else if(strcasecmp(cmdbuf, "s") == 0) { i = atari_exec(SETUP_FILENAME); printf("Error %d!\n", i); @@ -526,7 +535,11 @@ static void handle_keystroke(void) { c = NL; send_buf = 1; } else if(c == A_TAB) { +#ifdef FEAT_NICK_COMPLETE + nick_completion(); +#else c = TAB; +#endif } // #ifdef FEAT_COL80_HACK // else { col80_cursor(); } @@ -813,8 +826,16 @@ void do_msg() { output_buf[output_buf_len - 2] = A_EOL; output_buf[output_buf_len - 1] = '\0'; printf("* %s %s", nick, msg + 8); +#ifdef FEAT_NICK_COMPLETE + add_to_nick_list(nick); +#endif } else { printf("%s %s", nick, msg); +#ifdef FEAT_NICK_COMPLETE + nick++; + bang[0] = '\0'; + add_to_nick_list(nick); +#endif } } else { // privmsg, is to our nick @@ -1014,18 +1035,71 @@ void resolv_found(char *name, u16_t *ipaddr) { done = 1; } else { printf("%s is %s\n", name, format_ip((uip_ipaddr_t *)ipaddr)); - /* - printf("Found name '%s' = %d.%d.%d.%d\n", name, - htons(ipaddr[0]) >> 8, - htons(ipaddr[0]) & 0xff, - htons(ipaddr[1]) >> 8, - htons(ipaddr[1]) & 0xff); - */ if(!connected) (void)uip_connect((uip_ipaddr_t *)ipaddr, htons(config->server_port)); } } +#ifdef FEAT_NICK_COMPLETE +/* nick completion: if the cursor is at the end of a word, search backwards + to the previous space or the beginning of the line to find the start + of the search term. Then search for that term in the nick list. If + we find anything, truncate the input buffer at the start of the search + term, then append whatever we found. */ + +void add_to_nick_list(char *nick) { + int i; + for(i=0; i input_buf && start[-1] != ' ' && len < NICKLEN) { + start--; + len++; + fuji_putchar(A_BS); + } + if(len == 0) return; + input_buf_len -= len; + + for(i=0; i