Hi,


I am making a small software. As a part of the Command Line Interface I am supposed to include the "tab help facility" .Incase the user is typing a command and in between he presses the Tab key, the software should display all the avavilable commands.


I am unable to trap the Tab ...

And ofcourse the Coding is in C..

As you need to trap a single key, I don't think you can use getline/s().
Just catch every character typed using getchar/ch() and echo it back using putxx() if it's not the tab char.

if you are using c++ we can write portable code

std::cin >> std::noskipws ;
char ch ; 
std::cin >> ch ;
if( ch == '\t' ) /* ... */ ;// tab
else /* ... */ ; // something else

1.I am working on LINUX
2. Using C, not C++
3I can Download extra lib if the need be.

1.I am working on LINUX
2. Using C, not C++
3I can Download extra lib if the need be.

Depends on if you want the user to press the return/enter key first. If not, you'll probably want to code with something like [search]NCurses[/search].

Depends on if you want the user to press the return/enter key first. If not, you'll probably want to code with something like [search]NCurses[/search].

I think the user doesn't press the return key.
"Incase the user is typing a command and in between he presses the Tab key, the software should display all the avavilable commands."
Kinda like word completion in shells.

Yes, I dont want the user to have to press the return key.

Can any one please explain in detail, how the Ncurses thing works...

@ kashyap.. Man I dont want the user to press the ReTURN key. I mean, the 1st method that u suggested would not work in this situation...

???

ncurses (or curses) is installed by default by
most linux distros. try man curses to check.

install ncurses-development package if
it is not already installed.

while writing code,

[B]#include <ncurses.h> [/B]// or <curses.h>
[B]int main()[/B]
[B]{
    initscr() ; [/B]// must be called first[B][B]
    cbreak() [/B][/B][B]// [/B]disable the buffering
     // required to get a character immediately
     // without waiting for return key.
 [B]
    noecho();[/B]   // only if u want to suppress 
      // echo of input keys
  
    [B] keypad(stdscr, TRUE);[/B]   // only if u want
     // to read special keys (delete,arrow keys etc.)

     // to read a character, use
     [B]int getch(void) ; 
 [/B]   // normally [B]getch[/B] waits till a 
    // key is hit. to work in a 
    // nonblocking manner, call
 [B]  // nodelay(stdscr,   TRUE) ;
 [/B]  // in this case getch will return 
   // [B]ERR[/B] if key input is   not available.
 
    [B]endwin()[/B] // must be called before exiting
    // to restore the terminal settings.
   
   return 0 ;
}

compiling/linking:
either gcc. -lncurses your_program.c
or gcc your_program.c libncurses.a

link statically to the ncurses library
if u want to run your program on machines
where ncurses is not installed.

This article has been dead for over six months. Start a new discussion instead.