GNU readline 和键绑定

Sas*_*asQ 3 gnu readline key-bindings

我从 GNU getline 文档中读到它能够将某些回调函数绑定到某些键。我已经知道如何TAB使用rl_bind_key函数将操作绑定到按键。

但是我如何使用它来将某些操作绑定到以下键?: CTRL+ TAB, ESC, PAUSE/BREAK

小智 5

#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> ");
     }
}
Run Code Online (Sandbox Code Playgroud)

如果您正在运行 GNU 系统(或其变体之一),则运行:

info readline "command line editing" "introduction" # notation convention
info readline "programming" "readline" "biding" # biding functions
Run Code Online (Sandbox Code Playgroud)