]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Add virshKeycodeNameCompleter
authorKristina Hanicova <khanicov@redhat.com>
Thu, 18 Feb 2021 18:11:22 +0000 (19:11 +0100)
committerJán Tomko <jtomko@redhat.com>
Fri, 19 Feb 2021 06:39:56 +0000 (07:39 +0100)
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
tools/virsh-completer-domain.c
tools/virsh-completer-domain.h
tools/virsh-domain.c

index fc4d7b2e5211f54de6091dc78a97ad16a2875cca..15993064fae60875267cf93edd302ba66153f5b3 100644 (file)
@@ -32,6 +32,9 @@
 #include "virperf.h"
 #include "virbitmap.h"
 #include "virkeycode.h"
+#include "virkeynametable_linux.h"
+#include "virkeynametable_osx.h"
+#include "virkeynametable_win32.h"
 
 char **
 virshDomainNameCompleter(vshControl *ctl,
@@ -800,3 +803,72 @@ virshCodesetNameCompleter(vshControl *ctl G_GNUC_UNUSED,
 
     return g_steal_pointer(&tmp);
 }
+
+
+char **
+virshKeycodeNameCompleter(vshControl *ctl,
+                          const vshCmd *cmd,
+                          unsigned int flags)
+{
+    g_auto(GStrv) tmp = NULL;
+    size_t i = 0;
+    size_t j = 0;
+    const char *codeset_option;
+    int codeset;
+    const char **names = NULL;
+    size_t len;
+
+    virCheckFlags(0, NULL);
+
+    if (vshCommandOptStringQuiet(ctl, cmd, "codeset", &codeset_option) <= 0)
+        codeset_option = "linux";
+
+    if (STREQ(codeset_option, "rfb"))
+        codeset_option = "qnum";
+
+    codeset = virKeycodeSetTypeFromString(codeset_option);
+
+    if (codeset < 0)
+        return NULL;
+
+    switch ((virKeycodeSet) codeset) {
+    case VIR_KEYCODE_SET_LINUX:
+        names = virKeyNameTable_linux;
+        len = virKeyNameTable_linux_len;
+        break;
+    case VIR_KEYCODE_SET_OSX:
+        names = virKeyNameTable_osx;
+        len = virKeyNameTable_osx_len;
+        break;
+    case VIR_KEYCODE_SET_WIN32:
+        names = virKeyNameTable_win32;
+        len = virKeyNameTable_win32_len;
+        break;
+    case VIR_KEYCODE_SET_XT:
+    case VIR_KEYCODE_SET_ATSET1:
+    case VIR_KEYCODE_SET_ATSET2:
+    case VIR_KEYCODE_SET_ATSET3:
+    case VIR_KEYCODE_SET_XT_KBD:
+    case VIR_KEYCODE_SET_USB:
+    case VIR_KEYCODE_SET_QNUM:
+    case VIR_KEYCODE_SET_LAST:
+        break;
+    }
+
+    if (!names)
+        return NULL;
+
+    tmp = g_new0(char *, len + 1);
+
+    for (i = 0; i < len; i++) {
+        if (!names[i])
+            continue;
+
+        tmp[j] = g_strdup(names[i]);
+        j++;
+    }
+
+    tmp = g_renew(char *, tmp, j + 1);
+
+    return g_steal_pointer(&tmp);
+}
index eb8d12455c5a3a07433d7c02da5fbc020280b60a..04a3705ff9a86c77d0c4ceccedd332921d92ce5a 100644 (file)
@@ -114,3 +114,7 @@ char ** virshDomainLifecycleActionCompleter(vshControl *ctl,
 char ** virshCodesetNameCompleter(vshControl *ctl,
                                   const vshCmd *cmd,
                                   unsigned int flags);
+
+char ** virshKeycodeNameCompleter(vshControl *ctl,
+                                  const vshCmd *cmd,
+                                  unsigned int flags);
index d40995f44db2ecff0eefa96092599ef89e7c7b49..df334676468ee9d69b354cdb7104c12b3e043336 100644 (file)
@@ -8802,6 +8802,7 @@ static const vshCmdOptDef opts_send_key[] = {
     {.name = "keycode",
      .type = VSH_OT_ARGV,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshKeycodeNameCompleter,
      .help = N_("the key code")
     },
     {.name = NULL}