开发者

GNU readline and key bindings

开发者 https://www.devze.com 2023-04-01 05:31 出处:网络
开发者_开发技巧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
开发者_开发技巧

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


#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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号