mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-09 12:54:23 +01:00
* keyedit.c (command_generator, keyedit_completion) [HAVE_LIBREADLINE]:
New functions to enable command completion in the --edit-key menu. (keyedit_menu): Call them here.
This commit is contained in:
parent
9c3484924b
commit
c249809a6b
@ -1,3 +1,10 @@
|
|||||||
|
2005-03-18 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
|
* keyedit.c (command_generator, keyedit_completion)
|
||||||
|
[HAVE_LIBREADLINE]: New functions to enable command completion in
|
||||||
|
the --edit-key menu.
|
||||||
|
(keyedit_menu): Call them here.
|
||||||
|
|
||||||
2005-03-17 David Shaw <dshaw@jabberwocky.com>
|
2005-03-17 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
* getkey.c (get_seckey_byname2): If no explicit default key is
|
* getkey.c (get_seckey_byname2): If no explicit default key is
|
||||||
|
@ -26,7 +26,10 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#ifdef HAVE_LIBREADLINE
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <readline/readline.h>
|
||||||
|
#endif
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
@ -1405,6 +1408,49 @@ static struct
|
|||||||
{ NULL, cmdNONE, 0, NULL }
|
{ NULL, cmdNONE, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBREADLINE
|
||||||
|
|
||||||
|
/* These two functions are used by readline for command completion. */
|
||||||
|
|
||||||
|
static char *command_generator(const char *text,int state)
|
||||||
|
{
|
||||||
|
static int list_index,len;
|
||||||
|
const char *name;
|
||||||
|
|
||||||
|
/* If this is a new word to complete, initialize now. This includes
|
||||||
|
saving the length of TEXT for efficiency, and initializing the
|
||||||
|
index variable to 0. */
|
||||||
|
if(!state)
|
||||||
|
{
|
||||||
|
list_index=0;
|
||||||
|
len=strlen(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the next partial match */
|
||||||
|
while((name=cmds[list_index].name))
|
||||||
|
{
|
||||||
|
/* Only complete commands that have help text */
|
||||||
|
if(cmds[list_index++].desc && strncmp(name,text,len)==0)
|
||||||
|
return strdup(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char **keyedit_completion(const char *text, int start, int end)
|
||||||
|
{
|
||||||
|
/* If we are at the start of a line, we try and command-complete.
|
||||||
|
If not, just do nothing for now. */
|
||||||
|
|
||||||
|
if(start==0)
|
||||||
|
return rl_completion_matches(text,command_generator);
|
||||||
|
|
||||||
|
rl_attempted_completion_over=1;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
keyedit_menu( const char *username, STRLIST locusr,
|
keyedit_menu( const char *username, STRLIST locusr,
|
||||||
STRLIST commands, int quiet, int seckey_check )
|
STRLIST commands, int quiet, int seckey_check )
|
||||||
@ -1522,9 +1568,12 @@ keyedit_menu( const char *username, STRLIST locusr,
|
|||||||
else
|
else
|
||||||
have_commands = 0;
|
have_commands = 0;
|
||||||
}
|
}
|
||||||
if( !have_commands ) {
|
if( !have_commands )
|
||||||
|
{
|
||||||
|
tty_enable_completion(keyedit_completion);
|
||||||
answer = cpr_get_no_help("keyedit.prompt", _("Command> "));
|
answer = cpr_get_no_help("keyedit.prompt", _("Command> "));
|
||||||
cpr_kill_prompt();
|
cpr_kill_prompt();
|
||||||
|
tty_disable_completion();
|
||||||
}
|
}
|
||||||
trim_spaces(answer);
|
trim_spaces(answer);
|
||||||
} while( *answer == '#' );
|
} while( *answer == '#' );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user