PDA

View Full Version : bash completion on user input



t0bias
12-20-2007, 07:55 AM
hi,

i'm working on a small tool to convert some files. while the program is
running, the user is being asked to enter some file-paths.
i'm actually doing this with a cin, but it would be - obviously - more
comfortable if the user could use the bash-completion. is there a
way to implement this?

thanks,

toby

Salem
12-20-2007, 08:27 AM
Yes, link your code with the readline library.

t0bias
12-20-2007, 09:22 AM
thanks! well... and that's it then? bash-completion on cin?

matsp
12-20-2007, 09:55 AM
No, you would need to use the readline function, defined in the readline library. cin is not changed by this.

--
Mats

t0bias
12-20-2007, 10:18 AM
yepp, it works, thanks a lot!!

brewbuck
12-20-2007, 11:36 AM
yepp, it works, thanks a lot!!

Be careful though -- readline doesn't know that cin exists. They both do some sort of buffering. So they can step on each other's toes.

Once you've decided to use readline, you should use it for ALL input. Don't use cin at all.

Salem
12-20-2007, 11:43 AM
The same goes for mixing std::cin and std::getline

Mixing any combination of input styles usually results in coming unstuck at some point. Pick one at stick with it.