From e3a344854f91a834ec2bb1a7dd1904e3f294c421 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sat, 18 Aug 2018 20:17:08 -0400 Subject: Accept unique prefixes of commands --- input.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/input.c b/input.c index 9bf29ac..4d34420 100644 --- a/input.c +++ b/input.c @@ -172,21 +172,31 @@ void input(struct Tag tag, char *input) { return; } - char *command = strsep(&input, " "); + char *word = strsep(&input, " "); if (input && !input[0]) input = NULL; - for (size_t i = 0; i < COMMANDS_LEN; ++i) { - if (strcasecmp(command, COMMANDS[i].command)) continue; - COMMANDS[i].handler(tag, input); - return; - } char *trail; - strtol(&command[1], &trail, 0); + strtol(&word[1], &trail, 0); if (!trail[0]) { - inputView(tag, &command[1]); + 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 { - uiFmt(TAG_STATUS, UI_WARM, "%s isn't a recognized command", command); + tabReject(); + } + + for (size_t i = 0; i < COMMANDS_LEN; ++i) { + if (strcasecmp(command, COMMANDS[i].command)) continue; + COMMANDS[i].handler(tag, input); + return; } + uiFmt(TAG_STATUS, UI_WARM, "%s isn't a recognized command", command); } void inputTab(void) { -- cgit 1.4.1