Don't escape/quote command names in completion proposals

Fixes #76
This commit is contained in:
Eric Bottard
2017-06-01 15:49:42 +02:00
parent 30b49ef501
commit 109094c48c
3 changed files with 17 additions and 1 deletions

View File

@@ -43,6 +43,12 @@ public class CompletionProposal {
*/
private String category;
/**
* Whether the proposal should bypass escaping and quoting rules. This is useful for command proposals, which can
* appear as true multi-word Strings.
*/
private boolean dontQuote = false;
public CompletionProposal(String value) {
this.value = this.displayText = value;
}
@@ -83,6 +89,15 @@ public class CompletionProposal {
return this;
}
public CompletionProposal dontQuote(boolean dontQuote) {
this.dontQuote = dontQuote;
return this;
}
public boolean dontQuote() {
return dontQuote;
}
@Override
public String toString() {
return value;

View File

@@ -172,6 +172,7 @@ public class Shell implements CommandRegistry {
private CompletionProposal toCompletionProposal(String command, MethodTarget methodTarget) {
return new CompletionProposal(command)
.dontQuote(true)
.category("Available commands")
.description(methodTarget.getHelp());
}

View File

@@ -154,7 +154,7 @@ public class JLineShell {
List<CompletionProposal> proposals = shell.complete(context);
proposals.stream()
.map(p -> new Candidate(
cpl.emit(p.value()).toString(),
p.dontQuote() ? p.value() : cpl.emit(p.value()).toString(),
p.displayText(),
p.category(),
p.description(),