Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mattirn/jline3.git into h…
Browse files Browse the repository at this point in the history
…istory-command
  • Loading branch information
mattirn committed Sep 2, 2019
2 parents 2eb14ad + bd6bbb1 commit d87545d
Show file tree
Hide file tree
Showing 9 changed files with 1,043 additions and 219 deletions.
4 changes: 2 additions & 2 deletions builtins/src/main/java/org/jline/builtins/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static void less(Terminal terminal, InputStream in, PrintStream out, Prin
tabs.add(parseInteger(s));
}
}
Less less = new Less(terminal).tabs(tabs);
Less less = new Less(terminal, currentDir).tabs(tabs);
less.quitAtFirstEof = opt.isSet("QUIT-AT-EOF");
less.quitAtSecondEof = opt.isSet("quit-at-eof");
less.quiet = opt.isSet("quiet");
Expand All @@ -176,7 +176,7 @@ public static void less(Terminal terminal, InputStream in, PrintStream out, Prin
less.run(sources);
}

private static Source doUrlSource(Path currentDir, Path file) {
protected static Source doUrlSource(Path currentDir, Path file) {
Source out = null;
try {
out = new URLSource(currentDir.resolve(file).toUri().toURL(), file.toString());
Expand Down
50 changes: 47 additions & 3 deletions builtins/src/main/java/org/jline/builtins/Completers.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,24 +219,44 @@ private boolean isTrue(Object result) {
public static class DirectoriesCompleter extends FileNameCompleter {

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

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

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

public DirectoriesCompleter(Path currentDir) {
this(currentDir, false);
}

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

public DirectoriesCompleter(Supplier<Path> currentDir) {
this(currentDir, false);
}

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

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

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

@Override
protected boolean accept(Path path) {
return Files.isDirectory(path) && super.accept(path);
Expand All @@ -246,23 +266,43 @@ protected boolean accept(Path path) {
public static class FilesCompleter extends FileNameCompleter {

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

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

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

public FilesCompleter(Path currentDir) {
this(currentDir, false);
}

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

public FilesCompleter(Supplier<Path> currentDir) {
this(currentDir, false);
}

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

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

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

/**
Expand Down Expand Up @@ -295,7 +335,7 @@ public void complete(LineReader reader, ParsedLine commandLine, final List<Candi

Path current;
String curBuf;
String sep = getUserDir().getFileSystem().getSeparator();
String sep = getSeparator();
int lastSep = buffer.lastIndexOf(sep);
if (lastSep >= 0) {
curBuf = buffer.substring(0, lastSep + 1);
Expand Down Expand Up @@ -345,6 +385,10 @@ protected Path getUserDir() {
protected Path getUserHome() {
return Paths.get(System.getProperty("user.home"));
}

protected String getSeparator() {
return getUserDir().getFileSystem().getSeparator();
}

protected String getDisplay(Terminal terminal, Path p) {
// TODO: use $LS_COLORS for output
Expand Down
Loading

0 comments on commit d87545d

Please sign in to comment.