views:

532

answers:

4

I am using the Term::Shell package in Perl for implementing a CLI tool. I am not able to do the tab completion of a command part with that.

comp_CMD() - which is a API provided by this Term::Shell, is to achieve the tab completion. This is not helping me. Does anyone know how to make this work??

Sample Code:

#!/usr/bin/env perl
package Sample;
use base qw(Term::Shell);

sub prompt_str { "Sample\>" };

sub comp_show
{
    my $o = shift;
    my $word = shift;
    $o->completions($word, [qw(all work and no play is no fun at)]);
}

sub run_show
{
        print "run show\n";
}

package main;
Sample->new->cmdloop;

This is a run of the program:

Sample>show[TAB]

The above command doesnt give the expected output.. it just gives me a tab.

+2  A: 

Your sample works for me. Both "show" and its arguments get completed.

After you type "show", there is nothing more to complete, it's already a full command. To get the first argument to complete, you have to at least provide its first letter; so typing <TAB> immediately after show, can only get you to the place where you have to type the first letter of the argument you want to complete. And if you hit <TAB> twice in a row, you will see what completions are available.

The only thing I found odd is that, if there is only a single possible argument to complete, it doesn't automatically get completed. You still have to provide the first letter. It's a little odd that, but perhaps just an oversight by the implementor.

Inshallah
Same here: sh[tab] expands to show
Cebjyre
A: 

Hi,

first of all, i am not getting the "add comment" button.. so i am posting as an answer.

I tried this way:

sample> sh"TAB"

sample>show w"TAB"

Nothing worked.

Does it have anything to do with environment? or something else?

You should be able to edit your own answer.
brian d foy
To make a comment, you need at least 50 rep points.
brian d foy
+4  A: 

Make sure you have Term::ReadLine::Gnu or Term::ReadLine::Perl installed.

ccheneson
+1 I think that was it.
Inshallah
A: 

YES... I have installed the packages.. and its working fine now..

THANKS A LOT for you all !!!!! :):)