mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
tools: Pass opaque data in vshCompleter and introduce autoCompleteOpaque
This patch changes the signature of vshCompleters, allowing to pass along some data that we might want to along with the completers; for example, we might want to pass the autocomplete vshControl along with the completer, in case the completer requires a connection to libvirtd. Signed-off-by: Nishith Shah <nishithshah.2211@gmail.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
f8435a434a
commit
cbbaa17faf
11
tools/vsh.c
11
tools/vsh.c
@ -64,6 +64,11 @@
|
||||
# define SA_SIGINFO 0
|
||||
#endif
|
||||
|
||||
#ifdef WITH_READLINE
|
||||
/* For autocompletion */
|
||||
void *autoCompleteOpaque;
|
||||
#endif
|
||||
|
||||
/* NOTE: It would be much nicer to have these two as part of vshControl
|
||||
* structure, unfortunately readline doesn't support passing opaque data
|
||||
* and only relies on static data accessible from the user-side callback
|
||||
@ -2808,7 +2813,8 @@ vshReadlineParse(const char *text, int state)
|
||||
res = vshReadlineOptionsGenerator(sanitized_text, state, cmd);
|
||||
} else if (non_bool_opt_exists && data_complete && opt->completer) {
|
||||
if (!completed_list)
|
||||
completed_list = opt->completer(opt->completer_flags);
|
||||
completed_list = opt->completer(autoCompleteOpaque,
|
||||
opt->completer_flags);
|
||||
if (completed_list) {
|
||||
while ((completed_name = completed_list[completed_list_index])) {
|
||||
completed_list_index++;
|
||||
@ -2858,6 +2864,9 @@ vshReadlineInit(vshControl *ctl)
|
||||
char *histsize_env = NULL;
|
||||
const char *histsize_str = NULL;
|
||||
|
||||
/* Opaque data for autocomplete callbacks. */
|
||||
autoCompleteOpaque = ctl;
|
||||
|
||||
/* Allow conditional parsing of the ~/.inputrc file.
|
||||
* Work around ancient readline 4.1 (hello Mac OS X),
|
||||
* which declared it as 'char *' instead of 'const char *'.
|
||||
|
@ -123,7 +123,7 @@ typedef struct _vshCmdOpt vshCmdOpt;
|
||||
typedef struct _vshCmdOptDef vshCmdOptDef;
|
||||
typedef struct _vshControl vshControl;
|
||||
|
||||
typedef char **(*vshCompleter)(unsigned int flags);
|
||||
typedef char **(*vshCompleter)(void *opaque, unsigned int flags);
|
||||
|
||||
/*
|
||||
* vshCmdInfo -- name/value pair for information about command
|
||||
|
Loading…
Reference in New Issue
Block a user