Changeset 4fbc7f5


Ignore:
Timestamp:
Jul 29, 2009, 9:41:44 PM (8 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
747d6a5
Parents:
e711ca7
git-author:
Nelson Elhage <nelhage@mit.edu> (07/29/09 21:30:43)
git-committer:
Nelson Elhage <nelhage@mit.edu> (07/29/09 21:41:44)
Message:
complete_flags: Pass the completer the argument number being completed

This is the index of the argument (not flag or flag option) being
completed, for convenience.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • perl/lib/BarnOwl/Completion/Util.pm

    re711ca7 r4fbc7f5  
    1919    my $flag = undef;
    2020
    21     my $word = 0;
     21    my $argct = 0;
    2222    my $optsdone = 0;
    2323
     
    3535            $word = "-" . substr($word, -1);
    3636            $flag = $word if(exists $args->{$word});
     37        } else {
     38            $argct++;
    3739        }
    3840        $idx++;
     
    4749    } else {
    4850        return ($optsdone ? () : (@$no_args, keys %$args),
    49                 $default ? ($default->($ctx)) : ());
     51                $default ? ($default->($ctx, $argct)) : ());
    5052    }
    5153}
  • t/completion.t

    re711ca7 r4fbc7f5  
    146146    my $after = shift;
    147147    my $words = shift;
     148    my $complete = shift || \&complete_zwrite;
    148149   
    149150    my $ctx = BarnOwl::Completion::Context->new($before, $after);
     
    151152    local $Test::Builder::Level = $Test::Builder::Level + 1;
    152153
    153     my @got = complete_zwrite($ctx);
     154    my @got = $complete->($ctx);
    154155    is_deeply([sort @got], [sort @$words]);
    155156}
     
    170171              [qw(nelhage asedeno geofft)]);
    171172
     173sub complete_word {
     174    my $ctx = shift;
     175    return complete_flags($ctx,
     176                          [qw(-a -b -c)],
     177                          {
     178                              "-d" => sub {qw(some words for completing)},
     179                          },
     180                          sub {$_[1]});
     181}
     182
     183test_complete('cmd -a -d foo -c hello ','',
     184              [qw(-a -b -c -d 1)], \&complete_word);
     185
     186test_complete('cmd -a -d foo -c ','',
     187              [qw(-a -b -c -d 0)], \&complete_word);
     188
    1721891;
    173190
Note: See TracChangeset for help on using the changeset viewer.