Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @see Macro
* @see Reference
* @see Widget
* @see org.jline.keymap.KeyMap
* @see jdk.internal.org.jline.keymap.KeyMap
*
* @author <a href="mailto:gnodet@gmail.com">Guillaume Nodet</a>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ public class Candidate implements Comparable<Candidate> {
private final String suffix;
private final String key;
private final boolean complete;
private final int sort;

/**
* Simple constructor with only a single String as an argument.
*
* @param value the candidate
*/
public Candidate(String value) {
this(value, value, null, null, null, null, true);
this(value, value, null, null, null, null, true, 0);
}

/**
Expand All @@ -44,15 +45,32 @@ public Candidate(String value) {
* @param suffix the suffix
* @param key the key
* @param complete the complete flag
* @param sort the sort flag
*/
public Candidate(String value, String displ, String group, String descr, String suffix, String key, boolean complete) {
public Candidate(String value, String displ, String group, String descr, String suffix, String key, boolean complete, int sort) {
this.value = Objects.requireNonNull(value);
this.displ = Objects.requireNonNull(displ);
this.group = group;
this.descr = descr;
this.suffix = suffix;
this.key = key;
this.complete = complete;
this.sort = sort;
}

/**
* Constructs a new Candidate.
*
* @param value the value
* @param displ the display string
* @param group the group
* @param descr the description
* @param suffix the suffix
* @param key the key
* @param complete the complete flag
*/
public Candidate(String value, String displ, String group, String descr, String suffix, String key, boolean complete) {
this(value, displ, group, descr, suffix, key, complete, 0);
}

/**
Expand Down Expand Up @@ -133,9 +151,36 @@ public boolean complete() {
return complete;
}

/**
* Integer used to override default sort logic.
* @return the sort int
*/
public int sort() {
return sort;
}


@Override
public int compareTo(Candidate o) {
return value.compareTo(o.value);
// If both candidates have same sort, use default behavior
if( sort == o.sort() ) {
return value.compareTo(o.value);
} else {
return Integer.compare(sort, o.sort());
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Candidate candidate = (Candidate) o;
return Objects.equals(value, candidate.value);
}

@Override
public int hashCode() {
return Objects.hash(value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

/**
* An extension of {@link ParsedLine} that, being aware of the quoting and escaping rules
* of the {@link org.jline.reader.Parser} that produced it, knows if and how a completion candidate
* of the {@link jdk.internal.org.jline.reader.Parser} that produced it, knows if and how a completion candidate
* should be escaped/quoted.
*
* @author Eric Bottard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void compile(Map<LineReader.Option, Boolean> options, boolean prefix, Completing
/**
*
* @param candidates list of candidates
* @return a map of candidates that completion matcher matches
* @return a list of candidates that completion matcher matches
*/
List<Candidate> matches(List<Candidate> candidates);

Expand Down
Original file line number Diff line number Diff line change
@@ -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 All @@ -14,7 +14,28 @@

public interface Highlighter {

/**
* Highlight buffer
* @param reader LineReader
* @param buffer the buffer to be highlighted
* @return highlighted buffer
*/
AttributedString highlight(LineReader reader, String buffer);
public void setErrorPattern(Pattern errorPattern);
public void setErrorIndex(int errorIndex);

/**
* Refresh highlight configuration
*/
default void refresh(LineReader reader) {}

/**
* Set error pattern to be highlighted
* @param errorPattern error pattern to be highlighted
*/
void setErrorPattern(Pattern errorPattern);

/**
* Set error index to be highlighted
* @param errorIndex error index to be highlighted
*/
void setErrorIndex(int errorIndex);
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ public interface History extends Iterable<History.Entry>
void append(Path file, boolean incremental) throws IOException;

/**
* Read history from the file. If incremental only the events that are not contained within the internal list are added.
* Read history from the file. If checkDuplicates is <code>true</code> only the events that
* are not contained within the internal list are added.
* @param file History file
* @param incremental If true incremental read operation is performed.
* @param checkDuplicates If <code>true</code>, duplicate history entries will be discarded
* @throws IOException if a problem occurs
*/
void read(Path file, boolean incremental) throws IOException;
void read(Path file, boolean checkDuplicates) throws IOException;

/**
* Purge history.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public interface LineReader {
String AMBIGUOUS_BINDING = "ambiguous-binding";

/**
* Columns separated list of patterns that will not be saved in history.
* Colon separated list of patterns that will not be saved in history.
*/
String HISTORY_IGNORE = "history-ignore";

Expand Down Expand Up @@ -467,6 +467,9 @@ enum Option {

/** Show command options tab completion candidates for zero length word */
EMPTY_WORD_OPTIONS(true),

/** Disable the undo feature */
DISABLE_UNDO
;

private final boolean def;
Expand Down Expand Up @@ -699,7 +702,7 @@ enum SuggestionType {
void runMacro(String macro);

/**
* Read a mouse event when the {@link org.jline.utils.InfoCmp.Capability#key_mouse} sequence
* Read a mouse event when the {@link jdk.internal.org.jline.utils.InfoCmp.Capability#key_mouse} sequence
* has just been read on the input stream.
* Compared to {@link Terminal#readMouseEvent()}, this method takes into account keys
* that have been pushed back using {@link #runMacro(String)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ public LineReader build() {
throw new IOError(e);
}
}

String appName = this.appName;
if (null == appName) {
appName = terminal.getName();
}

LineReaderImpl reader = new LineReaderImpl(terminal, appName, variables);
if (history != null) {
reader.setHistory(history);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2020, 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 All @@ -12,8 +12,8 @@
import java.util.regex.Pattern;

public interface Parser {
static final String REGEX_VARIABLE = "[a-zA-Z_]{1,}[a-zA-Z0-9_-]*";
static final String REGEX_COMMAND = "[:]{0,1}[a-zA-Z]{1,}[a-zA-Z0-9_-]*";
String REGEX_VARIABLE = "[a-zA-Z_]+[a-zA-Z0-9_-]*";
String REGEX_COMMAND = "[:]?[a-zA-Z]+[a-zA-Z0-9_-]*";

ParsedLine parse(String line, int cursor, ParseContext context) throws SyntaxError;

Expand All @@ -34,7 +34,7 @@ default boolean validVariableName(String name) {
}

default String getCommand(final String line) {
String out = "";
String out;
Pattern patternCommand = Pattern.compile("^\\s*" + REGEX_VARIABLE + "=(" + REGEX_COMMAND + ")(\\s+|$)");
Matcher matcher = patternCommand.matcher(line);
if (matcher.find()) {
Expand Down Expand Up @@ -68,7 +68,7 @@ enum ParseContext {

/** Parsed words will have all characters present in input line
* including quotes and escape chars.
* May throw EOFError in which case we have incomplete input.
* We should tolerate and ignore errors.
*/
SPLIT_LINE,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public List<Candidate> matches(List<Candidate> candidates) {
break;
}
}
return !matching.isEmpty() ? matching.entrySet().stream().flatMap(e -> e.getValue().stream()).collect(Collectors.toList())
return !matching.isEmpty() ? matching.entrySet().stream().flatMap(e -> e.getValue().stream()).distinct().collect(Collectors.toList())
: new ArrayList<>();
}

Expand Down
Loading