问题
I've read from the GNU getline documentation that it's capable for binding some callback functions to some keys. I know already how to bind an action to the TAB key using rl_bind_key
function.
But how can I use it to bind some action to the following keys?: CTRL + TAB, ESC, PAUSE/BREAK
回答1:
#include <stdio.h>
#include <readline/readline.h>
int my_cool_readline_func (int count, int key) {
printf ("key pressed: %d\n", key);
rl_on_new_line ();
return 0;
}
int main(void) {
rl_command_func_t my_cool_readline_func;
rl_bind_key ('\t', my_cool_readline_func);
rl_bind_key (27, my_cool_readline_func); /* ascii code for ESC */
rl_bind_keyseq ("\\C-a", my_cool_readline_func);
while (1) {
char *line = readline ("rl> ");
}
}
If your are running a GNU system (or one of its variants) then run:
info readline "command line editing" "introduction" # notation convention
info readline "programming" "readline" "biding" # biding functions
来源:https://stackoverflow.com/questions/7257737/gnu-readline-and-key-bindings