From 463b67e23ebe42134a1cf0f62569b7c772e9ed66 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Tue, 17 Mar 2026 06:56:38 -0400 Subject: Channel tab completion for the [server] screen. --- src/complete.c | 48 ++++++++++++++++++++++++++++++++++++++---------- src/complete.h | 1 + src/edbox.c | 5 +++++ src/edbox.h | 3 +++ src/irc.c | 1 + 5 files changed, 48 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/complete.c b/src/complete.c index 0ac00a7..f7ec731 100644 --- a/src/complete.c +++ b/src/complete.c @@ -16,26 +16,41 @@ static char search_pos = 0, in_progress = 0; static char prefix[33]; char comp_pm_nicks[MAX_PM_NICKS][25]; +char comp_pm_chans[MAX_PM_NICKS][25]; char (*list)[25] = comp_pm_nicks; +char (*add_to)[25] = comp_pm_nicks; static char pm_nick_pos = 0; /* insertion point for _add() */ -void comp_add_pm_nick(const char *n) { +static void add_list(const char *n) { int i; for(i = 0; i < 25; i++) - if(strncmp(n, comp_pm_nicks[i], 24) == 0) - return; + if(strncmp(n, add_to[i], 24) == 0) + return; /* we already got this one */ - strncpy(comp_pm_nicks[pm_nick_pos], n, 24); + strncpy(add_to[pm_nick_pos], n, 24); pm_nick_pos++; pm_nick_pos %= MAX_PM_NICKS; } +void comp_add_pm_nick(const char *n) { + add_to = comp_pm_nicks; + add_list(n); +} + +void comp_add_pm_chan(const char *n) { + add_to = comp_pm_chans; + add_list(n); +} + char match(const char *p, const char *q) { int len; - len = strlen(prefix); + while(*p == '#') p++; + while(*q == '#') q++; + + len = strlen(p); if(!len) return 0; while(len--) { @@ -55,27 +70,40 @@ void comp_continue(void) { while(search_pos < MAX_PM_NICKS) { if(match(prefix, list[search_pos])) { edbox_set(list[search_pos]); + edbox_space(); search_pos++; return; } search_pos++; } - edbox_set(prefix); + edbox_set(prefix); /* no space here */ comp_complete_done(); } void comp_start(void) { - if(scr_current != SCR_PRIV) + char *p; + + if(scr_current == SCR_SERVER) { + p = last_chan; + list = comp_pm_chans; + } else if(scr_current == SCR_PRIV) { + p = last_pm_nick; + list = comp_pm_nicks; + } else { + /* channel screens not yet supported */ return; + } - /* just insert the last nick if there's nothing to search for */ + /* just insert the last nick/chan if there's nothing to search for */ if(!edbox_len) { - if(*last_pm_nick) edbox_set(last_pm_nick); + if(*p) { + edbox_set(p); + edbox_space(); + } } else { in_progress = COMP_PM; search_pos = 0; strncpy(prefix, edit_box, 24); - list = comp_pm_nicks; comp_continue(); } } diff --git a/src/complete.h b/src/complete.h index 4b0663b..d344eac 100644 --- a/src/complete.h +++ b/src/complete.h @@ -1,3 +1,4 @@ void comp_complete(void); void comp_complete_done(void); void comp_add_pm_nick(const char *n); +void comp_add_pm_chan(const char *n); diff --git a/src/edbox.c b/src/edbox.c index 5d529d3..2bb1cef 100644 --- a/src/edbox.c +++ b/src/edbox.c @@ -272,6 +272,11 @@ void edbox_keystroke(void) { show_cursor(); } +void edbox_space(void) { + edit_box[edbox_len++] = ' '; + edbox_pos = edbox_len; +} + void edbox_set(char *contents) { edbox_clear(); while(*contents) { diff --git a/src/edbox.h b/src/edbox.h index 4863407..181f17f 100644 --- a/src/edbox.h +++ b/src/edbox.h @@ -28,3 +28,6 @@ extern void (*edbox_callback)(void); /* set edit box contents (clears out whatever was there) */ void edbox_set(char *contents); + +/* append a space to the edit box */ +void edbox_space(void); diff --git a/src/irc.c b/src/irc.c index 7611cef..4a69784 100644 --- a/src/irc.c +++ b/src/irc.c @@ -498,6 +498,7 @@ void select_screen(void) { s = scr_getbyname(msg_dest); if(!s) { strncpy(last_chan, msg_dest, 32); + comp_add_pm_chan(last_chan); s = SCR_SERVER; } } else { -- cgit v1.2.3