From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Luiz Capitulino <lcapitulino@redhat.com>
Subject: [Qemu-devel] [PATCH 5/5] qemu-io: add command completion
Date: Thu, 14 Nov 2013 11:54:18 +0100 [thread overview]
Message-ID: <1384426458-24700-6-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1384426458-24700-1-git-send-email-stefanha@redhat.com>
Autocomplete qemu-io commands at the interactive prompt.
Note this only completes command names and not their options.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
include/qemu-io.h | 3 +++
qemu-io-cmds.c | 15 +++++++++++++++
qemu-io.c | 8 +++++++-
3 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/include/qemu-io.h b/include/qemu-io.h
index a418b46..7e7c07c 100644
--- a/include/qemu-io.h
+++ b/include/qemu-io.h
@@ -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 */
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 667f4e4..30c23c2 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -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;
diff --git a/qemu-io.c b/qemu-io.c
index d7c26d3..fdc46a9 100644
--- 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)
--
1.8.3.1
next prev parent reply other threads:[~2013-11-14 10:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-14 10:54 [Qemu-devel] [PATCH 0/5] qemu-io: readline command completion Stefan Hajnoczi
2013-11-14 10:54 ` [Qemu-devel] [PATCH 1/5] readline: decouple readline from the monitor Stefan Hajnoczi
2013-11-14 10:54 ` [Qemu-devel] [PATCH 2/5] readline: move readline to a generic location Stefan Hajnoczi
2013-11-14 10:54 ` [Qemu-devel] [PATCH 3/5] osdep: add qemu_set_tty_echo() Stefan Hajnoczi
2013-11-29 10:04 ` Kevin Wolf
2013-11-29 10:13 ` Kevin Wolf
2013-12-02 14:23 ` Stefan Hajnoczi
2013-11-14 10:54 ` [Qemu-devel] [PATCH 4/5] qemu-io: use readline.c Stefan Hajnoczi
2013-11-14 10:54 ` Stefan Hajnoczi [this message]
2013-11-28 1:28 ` [Qemu-devel] [PATCH 0/5] qemu-io: readline command completion Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1384426458-24700-6-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=kwolf@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).