Skip to content

Commit

Permalink
Add an example completer for #35
Browse files Browse the repository at this point in the history
It would be nice to have a few more builtin Completers to help
  • Loading branch information
gnodet committed Nov 7, 2016
1 parent 63ce9be commit ab1d420
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/test/java/org/jline/example/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,11 @@
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.Map;
import java.util.*;

import org.jline.keymap.KeyMap;
import org.jline.reader.Binding;
import org.jline.reader.Completer;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
import org.jline.reader.EndOfFileException;
import org.jline.reader.ParsedLine;
import org.jline.reader.Reference;
import org.jline.reader.UserInterruptException;
import org.jline.reader.*;
import org.jline.reader.impl.LineReaderImpl;
import org.jline.reader.Macro;
import org.jline.reader.impl.completer.ArgumentCompleter;
import org.jline.reader.impl.completer.FileNameCompleter;
import org.jline.reader.impl.completer.StringsCompleter;
Expand Down Expand Up @@ -123,6 +115,28 @@ public static void main(String[] args) throws IOException {
new StringsCompleter("foo11", "foo12", "foo13"),
new StringsCompleter("foo21", "foo22", "foo23"));
break label;
case "param":
completer = (reader, line, candidates) -> {
if (line.wordIndex() == 0) {
candidates.add(new Candidate("Command1"));
} else if (line.words().get(0).equals("Command1")) {
if (line.words().get(line.wordIndex() - 1).equals("Option1")) {
candidates.add(new Candidate("Param1"));
candidates.add(new Candidate("Param2"));
} else {
if (line.wordIndex() == 1) {
candidates.add(new Candidate("Option1"));
}
if (!line.words().contains("Option2")) {
candidates.add(new Candidate("Option2"));
}
if (!line.words().contains("Option3")) {
candidates.add(new Candidate("Option3"));
}
}
}
};
break label;
case "color":
color = true;
prompt = new AttributedStringBuilder()
Expand Down Expand Up @@ -265,4 +279,5 @@ else if ("sleep".equals(pl.word())) {
t.printStackTrace();
}
}

}

0 comments on commit ab1d420

Please sign in to comment.