Skip to content

Commit

Permalink
TailTipWidgets: auto suggests now also option values
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Dec 6, 2019
1 parent 347b1c2 commit c36f878
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
52 changes: 23 additions & 29 deletions builtins/src/main/java/org/jline/builtins/Widgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -772,35 +772,25 @@ public boolean tailtipUpdateStatus() {
private boolean doTailTip(String widget) {
Buffer buffer = buffer();
callWidget(widget);
Pair<String,Boolean> cmdkey = null;
List<String> args = args();
if (buffer.length() == buffer.cursor()) {
List<String> args = args();
Pair<String,Boolean> cmdkey = cmdDescs.evaluateCommandLine(buffer.toString(), args);
CmdDesc cmdDesc = cmdDescs.getDescription(cmdkey.getU());
if (cmdDesc == null) {
setErrorPattern(null);
setErrorIndex(-1);
clearDescription();
resetTailTip();
} else if (cmdDesc.isValid()) {
if (cmdkey.getV()) {
if (cmdDesc.isCommand()) {
doCommandTailTip(widget, cmdDesc, args);
}
} else {
doDescription(cmdDesc.getMainDescription(descriptionSize));
setErrorPattern(cmdDesc.getErrorPattern());
setErrorIndex(cmdDesc.getErrorIndex());
}
}
cmdkey = cmdDescs.evaluateCommandLine(buffer.toString(), args);
} else {
Pair<String,Boolean> cmdkey = cmdDescs.evaluateCommandLine(buffer.toString(), buffer.cursor());
CmdDesc cmdDesc = cmdDescs.getDescription(cmdkey.getU());
if (cmdDesc == null) {
setErrorPattern(null);
setErrorIndex(-1);
clearDescription();
resetTailTip();
} else if (cmdDesc.isValid() && !cmdkey.getV()) {
cmdkey = cmdDescs.evaluateCommandLine(buffer.toString(), buffer.cursor());
}
CmdDesc cmdDesc = cmdDescs.getDescription(cmdkey.getU());
if (cmdDesc == null) {
setErrorPattern(null);
setErrorIndex(-1);
clearDescription();
resetTailTip();
} else if (cmdDesc.isValid()) {
if (cmdkey.getV()) {
if (cmdDesc.isCommand() && buffer.length() == buffer.cursor()) {
doCommandTailTip(widget, cmdDesc, args);
}
} else {
doDescription(cmdDesc.getMainDescription(descriptionSize));
setErrorPattern(cmdDesc.getErrorPattern());
setErrorIndex(cmdDesc.getErrorIndex());
Expand Down Expand Up @@ -835,8 +825,12 @@ private void doCommandTailTip(String widget, CmdDesc cmdDesc, List<String> args)
if (cmdDesc != null) {
if (lastArg.startsWith("-")) {
doDescription(cmdDesc.getOptionDescription(lastArg, descriptionSize));
setSuggestionType(SuggestionType.TAIL_TIP);
noCompleters = true;
if (!lastArg.contains("=")) {
setSuggestionType(SuggestionType.TAIL_TIP);
noCompleters = true;
} else {
setTipType(tipType);
}
} else if (!widget.endsWith(LineReader.BACKWARD_DELETE_CHAR)){
setTipType(tipType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4010,7 +4010,7 @@ public AttributedString getDisplayedBufferWithPrompts(List<AttributedString> sec
full.append(sb.toAttributedString());
} else if (autosuggestion == SuggestionType.COMPLETER) {
if (buf.length() > 0 && buf.length() == buf.cursor()
&& (!lastBinding.equals("\t") || buf.prevChar() == ' ')) {
&& (!lastBinding.equals("\t") || buf.prevChar() == ' ' || buf.prevChar() == '=')) {
clearChoices();
listChoices(true);
} else if (!lastBinding.equals("\t")) {
Expand Down

1 comment on commit c36f878

@mattirn
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.