CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2008
    Posts
    2

    Autocompletion for a CLI application

    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?

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Autocompletion for a CLI application

    Try using getc instead of cin >> cmd.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3

    Re: Autocompletion for a CLI application

    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.

  4. #4
    Join Date
    Feb 2008
    Posts
    2

    Re: Autocompletion for a CLI application

    Ok, thanks for the hint on the readline library, I think it's what I was looking for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured