Skip to content

Commit

Permalink
FileNameCompleter: fixed Windows file name highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed May 5, 2020
1 parent 496492e commit 7333eeb
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions builtins/src/main/java/org/jline/builtins/Completers.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.jline.utils.AttributedString;
import org.jline.utils.AttributedStringBuilder;
import org.jline.utils.AttributedStyle;
import org.jline.utils.OSUtils;
import org.jline.utils.StyleResolver;

public class Completers {
Expand Down Expand Up @@ -366,10 +367,10 @@ public void complete(LineReader reader, ParsedLine commandLine, final List<Candi
if (Files.isDirectory(p)) {
candidates.add(
new Candidate(value + (reader.isSet(LineReader.Option.AUTO_PARAM_SLASH) ? sep : ""),
getDisplay(reader.getTerminal(), p, resolver), null, null,
getDisplay(reader.getTerminal(), p, resolver, sep), null, null,
reader.isSet(LineReader.Option.AUTO_REMOVE_SLASH) ? sep : null, null, false));
} else {
candidates.add(new Candidate(value, getDisplay(reader.getTerminal(), p, resolver), null, null, null, null,
candidates.add(new Candidate(value, getDisplay(reader.getTerminal(), p, resolver, sep), null, null, null, null,
true));
}
});
Expand Down Expand Up @@ -401,16 +402,16 @@ protected String getSeparator(boolean useForwardSlash) {
return useForwardSlash ? "/" : getUserDir().getFileSystem().getSeparator();
}

protected String getDisplay(Terminal terminal, Path p, StyleResolver resolver) {
protected String getDisplay(Terminal terminal, Path p, StyleResolver resolver, String separator) {
AttributedStringBuilder sb = new AttributedStringBuilder();
String name = p.getFileName().toString();
int idx = name.lastIndexOf(".");
String type = idx != -1 ? ".*" + name.substring(idx): null;
if (Files.isSymbolicLink(p)) {
sb.styled(resolver.resolve(".ln"), name).append("@");
} else if (Files.isDirectory(p)) {
sb.styled(resolver.resolve(".di"), name).append("/");
} else if (Files.isExecutable(p)) {
sb.styled(resolver.resolve(".di"), name).append(separator);
} else if (Files.isExecutable(p) && !OSUtils.IS_WINDOWS) {
sb.styled(resolver.resolve(".ex"), name).append("*");
} else if (type != null && resolver.resolve(type).getStyle() != 0) {
sb.styled(resolver.resolve(type), name);
Expand Down Expand Up @@ -697,7 +698,8 @@ protected boolean completeValue(LineReader reader, final ParsedLine commandLine,
String val = c.value();
if (valueCompleter instanceof FileNameCompleter) {
FileNameCompleter cc = (FileNameCompleter)valueCompleter;
val = cc.getDisplay(reader.getTerminal(), Paths.get(c.value()), FileNameCompleter.resolver);
String sep = cc.getSeparator(reader.isSet(LineReader.Option.USE_FORWARD_SLASH));
val = cc.getDisplay(reader.getTerminal(), Paths.get(c.value()), FileNameCompleter.resolver, sep);
}
candidates.add(new Candidate(curBuf + v, val, null, null, null, null, c.complete()));
}
Expand Down

0 comments on commit 7333eeb

Please sign in to comment.