Skip to content

Commit

Permalink
improve toString for completer
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Turbanov authored and mattirn committed Oct 6, 2020
1 parent 64af439 commit 12dbfa4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions reader/src/main/java/org/jline/reader/Candidate.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,9 @@ public boolean complete() {
public int compareTo(Candidate o) {
return value.compareTo(o.value);
}

@Override
public String toString() {
return "Candidate{" + value + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;

Expand All @@ -28,10 +29,11 @@
*/
public class StringsCompleter implements Completer
{
protected Collection<Candidate> candidates = new ArrayList<>();
protected Collection<Candidate> candidates;
protected Supplier<Collection<String>> stringsSupplier;

public StringsCompleter() {
this(Collections.<Candidate>emptyList());
}

public StringsCompleter(Supplier<Collection<String>> stringsSupplier) {
Expand All @@ -46,6 +48,7 @@ public StringsCompleter(String... strings) {

public StringsCompleter(Iterable<String> strings) {
assert strings != null;
this.candidates = new ArrayList<>();
for (String string : strings) {
candidates.add(new Candidate(AttributedString.stripAnsi(string), string, null, null, null, null, true));
}
Expand All @@ -57,9 +60,10 @@ public StringsCompleter(Candidate ... candidates) {

public StringsCompleter(Collection<Candidate> candidates) {
assert candidates != null;
this.candidates.addAll(candidates);
this.candidates = new ArrayList<>(candidates);
}

@Override
public void complete(LineReader reader, final ParsedLine commandLine, final List<Candidate> candidates) {
assert commandLine != null;
assert candidates != null;
Expand All @@ -72,4 +76,9 @@ public void complete(LineReader reader, final ParsedLine commandLine, final List
}
}

@Override
public String toString() {
String value = candidates != null ? candidates.toString() : "{" + stringsSupplier.toString() + "}";
return "StringsCompleter" + value;
}
}

0 comments on commit 12dbfa4

Please sign in to comment.