]> Git Repo - qemu.git/commitdiff
qemu-io: add command completion
authorStefan Hajnoczi <[email protected]>
Thu, 14 Nov 2013 10:54:18 +0000 (11:54 +0100)
committerKevin Wolf <[email protected]>
Wed, 22 Jan 2014 11:07:17 +0000 (12:07 +0100)
Autocomplete qemu-io commands at the interactive prompt.

Note this only completes command names and not their options.

Signed-off-by: Stefan Hajnoczi <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
include/qemu-io.h
qemu-io-cmds.c
qemu-io.c

index a418b46a409ebb8f15018323d34fa29cdfb5e737..7e7c07c09ba0a90bd9f035ad3b5383ae8181303d 100644 (file)
@@ -42,5 +42,8 @@ bool qemuio_command(BlockDriverState *bs, const char *cmd);
 
 void qemuio_add_command(const cmdinfo_t *ci);
 int qemuio_command_usage(const cmdinfo_t *ci);
+void qemuio_complete_command(const char *input,
+                             void (*fn)(const char *cmd, void *opaque),
+                             void *opaque);
 
 #endif /* QEMU_IO_H */
index 85e4982bd802c1c7e07ffb9e2522df8d9a4da3e7..6dfb4a51aea73b232f9206a8230bd92382e66210 100644 (file)
@@ -94,6 +94,21 @@ static const cmdinfo_t *find_command(const char *cmd)
     return NULL;
 }
 
+/* Invoke fn() for commands with a matching prefix */
+void qemuio_complete_command(const char *input,
+                             void (*fn)(const char *cmd, void *opaque),
+                             void *opaque)
+{
+    cmdinfo_t *ct;
+    size_t input_len = strlen(input);
+
+    for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) {
+        if (strncmp(input, ct->name, input_len) == 0) {
+            fn(ct->name, opaque);
+        }
+    }
+}
+
 static char **breakline(char *input, int *count)
 {
     int c = 0;
index d7c26d3ed0b68ad927963ef8087a12bc1a7a9d64..fdc46a97e805ca6dcac5c2d298bb5253adb11f9e 100644 (file)
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -236,9 +236,15 @@ static void readline_func(void *opaque, const char *str, void *readline_opaque)
     *line = g_strdup(str);
 }
 
+static void completion_match(const char *cmd, void *opaque)
+{
+    readline_add_completion(readline_state, cmd);
+}
+
 static void readline_completion_func(void *opaque, const char *str)
 {
-    /* No command or argument completion implemented yet */
+    readline_set_completion_index(readline_state, strlen(str));
+    qemuio_complete_command(str, completion_match, NULL);
 }
 
 static char *fetchline_readline(void)
This page took 0.03118 seconds and 4 git commands to generate.