Ignore:
File:
1 edited

Legend:

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

    r48d130b r880311d  
    3131    my @words = get_completions($ctx);
    3232    return unless @words;
    33     my $prefix = common_prefix(@words);
     33    my $prefix = common_prefix(map {completion_value($_)} @words);
    3434
    3535    if($prefix) {
    36         insert_completion($ctx, $prefix, scalar @words == 1);
     36        insert_completion($ctx, $prefix,
     37                          scalar @words == 1 && completion_done($words[0]));
    3738    }
    3839
     
    4445}
    4546
     47=head1 COMPLETIONS
     48
     49A COMPLETION is either a simple string, or a reference to an array
     50containing two or more values.
     51
     52In the former case, the string use used for both the text to display,
     53as well as the result of the completion, and is assumed to be a full
     54completion.
     55
     56An arrayref completion consists of
     57
     58    [$display_text, $replacement_value[, $completion_done] ].
     59
     60$display_text will be printed in the case of ambiguous completions,
     61$replacement_value will be used to substitute the value in. If there
     62is only a single completion for a given word, a space will be appended
     63after the completion iff $completion_done is true (or missing).
     64
     65=cut
     66
     67sub completion_text {
     68    my $c = shift;
     69    return $c unless ref($c) eq 'ARRAY';
     70    return $c->[0];
     71}
     72
     73sub completion_value {
     74    my $c = shift;
     75    return $c unless ref($c) eq 'ARRAY';
     76    return $c->[1];
     77}
     78
     79sub completion_done {
     80    my $c = shift;
     81    return 1 if ref($c) ne 'ARRAY' or @$c < 3;
     82    return $c->[2];
     83}
     84
    4685sub insert_completion {
    4786    my $ctx = shift;
    48     my $completion = BarnOwl::quote(shift);
    49     my $unique = shift;
     87    my $completion = BarnOwl::quote(completion_value(shift));
     88    my $done = shift;
    5089
    51     if($unique) {
     90    if($done) {
    5291        $completion .= " ";
    5392    }
     
    66105sub show_completions {
    67106    my @words = @_;
    68     my $all = BarnOwl::quote(@words);
     107    my $all = BarnOwl::quote(map {completion_text($_)} @words);
    69108    my $width = BarnOwl::getnumcols();
    70109    if (length($all) > $width-1) {
     
    98137        my $word = $ctx->words->[$ctx->word];
    99138        if(exists($completers{$cmd})) {
    100             return grep {$_ =~ m{^\Q$word\E}} $completers{$cmd}->($ctx);
     139            return grep {completion_value($_) =~ m{^\Q$word\E}} $completers{$cmd}->($ctx);
    101140        }
    102141        return;
Note: See TracChangeset for help on using the changeset viewer.