Skip to content

Commit

Permalink
Make "others" and "original" groups name configurable, fixes #212
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jan 18, 2018
1 parent 6e72fc9 commit fc728fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions reader/src/main/java/org/jline/reader/LineReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ public interface LineReader {
String REMOVE_SUFFIX_CHARS = "REMOVE_SUFFIX_CHARS";
String SEARCH_TERMINATORS = "search-terminators";
String ERRORS = "errors";
/** Property for the "others" group name */
String OTHERS_GROUP_NAME = "OTHERS_GROUP_NAME";
/** Property for the "original" group name */
String ORIGINAL_GROUP_NAME = "ORIGINAL_GROUP_NAME";
/** Completion style for displaying groups name */
String COMPLETION_STYLE_GROUP = "COMPLETION_STYLE_GROUP";
/** Completion style for displaying the current selected item */
Expand Down
14 changes: 12 additions & 2 deletions reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public class LineReaderImpl implements LineReader, Flushable
public static final long DEFAULT_BLINK_MATCHING_PAREN = 500L;
public static final long DEFAULT_AMBIGUOUS_BINDING = 1000L;
public static final String DEFAULT_SECONDARY_PROMPT_PATTERN = "%M> ";
public static final String DEFAULT_OTHERS_GROUP_NAME = "others";
public static final String DEFAULT_ORIGINAL_GROUP_NAME = "original";
public static final String DEFAULT_COMPLETION_STYLE_STARTING = "36"; // cyan
public static final String DEFAULT_COMPLETION_STYLE_DESCRIPTION = "90"; // dark gray
public static final String DEFAULT_COMPLETION_STYLE_GROUP = "35;1"; // magenta
Expand Down Expand Up @@ -3991,6 +3993,14 @@ else if (isSet(Option.RECOGNIZE_EXACT)) {
return true;
}

protected String getOthersGroupName() {
return getString(OTHERS_GROUP_NAME, DEFAULT_OTHERS_GROUP_NAME);
}

protected String getOriginalGroupName() {
return getString(ORIGINAL_GROUP_NAME, DEFAULT_ORIGINAL_GROUP_NAME);
}

private void mergeCandidates(List<Candidate> possible) {
// Merge candidates if the have the same key
Map<String, List<Candidate>> keyedCandidates = new HashMap<>();
Expand Down Expand Up @@ -4033,7 +4043,7 @@ Map<String, List<Candidate>>> typoMatcher(String word, int errors, boolean caseI
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
if (map.size() > 1) {
map.computeIfAbsent(word, w -> new ArrayList<>())
.add(new Candidate(word, word, "original", null, null, null, false));
.add(new Candidate(word, word, getOriginalGroupName(), null, null, null, false));
}
return map;
};
Expand Down Expand Up @@ -4422,7 +4432,7 @@ protected PostResult computePost(List<Candidate> possible, Candidate selection,
for (Map.Entry<String, TreeMap<String, Candidate>> entry : sorted.entrySet()) {
String group = entry.getKey();
if (group.isEmpty() && sorted.size() > 1) {
group = "others";
group = getOthersGroupName();
}
if (!group.isEmpty() && autoGroup) {
strings.add(group);
Expand Down

0 comments on commit fc728fc

Please sign in to comment.