aboutsummaryrefslogtreecommitdiff
path: root/src/complete.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2026-03-17 06:56:38 -0400
committerB. Watson <urchlay@slackware.uk>2026-03-17 06:57:14 -0400
commit463b67e23ebe42134a1cf0f62569b7c772e9ed66 (patch)
tree946118ff11adc6525ceb0760cfd3aa22bb706338 /src/complete.c
parentded1053f8b525e78d1121fd7f0a764ec5cc8cc05 (diff)
downloadfujinet-chat-463b67e23ebe42134a1cf0f62569b7c772e9ed66.tar.gz
Channel tab completion for the [server] screen.
Diffstat (limited to 'src/complete.c')
-rw-r--r--src/complete.c48
1 files changed, 38 insertions, 10 deletions
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();
}
}