Skip to content

Commit

Permalink
Merge branch 'master' into tailtip-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn authored Nov 7, 2019
2 parents 36bfbb6 + 454a286 commit 92be621
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 38 deletions.
70 changes: 37 additions & 33 deletions builtins/src/main/java/org/jline/builtins/Completers.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2018, the original author or authors.
* Copyright (c) 2002-2019, the original author or authors.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
Expand Down Expand Up @@ -219,7 +219,7 @@ private boolean isTrue(Object result) {
public static class DirectoriesCompleter extends FileNameCompleter {

private final Supplier<Path> currentDir;
private final boolean forceSlash;
private final boolean forceSlash;

public DirectoriesCompleter(File currentDir) {
this(currentDir.toPath(), false);
Expand All @@ -235,7 +235,7 @@ public DirectoriesCompleter(Path currentDir) {

public DirectoriesCompleter(Path currentDir, boolean forceSlash) {
this.currentDir = () -> currentDir;
this.forceSlash = forceSlash;
this.forceSlash = forceSlash;
}

public DirectoriesCompleter(Supplier<Path> currentDir) {
Expand All @@ -255,7 +255,7 @@ protected Path getUserDir() {
@Override
protected String getSeparator() {
return forceSlash ? "/" : getUserDir().getFileSystem().getSeparator();
}
}

@Override
protected boolean accept(Path path) {
Expand All @@ -266,7 +266,7 @@ protected boolean accept(Path path) {
public static class FilesCompleter extends FileNameCompleter {

private final Supplier<Path> currentDir;
private final boolean forceSlash;
private final boolean forceSlash;

public FilesCompleter(File currentDir) {
this(currentDir.toPath(), false);
Expand Down Expand Up @@ -298,11 +298,11 @@ public FilesCompleter(Supplier<Path> currentDir, boolean forceSlash) {
protected Path getUserDir() {
return currentDir.get();
}

@Override
protected String getSeparator() {
return forceSlash ? "/" : getUserDir().getFileSystem().getSeparator();
}
}
}

/**
Expand Down Expand Up @@ -337,35 +337,39 @@ public void complete(LineReader reader, ParsedLine commandLine, final List<Candi
String curBuf;
String sep = getSeparator();
int lastSep = buffer.lastIndexOf(sep);
if (lastSep >= 0) {
curBuf = buffer.substring(0, lastSep + 1);
if (curBuf.startsWith("~")) {
if (curBuf.startsWith("~" + sep)) {
current = getUserHome().resolve(curBuf.substring(2));
try {
if (lastSep >= 0) {
curBuf = buffer.substring(0, lastSep + 1);
if (curBuf.startsWith("~")) {
if (curBuf.startsWith("~" + sep)) {
current = getUserHome().resolve(curBuf.substring(2));
} else {
current = getUserHome().getParent().resolve(curBuf.substring(1));
}
} else {
current = getUserHome().getParent().resolve(curBuf.substring(1));
current = getUserDir().resolve(curBuf);
}
} else {
current = getUserDir().resolve(curBuf);
curBuf = "";
current = getUserDir();
}
} else {
curBuf = "";
current = getUserDir();
}
try (DirectoryStream<Path> directory = Files.newDirectoryStream(current, this::accept)) {
directory.forEach(p -> {
String value = curBuf + p.getFileName().toString();
if (Files.isDirectory(p)) {
candidates.add(
new Candidate(value + (reader.isSet(LineReader.Option.AUTO_PARAM_SLASH) ? sep : ""),
getDisplay(reader.getTerminal(), p), null, null,
reader.isSet(LineReader.Option.AUTO_REMOVE_SLASH) ? sep : null, null, false));
} else {
candidates.add(new Candidate(value, getDisplay(reader.getTerminal(), p), null, null, null, null,
true));
}
});
} catch (IOException e) {
try (DirectoryStream<Path> directory = Files.newDirectoryStream(current, this::accept)) {
directory.forEach(p -> {
String value = curBuf + p.getFileName().toString();
if (Files.isDirectory(p)) {
candidates.add(
new Candidate(value + (reader.isSet(LineReader.Option.AUTO_PARAM_SLASH) ? sep : ""),
getDisplay(reader.getTerminal(), p), null, null,
reader.isSet(LineReader.Option.AUTO_REMOVE_SLASH) ? sep : null, null, false));
} else {
candidates.add(new Candidate(value, getDisplay(reader.getTerminal(), p), null, null, null, null,
true));
}
});
} catch (IOException e) {
// Ignore
}
} catch (Exception e) {
// Ignore
}
}
Expand All @@ -385,7 +389,7 @@ protected Path getUserDir() {
protected Path getUserHome() {
return Paths.get(System.getProperty("user.home"));
}

protected String getSeparator() {
return getUserDir().getFileSystem().getSeparator();
}
Expand Down
4 changes: 2 additions & 2 deletions reader/src/main/java/org/jline/reader/impl/DefaultParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public ParsedLine parse(final String line, final int cursor, ParseContext contex
if (bracketChecker.isClosingBracketMissing() || bracketChecker.isOpeningBracketMissing()) {
String message = null;
String missing = null;
if(bracketChecker.isClosingBracketMissing()) {
if (bracketChecker.isClosingBracketMissing()) {
message = "Missing closing brackets";
missing = "add: " + bracketChecker.getMissingClosingBrackets();
} else {
Expand Down Expand Up @@ -418,7 +418,7 @@ public int getOpenBrackets() {
}

public String getNextClosingBracket() {
return nested.size() > 1 ? nextClosingBracket : null;
return nested.size() == 2 ? nextClosingBracket : null;
}

private int bracketId(final char[] brackets, final CharSequence buffer, final int pos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,8 @@ public String readLine(String prompt, String rightPrompt, MaskingCallback maskin
} catch (SyntaxError e) {
done = true;
} catch (Exception e) {
throw new IllegalArgumentException(e.getMessage());
} finally {
commandsBuffer.clear();
throw new IllegalArgumentException(e.getMessage());
}
} while (!done);
AttributedStringBuilder sb = new AttributedStringBuilder();
Expand Down Expand Up @@ -2192,10 +2191,11 @@ private void removeIndentation() {
if (buf.currChar() == ' ') {
buf.delete();
} else {
buf.move(1);
break;
}
}
endOfLine();
buf.move(1);
}
}

Expand Down

0 comments on commit 92be621

Please sign in to comment.