zoukankan      html  css  js  c++  java
  • 实现类似于shell中按“向上”,“向下”箭头的功能————readline库

    [转载] 正确编译使用readline库

    The GNU Readline library provides a set of functions for use by applications that allow users to edit command lines as they are typed in. Both Emacs and vi editing modes are available. The Readline library includes additional functions to maintain a list of previously-entered command lines, to recall and perhaps reedit those lines, and perform csh-like history expansion on previous commands.

    This function gives the user the default behaviour of TAB completion: completion on file names. If you do not want Readline to complete on filenames, you can change the binding of the TAB key with rl_bind_key().

    int rl_bind_key (int key, rl_command_func_t *function);

    rl_bind_key() takes two arguments: key is the character that you want to bind, and function is the address of the function to call when key is pressed. Binding TAB to rl_insert() makes TAB insert itself. rl_bind_key() returns non-zero if key is not a valid ASCII character code (between 0 and 255).

    Thus, to disable the default TAB behavior, the following suffices:

    rl_bind_key ('\t', rl_insert);

    This code should be executed once at the start of your program; you might write a function called initialize_readline() which performs this and other desired initializations, such as installing custom completers.

    ------------------------------------------------------------

    GNU Readline Offical Site:
    http://cnswww.cns.cwru.edu/~chet/readline/rltop.html

    If you want to use GNU Readline library in your program:

    * 1st, include <readline/readline.h> and <readline/history.h>
    * 2nd, invoke readline function such as char *readline (const char *prompt); add_history (line);
    * 3rd, link source file with -lreadline -ltermcap arguments


    Trackback: http://tb.donews.net/TrackBack.aspx?PostId=71391

    $ gcc readInput.c
    readline.c:2: fatal error: readline/readline.h: No such file or directory
    compilation terminated.

    If you come across this error, you must install readline dev package
    $ sudo apt-get install libreadline6 libreadline6-dev

  • 相关阅读:
    CentOS 静态IP设置&修改网卡名
    Centos 6.5 升级python到版本2.7.12
    VMware 安装Windows sever 2008 R2服务器
    RF安装
    Python的包管理工具pip
    Appium学习路—Android定位元素与操作
    MYSQL ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.10.210' (111) 解决方法
    MYSQL ERROR 1045 (28000): Access denied for user (using password: YES)解决方案详细说明
    CentOS下Apache默认安装路径
    Apache JMeter配置、安装
  • 原文地址:https://www.cnblogs.com/pswzone/p/2446796.html
Copyright © 2011-2022 走看看