Match windows by substring in /window

This could just iterate over idNames instead, but using complete
means more recently used windows will match first.
master
C. McEnroe 2021-06-17 18:43:26 -04:00
parent a8c1f02976
commit 0d888b88d0
4 changed files with 25 additions and 4 deletions

View File

@ -1,4 +1,4 @@
.Dd May 28, 2021
.Dd June 17, 2021
.Dt CATGIRL 1
.Os
.
@ -521,8 +521,9 @@ Temporarily remove a message highlight pattern.
Temporarily remove a message ignore pattern.
.It Ic /window
List all windows.
.It Ic /window Ar name
Switch to window by name.
.It Ic /window Ar name | substring
Switch to window by name
or matching substring.
.It Ic /window Ar num | Ic / Ns Ar num
Switch to window by number.
.El

1
chat.h
View File

@ -360,6 +360,7 @@ char *editBuffer(size_t *pos);
void editCompleteAdd(void);
const char *complete(uint id, const char *prefix);
const char *completeSubstr(uint id, const char *substr);
void completeAccept(void);
void completeReject(void);
void completeAdd(uint id, const char *str, enum Color color);

View File

@ -379,7 +379,17 @@ static void commandWindow(uint id, char *params) {
uiShowNum(strtoul(params, NULL, 10));
} else {
id = idFind(params);
if (id) uiShowID(id);
if (id) {
uiShowID(id);
return;
}
for (const char *match; (match = completeSubstr(None, params));) {
id = idFind(match);
if (!id) continue;
completeAccept();
uiShowID(id);
break;
}
}
}

View File

@ -119,6 +119,15 @@ const char *complete(uint id, const char *prefix) {
return NULL;
}
const char *completeSubstr(uint id, const char *substr) {
for (match = (match ? match->next : head); match; match = match->next) {
if (match->id && match->id != id) continue;
if (!strcasestr(match->str, substr)) continue;
return match->str;
}
return NULL;
}
void completeAccept(void) {
if (match) prepend(detach(match));
match = NULL;