简体   繁体   中英

Simple interactive prompt in C++

I work on an application that usually runs unattended. Now I need to add to it something like an interactive prompt. In the interactive mode the operator will be able to give simple commands to the application - nothing fancy, simple commands like start and stop . Parametrized commands (eg repeat 10 ) and commands history could be nice too.

Do you know, by chance, any library that helps with such tasks. I've been thinking about something that works like boost::program_options or gflags but for an interactive prompt and not for command line parameters. Any ideas?

Thanks

Readline is one the best known libraries for this

http://tiswww.case.edu/php/chet/readline/rltop.html

It is covered by GPL, so it is only possible to use in GPL-compatible programs.

I did a quick search for alternatives, and found this:

http://github.com/antirez/linenoise

I'm not sure if the following is a reasonable amount of work for what you're trying to do, but Python has a very nice Command Line Interface (CLI) building library called cmd2. If it's possible to expose the relevant parts of your apps to Python using SWIG or CTypes , then doing the rest should be easy.

Here's a nice video presentation about cmd2:

PyCon 2010:Easy command-line applications with cmd and cmd2

HTH

One possibilty is to open a TCP port and accept messages in text format. Then you can telnet to that port and issue simple commands.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM