Interactive console programming for c/c++?

2019-04-24 23:18发布

问题:

So I've written a small program which takes in commands by the users, and then displays the output (after connecting to a server). It's an interactive console of sorts.

However, after using the mongodb and redis command-line clients (which work interactively on the console/terminal), it seems that there must be a library somewhere which provides functionalities such as recording user inputs, accepting up/down keypresses to browse through command history, as well as tab completion framework (not sure how that one would work, but yeah).

What's an ideal library to use for such a thing?

回答1:

The readline library is a common choice: http://www.gnu.org/s/readline

If you are more ambitious, ncurses gives you more control, but has less functionality to begin with and a steeper learning curve.

Edit: icktoofay mentioned that readline is licensed under the GPL. If this is a problem for your software, tecla is an alternative licensed under an X11 style license, so it can be used in proprietary projects.