How to set up a tab in Perl Term :: Shell?

I use Term :: Shell to implement the CLI tool. This package provides the API: comp_CMD.

This function is called whenever the user presses TAB. My requirement is here:

shell> stack TAB

over under

`shell> stack over TAB

flow sample junk

But the default comp_CMDprovides only one set of TAB parameters, such as

shell> stack TAB

over under

`shell> stack over TAB

over under ### PROBLEM HERE

Instead of over under here I want to get a sample stream sample .

+3
source share
2 answers

comp_* . , , , catch_comp, ; :

my %completion_tree = (
    stack => { under => [],
               over  => [qw(flow sample junk)] }
);

sub catch_comp {
    my $o = shift;
    my ($cmd, $word, $line, $start) = @_;

    my $completed = substr $line, 0, $start;
    $completed =~ s/^\s*//;

    my $tree = \%completion_tree;
    foreach (split m'\s+', $completed) {
        last if ref($tree) ne 'HASH';
        $tree = $tree->{$_};
    }

    my @completions;
    $_ = ref($tree);
    @completions =      @$tree if /ARRAY/;
    @completions = keys %$tree if /HASH/;
    @completions =      ($tree)if /SCALAR/;

    return $o->completions($word, [@completions]);
}
+3

, .

rl_complete comp__ ( , TAB), .

0

Source: https://habr.com/ru/post/1713445/


All Articles