GNU readline implement filename auto-complete by default, it will list all the files in the current directory. We can disable it by binds our TAB key to some other operation. In previous post, I simply abort the operation to ignore users hitting TABs.
Auto-complete are useful if only we can customize it. Well, readline allows us do it by assign our own callback functions. First of all, you may want to read up the manual from HERE. It does provides a c sample codes as well but I find it too complicated, here I provide a simplified version that can be compiled under c++.
When I was assigned a project to create a text console based simulator, I am looking into how to keep a history list of entered command lines like Bash Shell. Users are allow to search through the history list by hitting UP and DOWN arrow key.
GNU readline library provides this feature, and it is pretty easy to use. Lets look at the example below:
I use rl_bind_key() to disable the tab key for file auto-complete that enabled by default. I will write another post for custom auto-complete using libreadline soon. add_history() is used to add the enterd inputs into the history list, and key bindings to arrow keys are enabled by default.