summary refs log tree commit diff
path: root/input.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-08-18 20:17:08 -0400
committerJune McEnroe <june@causal.agency>2018-08-18 20:17:08 -0400
commite3a344854f91a834ec2bb1a7dd1904e3f294c421 (patch)
tree157ec438fadda944d75c20a3affd548ffd7500f8 /input.c
parentFix /query error handling (diff)
downloadcatgirl-e3a344854f91a834ec2bb1a7dd1904e3f294c421.tar.gz
catgirl-e3a344854f91a834ec2bb1a7dd1904e3f294c421.zip
Accept unique prefixes of commands
Diffstat (limited to 'input.c')
-rw-r--r--input.c28
1 files 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) {