Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU readline and key bindings

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

like image 587
SasQ Avatar asked Nov 26 '25 10:11

SasQ


1 Answers

#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
like image 140
xojoc Avatar answered Dec 01 '25 15:12

xojoc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!