GNU readline和键绑定 [英] GNU readline and key bindings
本文介绍了GNU readline和键绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从GNU getline文档中了解到,它能够将某些回调函数绑定到某些键.我已经知道如何使用rl_bind_key
函数将动作绑定到 TAB 键.
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.
但是如何使用它将某些操作绑定到以下键? CTRL + TAB , ESC , PAUSE / BREAK
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> ");
}
}
如果您正在运行GNU系统(或其变体之一),请运行:
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
这篇关于GNU readline和键绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文