GNU readline and key bindings

折月煮酒 提交于 2019-12-31 01:43:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!