Skip to content

Commit

Permalink
Merge branch 'master' into tailtip-v2
Browse files Browse the repository at this point in the history
Conflicts:
	builtins/src/test/java/org/jline/example/Example.java
  • Loading branch information
mattirn committed Nov 10, 2019
2 parents 812ad2c + a890660 commit 3a5d132
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 20 deletions.
29 changes: 16 additions & 13 deletions builtins/src/main/java/org/jline/builtins/Nano.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,19 @@ void read(InputStream fis) throws IOException {
moveToChar(0);
}

private int charPosition(int displayPosition){
private int charPosition(int displayPosition) {
return charPosition(line, displayPosition, CursorMovement.STILL);
}

private int charPosition(int displayPosition, CursorMovement move){
private int charPosition(int displayPosition, CursorMovement move) {
return charPosition(line, displayPosition, move);
}

private int charPosition(int line, int displayPosition){
private int charPosition(int line, int displayPosition) {
return charPosition(line, displayPosition, CursorMovement.STILL);
}

private int charPosition(int line, int displayPosition, CursorMovement move){
private int charPosition(int line, int displayPosition, CursorMovement move) {
int out = lines.get(line).length();
if (!lines.get(line).contains("\t") || displayPosition == 0) {
out = displayPosition;
Expand Down Expand Up @@ -806,7 +806,7 @@ List<AttributedString> computeHeader() {
}
}

void highlightDisplayedLine(int curLine, int curOffset, int nextOffset, AttributedStringBuilder line){
void highlightDisplayedLine(int curLine, int curOffset, int nextOffset, AttributedStringBuilder line) {
AttributedString disp = highlight ? syntaxHighlighter.highlight(new AttributedStringBuilder().tabs(tabs).append(getLine(curLine)))
: new AttributedStringBuilder().tabs(tabs).append(getLine(curLine)).toAttributedString();
int[] hls = highlightStart();
Expand Down Expand Up @@ -1606,7 +1606,7 @@ public Pattern getEnd() {
return end;
}

public static RuleType evalRuleType(List<String> colorCfg){
public static RuleType evalRuleType(List<String> colorCfg) {
RuleType out = null;
if (colorCfg.get(0).equals("color") || colorCfg.get(0).equals("icolor")) {
out = RuleType.PATTERN;
Expand Down Expand Up @@ -1776,14 +1776,14 @@ private Pattern doPattern(String regex, boolean caseInsensitive) {
}

protected static class Parser {
protected static List<String> split(String s){
protected static List<String> split(String s) {
List<String> out = new ArrayList<String>();
if (s.length() == 0) {
return out;
}
int depth = 0;
StringBuilder sb = new StringBuilder();
for(int i = 0; i < s.length(); i++) {
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '"') {
depth = depth == 0 ? 1 : 0;
Expand All @@ -1792,7 +1792,7 @@ protected static List<String> split(String s){
sb = new StringBuilder();
continue;
}
if(sb.length() > 0 || (c!=' ' && c!='\t')) {
if (sb.length() > 0 || (c!=' ' && c!='\t')) {
sb.append(c);
}
}
Expand All @@ -1802,7 +1802,7 @@ protected static List<String> split(String s){
return out;
}

private static String stripQuotes(String s){
private static String stripQuotes(String s) {
String out = s.trim();
if (s.startsWith("\"") && s.endsWith("\"")) {
out = s.substring(1, s.length() - 1);
Expand Down Expand Up @@ -1891,7 +1891,7 @@ public void add(String pattern) {
patternId = -1;
}

public void persist(){
public void persist() {
if (historyFile == null) {
return;
}
Expand Down Expand Up @@ -2739,7 +2739,7 @@ void gotoLine() throws IOException {
String[] pos = editBuffer.toString().split(",", 2);
int[] args = { 0, 0 };
try {
for(int i = 0; i < pos.length; i++) {
for (int i = 0; i < pos.length; i++) {
if (pos[i].trim().length() > 0) {
args[i] = Integer.parseInt(pos[i]) - 1;
if (args[i] < 0) {
Expand Down Expand Up @@ -2888,12 +2888,14 @@ void help(String help) {
boolean oldPrintLineNumbers = this.printLineNumbers;
boolean oldConstantCursor = this.constantCursor;
boolean oldAtBlanks = this.atBlanks;
boolean oldHighlight = this.highlight;
String oldEditMessage = this.editMessage;
this.editMessage = "";
this.wrapping = true;
this.atBlanks = true;
this.printLineNumbers = false;
this.constantCursor = false;
this.highlight = false;
this.buffer = newBuf;
if (!oldWrapping) {
buffer.computeAllOffsets();
Expand Down Expand Up @@ -2943,6 +2945,7 @@ void help(String help) {
this.constantCursor = oldConstantCursor;
this.shortcuts = oldShortcuts;
this.atBlanks = oldAtBlanks;
this.highlight = oldHighlight;
this.editMessage = oldEditMessage;
terminal.puts(Capability.cursor_visible);
if (!oldWrapping) {
Expand Down Expand Up @@ -3414,7 +3417,7 @@ void enableSuspension() {
}
}

void toggleSuspension(){
void toggleSuspension() {
if (restricted) {
setMessage("This function is disabled in restricted mode");
} else if (vsusp < 0) {
Expand Down
39 changes: 37 additions & 2 deletions builtins/src/test/java/org/jline/example/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.function.Supplier;

import org.jline.builtins.Commands;
import org.jline.builtins.Completers;
Expand All @@ -40,6 +41,7 @@
import org.jline.reader.impl.DefaultParser;
import org.jline.reader.impl.DefaultParser.Bracket;
import org.jline.reader.impl.LineReaderImpl;
import org.jline.reader.impl.completer.AggregateCompleter;
import org.jline.reader.impl.completer.ArgumentCompleter;
import org.jline.reader.impl.completer.StringsCompleter;
import org.jline.terminal.Cursor;
Expand All @@ -66,7 +68,8 @@ public static void usage() {
, " -system terminalBuilder.system(false)"
, " +system terminalBuilder.system(true)"
, " Completors:"
, " argumet an argument completor & autosuggestion"
, " aggregate an aggregate completor with strings Supplier"
, " argument an argument completor & autosuggestion"
, " files a completor that completes file names"
, " none no completors"
, " param a paramenter completer using Java functional interface"
Expand Down Expand Up @@ -315,6 +318,27 @@ private CmdDesc commandDescription(String command) {
}
}

private static class ReaderOptions {
LineReader reader;

public ReaderOptions() {
}

public void setReader(LineReader reader) {
this.reader = reader;
}

List<String> unsetted(boolean set) {
List<String> out = new ArrayList<>();
for (Option option : Option.values()) {
if (set == (reader.isSet(option) == option.isDef())) {
out.add((option.isDef() ? "no-" : "") + option.toString().toLowerCase().replace('_', '-'));
}
}
return out;
}
}

public static void main(String[] args) throws IOException {
try {
String prompt = "prompt> ";
Expand All @@ -337,6 +361,7 @@ public static void main(String[] args) throws IOException {
Completer completer = null;
Parser parser = null;
List<Consumer<LineReader>> callbacks = new ArrayList<>();
ReaderOptions readerOptions = new ReaderOptions();

for (int index=0; index < args.length; index++) {
switch (args[index]) {
Expand Down Expand Up @@ -401,6 +426,16 @@ public static void main(String[] args) throws IOException {
}).start();
});
break;
case "aggregate":
List<Completer> ccc = new ArrayList<>();
ccc.add(new ArgumentCompleter(
new StringsCompleter("setopt"),
new StringsCompleter(() -> readerOptions.unsetted(true))));
ccc.add(new ArgumentCompleter(
new StringsCompleter("unsetopt"),
new StringsCompleter(() -> readerOptions.unsetted(false))));
completer = new AggregateCompleter(ccc);
break;
case "argument":
argument = true;
completer = new ArgumentCompleter(
Expand Down Expand Up @@ -517,7 +552,7 @@ public void complete(LineReader reader, ParsedLine line, List<Candidate> candida
.build();

Executor executor = new Executor(reader);

readerOptions.setReader(reader);
AutopairWidgets autopairWidgets = new AutopairWidgets(reader);
AutosuggestionWidgets autosuggestionWidgets = new AutosuggestionWidgets(reader);
TailTipWidgets tailtipWidgets = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2016, 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 All @@ -12,6 +12,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.function.Supplier;

import org.jline.reader.Candidate;
import org.jline.reader.Completer;
Expand All @@ -27,11 +28,18 @@
*/
public class StringsCompleter implements Completer
{
protected final Collection<Candidate> candidates = new ArrayList<>();
protected Collection<Candidate> candidates = new ArrayList<>();
protected Supplier<List<String>> stringsSupplier;

public StringsCompleter() {
}

public StringsCompleter(Supplier<List<String>> stringsSupplier) {
assert stringsSupplier != null;
candidates = null;
this.stringsSupplier = stringsSupplier;
}

public StringsCompleter(String... strings) {
this(Arrays.asList(strings));
}
Expand All @@ -44,8 +52,7 @@ public StringsCompleter(Iterable<String> strings) {
}

public StringsCompleter(Candidate ... candidates) {
assert candidates != null;
this.candidates.addAll(Arrays.asList(candidates));
this(Arrays.asList(candidates));
}

public StringsCompleter(Collection<Candidate> candidates) {
Expand All @@ -56,7 +63,13 @@ public StringsCompleter(Collection<Candidate> candidates) {
public void complete(LineReader reader, final ParsedLine commandLine, final List<Candidate> candidates) {
assert commandLine != null;
assert candidates != null;
candidates.addAll(this.candidates);
if (this.candidates != null) {
candidates.addAll(this.candidates);
} else {
for (String string : stringsSupplier.get()) {
candidates.add(new Candidate(AttributedString.stripAnsi(string), string, null, null, null, null, true));
}
}
}

}

0 comments on commit 3a5d132

Please sign in to comment.