virsh: Add virshKeycodeNameCompleter

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>
This commit is contained in:
Kristina Hanicova 2021-02-18 19:11:22 +01:00 committed by Ján Tomko
parent 6a8451c506
commit b0f4cf25a6
3 changed files with 77 additions and 0 deletions

View 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);
}

View 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);

View 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}