Skip to content

Commit

Permalink
Extend FilesCompleter/DirectoriesCompleter to accept a lambda for the…
Browse files Browse the repository at this point in the history
… current dir, fix for #413
  • Loading branch information
gnodet committed Jul 8, 2019
1 parent d9716b6 commit a1f2c93
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions builtins/src/main/java/org/jline/builtins/Completers.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.Supplier;

import org.jline.reader.Candidate;
import org.jline.reader.LineReader;
Expand Down Expand Up @@ -217,19 +218,23 @@ private boolean isTrue(Object result) {

public static class DirectoriesCompleter extends FileNameCompleter {

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

public DirectoriesCompleter(File currentDir) {
this(currentDir.toPath());
}

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

public DirectoriesCompleter(Supplier<Path> currentDir) {
this.currentDir = currentDir;
}

@Override
protected Path getUserDir() {
return currentDir;
return currentDir.get();
}

@Override
Expand All @@ -240,19 +245,23 @@ protected boolean accept(Path path) {

public static class FilesCompleter extends FileNameCompleter {

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

public FilesCompleter(File currentDir) {
this(currentDir.toPath());
}

public FilesCompleter(Path currentDir) {
this.currentDir = () -> currentDir;
}

public FilesCompleter(Supplier<Path> currentDir) {
this.currentDir = currentDir;
}

@Override
protected Path getUserDir() {
return currentDir;
return currentDir.get();
}
}

Expand Down

0 comments on commit a1f2c93

Please sign in to comment.