接口十分简单,readline和addhistory:

#include <stdlib.h>

#include <stdio.h>

#include <unistd.h>

#include <readline/readline.h>

#include <readline/history.h>





int main()

{

    char* input, shell_prompt[100];





    // Configure readline to auto-complete paths when the tab key is hit.

    rl_bind_key('\t', rl_complete);





    for(;;) {

        // Create prompt string from user name and current working directory.

        snprintf(shell_prompt, sizeof(shell_prompt), "%s:%s $ ", getenv("USER"), getcwd(NULL, 1024));





        // Display prompt and read input (n.b. input must be freed after use)...

        input = readline(shell_prompt);





        // Check for EOF.

        if (!input)

            break;





        // Add input to history.

        add_history(input);





        // Do stuff...





        // Free input.

        free(input);

    }

}

g++ TestReadLine.cc -lreadline就能够了。

readline库的使用的更多相关文章

  1. GNU Readline 库及编程简介

    用过 Bash 命令行的一定知道,Bash 有几个特性: TAB 键可以用来命令补全 ↑ 或 ↓ 键可以用来快速输入历史命令 还有一些交互式行编辑快捷键: C-A / C-E 将光标移到行首/行尾 C ...

  2. 【原创】lua编译时发现缺少readline库

    编译lualua项目,其中用到了lua-5.1版本的源码,编译时提示缺少readline库,找不到readline/readline.h头文件等 发现系统中其实有安装readline库不过没有做链接和 ...

  3. GNU Readline 库及编程简介【转】

    转自:https://www.cnblogs.com/hazir/p/instruction_to_readline.html 用过 Bash 命令行的一定知道,Bash 有几个特性: TAB 键可以 ...

  4. python——使用readline库实现tab自动补全

    Input History readline tracks the input history automatically. There are two different sets of funct ...

  5. 《Python标准库》 目录

    目录 译者序序前言第1章 文本1.1 string—文本常量和模板1.1.1 函数1.1.2 模板1.1.3 高级模板1.2 textwrap—格式化文本段落1.2.1 示例数据1.2.2 填充段落1 ...

  6. Python:标准库(包含下载地址及书本目录)

    下载地址 英文版(文字版) 官方文档 The Python Standard Library <Python标准库>一书的目录 <python标准库> 译者序 序 前言 第1章 ...

  7. GNU Readline库函数的应用示例

    说明 GNU Readline是一个跨平台开源程序库,提供交互式的文本编辑功能.应用程序借助该库函数,允许用户编辑键入的命令行,并提供自动补全和命令历史等功能.Bash(Bourne Again Sh ...

  8. 4 个用于构建优秀的命令行用户界面的 Python 库

    作者: Amjith Ramanujam 译者: LCTT Lv Feng 在这个分为两篇的关于具有绝佳命令行界面的终端程序的系列文章的第二篇教程中,我们将讨论 Prompt.Toolkit.Clic ...

  9. PHP的命令行扩展Readline相关函数学习

    PHP 作为一个 Web 开发语言,相对来说,命令行程序并不是它的主战场.所以很多年轻的 PHP 开发者可能连命令行脚本都没有写过,更别提交互式的命令操作了.而今天,我们带来的这个扩展就是针对 PHP ...

随机推荐

  1. php课程 8-29 gd库能够画哪些东西

    php课程 8-29 gd库能够画哪些东西 一.总结 一句话总结:文字,点,线,圆,弧线,矩形,各种形状都是可以的,和html5中的canva能画的东西很像,使用也很像,参数怎么记呢,参数完全不用记, ...

  2. fatal error C1859的有效解决办法

    作者:朱金灿来源:http://blog.csdn.net/clever101 在服务器(操作系统为Widows Server2008)上使用VS C++2008编译工程,总是出现这样一个错误:fat ...

  3. 《Java设计模式》之抽象工厂模式

    场景问题 举个生活中常见的样例--组装电脑.我们在组装电脑的时候.通常须要选择一系列的配件,比方CPU.硬盘.内存.主板.电源.机箱等. 为讨论使用简单点.仅仅考虑选择CPU和主板的问题. 其实,在选 ...

  4. hprof教程 分类: B1_JAVA 2015-03-02 12:18 444人阅读 评论(0) 收藏

    大部分内容参考http://www.linuxidc.com/Linux/2012-04/58178.htm J2SE中提供了一个简单的命令行工具来对java程序的cpu和heap进行 profili ...

  5. 【24.67%】【codeforces 551C】 GukiZ hates Boxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. ios开发核心动画五:图标抖动效果--CAKeyframeAnimation

    #import "ViewController.h" #define angle2Rad(angle) ((angle) / 180.0 * M_PI) @interface Vi ...

  7. [Angular] Create custom validators for formControl and formGroup

    Creating custom validators is easy, just create a class inject AbstractControl. Here is the form we ...

  8. Erlang基础知识集锦

    http://wenku.baidu.com/link?url=or-8mkUYUM0uVeqCYESGe93YIlh2IDLP7lFOwRlwr8Syf3PeHbwJC5DPCErs4NFrb1p4 ...

  9. 忙里偷闲( ˇˍˇ )闲里偷学【C语言篇】——(5)有趣的指针

    一.指针是C语言的灵魂 # include <stdio.h> int main(){ int *p; //p是变量名,int *表示p变量存放的是int类型变量的地址,p是一个指针变量 ...

  10. Distribution download cancelled. Using distribution from 'https://services.gradle.org/distributions/

    Distribution download cancelled. Using distribution from ‘https://services.gradle.org/distributions/ ...