Skip to content

Commit 0f40e8d

Browse files
committed
Use numbers for interactive disambiguation if there is a first letter collision
1 parent 35ea309 commit 0f40e8d

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

bin/p6doc

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,21 @@ sub disambiguate-f-search( $docee, %data ) {
139139
for %found.keys -> $key {
140140
%options{$key}.push: %found{$key}>>.subst(/^'Type::'/, '');
141141
}
142-
say "\t" ~ %options.values.map({ @($^a) }).join("\n\t") ~ "\n";
143142

144143
# 's' => Type::Supply.grep, ... | and we specifically want the %found values,
145144
# | not the presentation-versions in %options
146145
if INTERACT {
146+
my $idx = 0;
147+
my $total-elems = [+] %found.values.map({ +@^o });
148+
if +%found.keys < $total-elems {
149+
my @prefixes = (1..$total-elems) X~ ") ";
150+
say "\t" ~ ( @prefixes Z~ %options.values.map({ @($^a) }) ).join("\n\t") ~ "\n";
151+
} else {
152+
say "\t" ~ %options.values.map({ @($^a) }).join("\n\t") ~ "\n";
153+
}
147154
$final-docee = prompt-with-options( %options, %found );
148155
} else {
156+
say "\t" ~ %options.values.map({ @($^a) }).join("\n\t") ~ "\n";
149157
exit 1;
150158
}
151159
}
@@ -156,7 +164,17 @@ sub prompt-with-options( %options, %found ) {
156164
my $final-docee;
157165

158166
my %prefixes = do for %options.kv -> $k,@o { @o.map(*.comb[0].lc) X=> %found{$k} };
159-
my $prompt-text = "Narrow your choice? ({ %prefixes.keys.join(', ') }, or !{'/' ~ 'q' if !%prefixes<q>} to quit): ";
167+
168+
if %prefixes.values.grep( -> @o { +@o > 1 }) {
169+
my (%indexes,$base-idx);
170+
$base-idx = 0;
171+
for %options.kv -> $k,@o {
172+
%indexes.push: @o>>.map({ ++$base-idx}) Z=> @(%found{$k});
173+
}
174+
%prefixes = %indexes;
175+
}
176+
177+
my $prompt-text = "Narrow your choice? ({ %prefixes.keys.sort.join(', ') }, or !{'/' ~ 'q' if !%prefixes<q>} to quit): ";
160178

161179
while prompt( $prompt-text ).words -> $word {
162180
if $word ~~ '!' or ($word ~~ 'q' and !%prefixes<q>) {

0 commit comments

Comments
 (0)