Use complete to abbreviate commands

master
C. McEnroe 2020-02-07 21:53:50 -05:00
parent fe5fd89705
commit b200194206
2 changed files with 12 additions and 1 deletions

View File

@ -118,6 +118,12 @@ Log in with the server password
.El
.
.Sh COMMANDS
Any unique prefix can be used to abbreviate a command.
For example,
.Ic /join
can be typed
.Ic /j .
.
.Ss Chat Commands
.Bl -tag -width Ds
.It Ic /join Ar channel

View File

@ -125,7 +125,12 @@ void command(size_t id, char *input) {
} else if (input[0] == '/' && isdigit(input[1])) {
commandWindow(id, &input[1]);
} else {
char *cmd = strsep(&input, " ");
const char *cmd = strsep(&input, " ");
const char *unique = complete(None, cmd);
if (unique && !complete(None, cmd)) {
cmd = unique;
completeReject();
}
const struct Handler *handler = bsearch(
cmd, Commands, ARRAY_LEN(Commands), sizeof(*handler), compar
);