Line editor class with auto-complete

Hi,

I am a rather new C++ programmer, although I have been programming in C for many years. I am working on a C++ based open source app that will be used to control MIDI devices. This app is much like a shell and is text-based.

At its command prompt, you can issue a set of commands. For example, list, show, add, delete, modify, enable, etc. Each of those commands may have 0 or more options ("enable delay" or "add delay 100 ms"). So I need a line editor that not only handles auto-completion of base commands, but also the command's options (much like the bash-completion package). Notice that some options, like the "add delay 100 ms", has a variable ("100") option.

I am wondering if anyone can recommend something I can use, even as a starting point and then add the missing features I need?

Initially, I am developing this app on the Mac, then I would like to port it to Windows and Linux. I realize it is text-based, but I don't know if TERMIO settings of Mac and Linux are portable to Windows.

If there is a better place to ask this question, please let me know. A Google search did not uncover anything close to what I was looking for. Maybe I used the wrong search terms.

Thanks,
Kory
Use a tree structure for each command. Each node represents an option.

For nodes that take non-keyword data (like a number), mark it as such.

Then, as your user types-in a command, keep track of where in the node tree you are and either autocomplete (for unambiguous choices) or suggest possibilities.

You will need some line-editing capabilities. I believe the GNU readline library can help — it exists for all POSIX systems and has a port for Windows.

Please do not use ANSI/VT-100/whatever codes directly. You will make more work for yourself. Use NCurses to program terminal control. You can port it to Windows using PDCurses.

(There are minor differences between them, but you typically have to be doing something odd to find them.)


Lately I’ve been messing with making my cross-platform terminal I/O routines presentable to the world. If you want, I’ll keep you advised when I post it all on Github.
Thank you for your reply. Yes, please keep me informed.

I did find this article that was helpful and a good start:

https://eli.thegreenplace.net/2016/basics-of-using-the-readline-library/

I just need to expand that code to be able to handle sub-options.

Kory
Topic archived. No new replies allowed.