Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

8273682: Upgrade Jline to 3.20.0 #197

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 + "}";
}
}
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2002-2020, 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.
*
* https://opensource.org/licenses/BSD-3-Clause
*/
package jdk.internal.org.jline.reader;

import java.util.List;
import java.util.Map;

public interface CompletionMatcher {

/**
* Compiles completion matcher functions
*
* @param options LineReader options
* @param prefix invoked by complete-prefix or expand-or-complete-prefix widget
* @param line The parsed line within which completion has been requested
* @param caseInsensitive if completion is case insensitive or not
* @param errors number of errors accepted in matching
* @param originalGroupName value of JLineReader variable original-group-name
*/
void compile(Map<LineReader.Option, Boolean> options, boolean prefix, CompletingParsedLine line
, boolean caseInsensitive, int errors, String originalGroupName);

/**
*
* @param candidates list of candidates
* @return a map of candidates that completion matcher matches
*/
List<Candidate> matches(List<Candidate> candidates);

/**
*
* @return a candidate that have exact match, null if no exact match found
*/
Candidate exactMatch();

/**
*
* @return a common prefix of matched candidates
*/
String getCommonPrefix();

}

This file was deleted.

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2016, the original author or authors.
* Copyright (c) 2002-2020, 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 @@ -15,6 +15,7 @@
public class EndOfFileException extends RuntimeException {

private static final long serialVersionUID = 528485360925144689L;
private String partialLine;

public EndOfFileException() {
}
Expand All @@ -34,4 +35,13 @@ public EndOfFileException(Throwable cause) {
public EndOfFileException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

public EndOfFileException partialLine(String partialLine) {
this.partialLine = partialLine;
return this;
}

public String getPartialLine() {
return partialLine;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2019, the original author or authors.
* Copyright (c) 2002-2021, 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 Down Expand Up @@ -294,7 +294,13 @@ public interface LineReader {
String COMMENT_BEGIN = "comment-begin";
String BELL_STYLE = "bell-style";
String PREFER_VISIBLE_BELL = "prefer-visible-bell";
/** tab completion: if candidates are more than list-max a question will be asked before displaying them */
String LIST_MAX = "list-max";
/**
* tab completion: if candidates are less than menu-list-max
* they are displayed in a list below the field to be completed
*/
String MENU_LIST_MAX = "menu-list-max";
String DISABLE_HISTORY = "disable-history";
String DISABLE_COMPLETION = "disable-completion";
String EDITING_MODE = "editing-mode";
Expand All @@ -303,19 +309,27 @@ public interface LineReader {
String WORDCHARS = "WORDCHARS";
String REMOVE_SUFFIX_CHARS = "REMOVE_SUFFIX_CHARS";
String SEARCH_TERMINATORS = "search-terminators";
/** Number of matching errors that are accepted by the completion matcher */
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";
String COMPLETION_STYLE_LIST_GROUP = "COMPLETION_STYLE_LIST_GROUP";
/** Completion style for displaying the current selected item */
String COMPLETION_STYLE_SELECTION = "COMPLETION_STYLE_SELECTION";
String COMPLETION_STYLE_LIST_SELECTION = "COMPLETION_STYLE_LIST_SELECTION";
/** Completion style for displaying the candidate description */
String COMPLETION_STYLE_DESCRIPTION = "COMPLETION_STYLE_DESCRIPTION";
String COMPLETION_STYLE_LIST_DESCRIPTION = "COMPLETION_STYLE_LIST_DESCRIPTION";
/** Completion style for displaying the matching part of candidates */
String COMPLETION_STYLE_STARTING = "COMPLETION_STYLE_STARTING";
String COMPLETION_STYLE_LIST_STARTING = "COMPLETION_STYLE_LIST_STARTING";
/** Completion style for displaying the list */
String COMPLETION_STYLE_BACKGROUND = "COMPLETION_STYLE_BACKGROUND";
String COMPLETION_STYLE_LIST_BACKGROUND = "COMPLETION_STYLE_LIST_BACKGROUND";
/**
* Set the template for prompts for secondary (continuation) lines.
* This is a prompt template as described in the class header.
Expand Down Expand Up @@ -370,10 +384,20 @@ public interface LineReader {
*/
String FEATURES_MAX_BUFFER_SIZE = "features-max-buffer-size";

/**
* Min buffer size for tab auto-suggestions.
* For shorter buffer sizes auto-suggestions are not resolved.
*/
String SUGGESTIONS_MIN_BUFFER_SIZE = "suggestions-min-buffer-size";

Map<String, KeyMap<Binding>> defaultKeyMaps();

enum Option {
COMPLETE_IN_WORD,
/** use camel case completion matcher */
COMPLETE_MATCHER_CAMELCASE,
/** use type completion matcher */
COMPLETE_MATCHER_TYPO(true),
DISABLE_EVENT_EXPANSION,
HISTORY_VERIFY,
HISTORY_IGNORE_SPACE(true),
Expand All @@ -386,9 +410,13 @@ enum Option {
AUTO_GROUP(true),
AUTO_MENU(true),
AUTO_LIST(true),
/** list candidates below the field to be completed */
AUTO_MENU_LIST,
RECOGNIZE_EXACT,
/** display group name before each group (else display all group names first) */
GROUP(true),
/** when double tab to select candidate keep candidates grouped (else loose grouping) */
GROUP_PERSIST,
/** if completion is case insensitive or not */
CASE_INSENSITIVE,
LIST_AMBIGUOUS,
Expand All @@ -414,7 +442,8 @@ enum Option {
DELAY_LINE_WRAP,
AUTO_PARAM_SLASH(true),
AUTO_REMOVE_SLASH(true),
USE_FORWARD_SLASH(false),
/** FileNameCompleter: Use '/' character as a file directory separator */
USE_FORWARD_SLASH,
/** When hitting the <code>&lt;tab&gt;</code> key at the beginning of the line, insert a tabulation
* instead of completing. This is mainly useful when {@link #BRACKETED_PASTE} is
* disabled, so that copy/paste of indented text does not trigger completion.
Expand Down Expand Up @@ -450,6 +479,11 @@ enum Option {
this.def = def;
}

public final boolean isSet(Map<Option, Boolean> options) {
Boolean b = options.get(this);
return b != null ? b : this.isDef();
}

public boolean isDef() {
return def;
}
Expand Down Expand Up @@ -489,8 +523,9 @@ enum SuggestionType {
* Equivalent to <code>readLine(null, null, null)</code>.
*
* @return the line read
* @throws UserInterruptException If the call was interrupted by the user.
* @throws EndOfFileException If the end of the input stream was reached.
* @throws UserInterruptException if readLine was interrupted (using Ctrl-C for example)
* @throws EndOfFileException if an EOF has been found (using Ctrl-D for example)
* @throws java.io.IOError in case of other i/o errors
*/
String readLine() throws UserInterruptException, EndOfFileException;

Expand All @@ -502,8 +537,9 @@ enum SuggestionType {
*
* @param mask The mask character, <code>null</code> or <code>0</code>.
* @return A line that is read from the terminal, can never be null.
* @throws UserInterruptException If the call was interrupted by the user.
* @throws EndOfFileException If the end of the input stream was reached.
* @throws UserInterruptException if readLine was interrupted (using Ctrl-C for example)
* @throws EndOfFileException if an EOF has been found (using Ctrl-D for example)
* @throws java.io.IOError in case of other i/o errors
*/
String readLine(Character mask) throws UserInterruptException, EndOfFileException;

Expand All @@ -515,8 +551,9 @@ enum SuggestionType {
*
* @param prompt The prompt to issue to the terminal, may be null.
* @return A line that is read from the terminal, can never be null.
* @throws UserInterruptException If the call was interrupted by the user.
* @throws EndOfFileException If the end of the input stream was reached.
* @throws UserInterruptException if readLine was interrupted (using Ctrl-C for example)
* @throws EndOfFileException if an EOF has been found (using Ctrl-D for example)
* @throws java.io.IOError in case of other i/o errors
*/
String readLine(String prompt) throws UserInterruptException, EndOfFileException;

Expand All @@ -529,8 +566,9 @@ enum SuggestionType {
* @param prompt The prompt to issue to the terminal, may be null.
* @param mask The mask character, <code>null</code> or <code>0</code>.
* @return A line that is read from the terminal, can never be null.
* @throws UserInterruptException If the call was interrupted by the user.
* @throws EndOfFileException If the end of the input stream was reached.
* @throws UserInterruptException if readLine was interrupted (using Ctrl-C for example)
* @throws EndOfFileException if an EOF has been found (using Ctrl-D for example)
* @throws java.io.IOError in case of other i/o errors
*/
String readLine(String prompt, Character mask) throws UserInterruptException, EndOfFileException;

Expand All @@ -546,8 +584,9 @@ enum SuggestionType {
* @param mask The character mask, may be null.
* @param buffer The default value presented to the user to edit, may be null.
* @return A line that is read from the terminal, can never be null.
* @throws UserInterruptException If the call was interrupted by the user.
* @throws EndOfFileException If the end of the input stream was reached.
* @throws UserInterruptException if readLine was interrupted (using Ctrl-C for example)
* @throws EndOfFileException if an EOF has been found (using Ctrl-D for example)
* @throws java.io.IOError in case of other i/o errors
*/
String readLine(String prompt, Character mask, String buffer) throws UserInterruptException, EndOfFileException;

Expand All @@ -568,8 +607,6 @@ enum SuggestionType {
* @throws UserInterruptException if readLine was interrupted (using Ctrl-C for example)
* @throws EndOfFileException if an EOF has been found (using Ctrl-D for example)
* @throws java.io.IOError in case of other i/o errors
* @throws UserInterruptException If the call was interrupted by the user.
* @throws EndOfFileException If the end of the input stream was reached.
*/
String readLine(String prompt, String rightPrompt, Character mask, String buffer) throws UserInterruptException, EndOfFileException;

Expand All @@ -590,8 +627,6 @@ enum SuggestionType {
* @throws UserInterruptException if readLine was interrupted (using Ctrl-C for example)
* @throws EndOfFileException if an EOF has been found (using Ctrl-D for example)
* @throws java.io.IOError in case of other i/o errors
* @throws UserInterruptException If the call was interrupted by the user.
* @throws EndOfFileException If the end of the input stream was reached.
*/
String readLine(String prompt, String rightPrompt, MaskingCallback maskingCallback, String buffer) throws UserInterruptException, EndOfFileException;

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2018, the original author or authors.
* Copyright (c) 2002-2020, 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 Down Expand Up @@ -36,6 +36,7 @@ public static LineReaderBuilder builder() {
Highlighter highlighter;
Parser parser;
Expander expander;
CompletionMatcher completionMatcher;

private LineReaderBuilder() {
}
Expand Down Expand Up @@ -103,6 +104,11 @@ public LineReaderBuilder expander(Expander expander) {
return this;
}

public LineReaderBuilder completionMatcher(CompletionMatcher completionMatcher) {
this.completionMatcher = completionMatcher;
return this;
}

public LineReader build() {
Terminal terminal = this.terminal;
if (terminal == null) {
Expand Down Expand Up @@ -133,6 +139,9 @@ public LineReader build() {
if (expander != null) {
reader.setExpander(expander);
}
if (completionMatcher != null) {
reader.setCompletionMatcher(completionMatcher);
}
for (Map.Entry<LineReader.Option, Boolean> e : options.entrySet()) {
reader.option(e.getKey(), e.getValue());
}
Expand Down