This page has been designed specifically for the printed screen. It may look different than the page you were viewing on the web.
Please recycle it when you're done reading.

The URI for this page is { http://cc.byexamples.com }

gnu readline: How to keep a history list of entered command lines Posted on June 13th

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.

Compile it with g++ now:

g++ -o simple_rl{,.cpp} -lreadline

That is it, simple and nice :)

Trackback URL

Some Responses to “gnu readline: How to keep a history list of entered command lines” :

  1. Presumably the topic on gadgets collections from Visitthebest was so merit to me. Wished to inform about this site to all of my net friends.

    Commented Best History Websites Guide on June 17th, 2008.
  2. [...] gnu readline: How to keep a history list of entered command lines [...]

    Commented GNU readline: Implement Custom Auto-complete :: c/c++ linux programming by examples on July 5th, 2008.
  3. How to keep a history list of entered command lines…

    This example shows how to keep a history list of entered commands in linux using GNU readline library…

    Commented alldevnet.com on July 26th, 2008.
Leave your own comments about this post: