Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autocomplete with C++ (NOT with Shell)

I am trying to add autocomplete functionality to my command line application. So far all the answers are saying that it is priority of the shell but in my case it is different. My program goes into a loop (to get commands) in main(), so I don't think it has anything to do with shell. How can I achieve such goal?

This following is my program. It starts parsing when the user hits enter (std::getline()). How can I get user input at runtime without using any external libraries?

while (input != "exit") {

  std::cout << "\nCommand >> ";
  std::getline(std::cin, input);

  com.parse(input);
}
like image 357
khajvah Avatar asked Jul 30 '13 15:07

khajvah


1 Answers

As David Rodríguez said, using readline GNU does the job (I had to use a library) in linux.

This is the official documentation, it has some C examples but they are too confusing, so I used this to create my custom autocompletion.

like image 173
khajvah Avatar answered Oct 24 '22 05:10

khajvah