mirror of
https://github.com/troglobit/editline.git
synced 2025-10-16 23:18:08 +08:00
Add support for el_bind_key() and example usage binding '?' in examples/cli.c
This changeset refactors el_bind_key_in_metamap() into two functions, adding el_bind_key(), to provide the ability for the user to bind keys in both the regular and the meta-key maps. Several useful, but previously internal, functions have been made global to facilitate the example code mentioned above. These are likely useful to the user of this library as well: el_print_columns() - Display words in columns across a tty_cols wide screen. el_ring_bell() - Can be used as default key binding function. el_find_word() - Returns a copy of the word at rl_point.
This commit is contained in:
@@ -80,6 +80,28 @@ static int my_rl_list_possib(char *token, char ***av)
|
||||
return total;
|
||||
}
|
||||
|
||||
el_status_t list_possible(void)
|
||||
{
|
||||
char **av;
|
||||
char *word;
|
||||
int ac;
|
||||
|
||||
word = el_find_word();
|
||||
ac = rl_list_possib(word, &av);
|
||||
if (word)
|
||||
free(word);
|
||||
if (ac) {
|
||||
el_print_columns(ac, av);
|
||||
while (--ac >= 0)
|
||||
free(av[ac]);
|
||||
free(av);
|
||||
|
||||
return CSmove;
|
||||
}
|
||||
|
||||
return el_ring_bell();
|
||||
}
|
||||
|
||||
int main(int ac __attribute__ ((unused)), char *av[] __attribute__ ((unused)))
|
||||
{
|
||||
char *line;
|
||||
@@ -88,6 +110,7 @@ int main(int ac __attribute__ ((unused)), char *av[] __attribute__ ((unused)))
|
||||
/* Setup callbacks */
|
||||
rl_set_complete_func(&my_rl_complete);
|
||||
rl_set_list_possib_func(&my_rl_list_possib);
|
||||
el_bind_key('?', list_possible);
|
||||
read_history(HISTORY);
|
||||
|
||||
while ((line = readline(prompt)) != NULL) {
|
||||
|
Reference in New Issue
Block a user