aboutsummaryrefslogtreecommitdiff
path: root/monitor.c
diff options
context:
space:
mode:
authorHani Benhabiles <kroosec@gmail.com>2014-05-07 23:41:27 +0100
committerLuiz Capitulino <lcapitulino@redhat.com>2014-05-15 15:16:01 -0400
commit29136cd8a4883f2ce97387f3a01c156ac1c43869 (patch)
treee607863f84c29b48f1f7cc31715e04a1bcdfec3a /monitor.c
parent87a560c455dfc53c151f7f5dd4a305f6d44e00dd (diff)
monitor: Convert sendkey to use command_completion.
Signed-off-by: Hani Benhabiles <hani@linux.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'monitor.c')
-rw-r--r--monitor.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/monitor.c b/monitor.c
index 9af6b0ad66..cb9b2c25bb 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4376,6 +4376,28 @@ void object_del_completion(ReadLineState *rs, int nb_args, const char *str)
qapi_free_ObjectPropertyInfoList(start);
}
+void sendkey_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+ int i;
+ char *sep;
+ size_t len;
+
+ if (nb_args != 2) {
+ return;
+ }
+ sep = strrchr(str, '-');
+ if (sep) {
+ str = sep + 1;
+ }
+ len = strlen(str);
+ readline_set_completion_index(rs, len);
+ for (i = 0; i < Q_KEY_CODE_MAX; i++) {
+ if (!strncmp(str, QKeyCode_lookup[i], len)) {
+ readline_add_completion(rs, QKeyCode_lookup[i]);
+ }
+ }
+}
+
static void monitor_find_completion_by_table(Monitor *mon,
const mon_cmd_t *cmd_table,
char **args,
@@ -4444,15 +4466,7 @@ static void monitor_find_completion_by_table(Monitor *mon,
break;
case 's':
case 'S':
- if (!strcmp(cmd->name, "sendkey")) {
- char *sep = strrchr(str, '-');
- if (sep)
- str = sep + 1;
- readline_set_completion_index(mon->rs, strlen(str));
- for (i = 0; i < Q_KEY_CODE_MAX; i++) {
- cmd_completion(mon, str, QKeyCode_lookup[i]);
- }
- } else if (!strcmp(cmd->name, "help|?")) {
+ if (!strcmp(cmd->name, "help|?")) {
monitor_find_completion_by_table(mon, cmd_table,
&args[1], nb_args - 1);
}