From fc728fcb1d50065e88f5970e46f5a2e6af844ff7 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 18 Jan 2018 19:55:23 +0100 Subject: [PATCH] Make "others" and "original" groups name configurable, fixes #212 --- .../src/main/java/org/jline/reader/LineReader.java | 4 ++++ .../java/org/jline/reader/impl/LineReaderImpl.java | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/reader/src/main/java/org/jline/reader/LineReader.java b/reader/src/main/java/org/jline/reader/LineReader.java index 8daeb4f01..94f2dd98e 100644 --- a/reader/src/main/java/org/jline/reader/LineReader.java +++ b/reader/src/main/java/org/jline/reader/LineReader.java @@ -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 */ diff --git a/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java b/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java index e86fd1b37..25a6c4481 100644 --- a/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java +++ b/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java @@ -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 @@ -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 possible) { // Merge candidates if the have the same key Map> keyedCandidates = new HashMap<>(); @@ -4033,7 +4043,7 @@ Map>> 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; }; @@ -4422,7 +4432,7 @@ protected PostResult computePost(List possible, Candidate selection, for (Map.Entry> entry : sorted.entrySet()) { String group = entry.getKey(); if (group.isEmpty() && sorted.size() > 1) { - group = "others"; + group = getOthersGroupName(); } if (!group.isEmpty() && autoGroup) { strings.add(group);