Changes in perl/lib/BarnOwl/Completion.pm [48d130b:880311d]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/lib/BarnOwl/Completion.pm
r48d130b r880311d 31 31 my @words = get_completions($ctx); 32 32 return unless @words; 33 my $prefix = common_prefix( @words);33 my $prefix = common_prefix(map {completion_value($_)} @words); 34 34 35 35 if($prefix) { 36 insert_completion($ctx, $prefix, scalar @words == 1); 36 insert_completion($ctx, $prefix, 37 scalar @words == 1 && completion_done($words[0])); 37 38 } 38 39 … … 44 45 } 45 46 47 =head1 COMPLETIONS 48 49 A COMPLETION is either a simple string, or a reference to an array 50 containing two or more values. 51 52 In the former case, the string use used for both the text to display, 53 as well as the result of the completion, and is assumed to be a full 54 completion. 55 56 An 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 62 is only a single completion for a given word, a space will be appended 63 after the completion iff $completion_done is true (or missing). 64 65 =cut 66 67 sub completion_text { 68 my $c = shift; 69 return $c unless ref($c) eq 'ARRAY'; 70 return $c->[0]; 71 } 72 73 sub completion_value { 74 my $c = shift; 75 return $c unless ref($c) eq 'ARRAY'; 76 return $c->[1]; 77 } 78 79 sub completion_done { 80 my $c = shift; 81 return 1 if ref($c) ne 'ARRAY' or @$c < 3; 82 return $c->[2]; 83 } 84 46 85 sub insert_completion { 47 86 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; 50 89 51 if($ unique) {90 if($done) { 52 91 $completion .= " "; 53 92 } … … 66 105 sub show_completions { 67 106 my @words = @_; 68 my $all = BarnOwl::quote( @words);107 my $all = BarnOwl::quote(map {completion_text($_)} @words); 69 108 my $width = BarnOwl::getnumcols(); 70 109 if (length($all) > $width-1) { … … 98 137 my $word = $ctx->words->[$ctx->word]; 99 138 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); 101 140 } 102 141 return;
Note: See TracChangeset
for help on using the changeset viewer.