让 linux 交互式命令行程序支持方向键等功能

自己写交互式命令行程序,通常都是从标准输入输出读写。运行的时候,只能敲完整一个命令,然后回车。想要按方向键移动光标,按 del 往后删除都只会出现个 ^[[A 这样的东西。要实现那些功能,得处理终端命令,这个活并不轻松。虽然有 readline 这样的库,但还是会带来很多麻烦。

好在 unix 的哲学就是一个程序干一件事情,并把它做到最好。于是就有一个 rlwrap 的程序。用这个程序启动你的工具,你的程序就立马有了那些功能。还可以按上下键翻阅历史命令,ctrl+r 来搜索历史输入等。

 

2 thoughts on “让 linux 交互式命令行程序支持方向键等功能

  1. Er.Z November 15, 2011 / 2:11 am

    回踩,链接已加。。。呵呵。

  2. weight loss January 7, 2015 / 4:59 pm

    Awesome posts you post here, i have shared this post on my
    fb

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s