Accept unique prefixes of commands

master
Curtis McEnroe 2018-08-18 20:17:08 -04:00
parent c1e0128803
commit e3a344854f
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
1 changed files with 19 additions and 9 deletions

26
input.c
View File

@ -172,22 +172,32 @@ void input(struct Tag tag, char *input) {
return; return;
} }
char *command = strsep(&input, " "); char *word = strsep(&input, " ");
if (input && !input[0]) input = NULL; if (input && !input[0]) input = NULL;
char *trail;
strtol(&word[1], &trail, 0);
if (!trail[0]) {
inputView(tag, &word[1]);
return;
}
const char *command = word;
const char *uniq = tabNext(TAG_NONE, command);
if (uniq && uniq == tabNext(TAG_NONE, command)) {
command = uniq;
tabAccept();
} else {
tabReject();
}
for (size_t i = 0; i < COMMANDS_LEN; ++i) { for (size_t i = 0; i < COMMANDS_LEN; ++i) {
if (strcasecmp(command, COMMANDS[i].command)) continue; if (strcasecmp(command, COMMANDS[i].command)) continue;
COMMANDS[i].handler(tag, input); COMMANDS[i].handler(tag, input);
return; return;
} }
char *trail;
strtol(&command[1], &trail, 0);
if (!trail[0]) {
inputView(tag, &command[1]);
} else {
uiFmt(TAG_STATUS, UI_WARM, "%s isn't a recognized command", command); uiFmt(TAG_STATUS, UI_WARM, "%s isn't a recognized command", command);
} }
}
void inputTab(void) { void inputTab(void) {
for (size_t i = 0; i < COMMANDS_LEN; ++i) { for (size_t i = 0; i < COMMANDS_LEN; ++i) {