我程序中的控制台输入历史记录 [英] Console input history in my program

查看:97
本文介绍了我程序中的控制台输入历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Linux控制台应用程序,这是正常的事情:输出提示,阅读用户的输入行,对其进行操作,然后重复.但是,我想提供一种类似于Linux Shell的行输入工具,可以访问以前键入的输入行以及对输入的常规编辑.换句话说,像BACKSPACE,DELETE等之类的键都可以满足您的期望,而ENTER会将输入的完整行提供给我的程序,一切正常,但是向上箭头键将当前输入行替换为前一个输入行. (根据我程序的输入,而不是shell的历史记录)

Shell显然拥有所有代码,并且复制它是一项不平凡的工作,因此我想知道,假设它存在于库中,是否有可能利用该代码.有没有人做过,或者对实现我想要的简单方法有任何其他建议?

I''m developing a Linux console app, the normal sort of thing: output a prompt, read the user''s input line, action it, repeat. However, I want to offer a line input facility like that of the Linux shell, with access to previously-typed input lines, as well as the normal editing of input. In other words, keys like BACKSPACE, DELETE, etc. all do what you would expect, and ENTER delivers the complete line of input to my program, all as normal, BUT the up-arrow key replaces the current input line with the previous one (from my program''s input, not from the shell''s history)

The shell obviously has all the code for this, and it''s a non-trivial job to replicate it, so I wondered whether it is possible to tap into that code, assuming it lives in a library. Anybody ever done that, or have any other suggestions as to an easy way to achieve what I want?

推荐答案

GNU shell(bash)使用GNU Readline库 [
The GNU shell (bash) uses the GNU Readline Library[^].


这篇关于我程序中的控制台输入历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆