Click to See Complete Forum and Search --> : Autocompletion for a CLI application


xinkt
February 29th, 2008, 03:29 PM
Hello,

I'm programming a CLI application and I would like to add the autocompletion feature.

I have all the valid commands in a hash table and I would like to display the available options when a user presses the TAB key when typing an incomplete command.

Ex: sc(hit the TAB key) --> scanf

The same functionality as in a linux shell.

The problem is when I do a (cin >> cmd) I have to press the enter key to read that line and I would like to display the options only by pressing the TAB key.

I tried the ncurses library but I would like to do that with standard C++ w/o any external library.

Somebody with a good idea?

Marc G
March 1st, 2008, 01:53 AM
Try using getc (http://msdn2.microsoft.com/en-us/library/5231d02a(VS.71).aspx) instead of cin >> cmd.

pm_kirkham
March 1st, 2008, 07:28 AM
Use an existing library - either GNU readline http://tiswww.case.edu/php/chet/readline/rltop.html (GPL2) or editline http://www.thrysoee.dk/editline/ (BSD) depending on licensing tastes.

xinkt
March 1st, 2008, 07:51 PM
Ok, thanks for the hint on the readline library, I think it's what I was looking for.