Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit 6db9050

Browse files
Prasadrao KoppulaRob McKenna
Prasadrao Koppula
authored and
Rob McKenna
committed
8297587: Upgrade JLine to 3.22.0
8304498: JShell does not switch to raw mode when there is no /bin/test Reviewed-by: coffeys
1 parent 3f8adc4 commit 6db9050

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1348
-687
lines changed

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/Binding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @see Macro
1515
* @see Reference
1616
* @see Widget
17-
* @see org.jline.keymap.KeyMap
17+
* @see jdk.internal.org.jline.keymap.KeyMap
1818
*
1919
* @author <a href="mailto:gnodet@gmail.com">Guillaume Nodet</a>
2020
*/

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/Candidate.java

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ public class Candidate implements Comparable<Candidate> {
2424
private final String suffix;
2525
private final String key;
2626
private final boolean complete;
27+
private final int sort;
2728

2829
/**
2930
* Simple constructor with only a single String as an argument.
3031
*
3132
* @param value the candidate
3233
*/
3334
public Candidate(String value) {
34-
this(value, value, null, null, null, null, true);
35+
this(value, value, null, null, null, null, true, 0);
3536
}
3637

3738
/**
@@ -44,15 +45,32 @@ public Candidate(String value) {
4445
* @param suffix the suffix
4546
* @param key the key
4647
* @param complete the complete flag
48+
* @param sort the sort flag
4749
*/
48-
public Candidate(String value, String displ, String group, String descr, String suffix, String key, boolean complete) {
50+
public Candidate(String value, String displ, String group, String descr, String suffix, String key, boolean complete, int sort) {
4951
this.value = Objects.requireNonNull(value);
5052
this.displ = Objects.requireNonNull(displ);
5153
this.group = group;
5254
this.descr = descr;
5355
this.suffix = suffix;
5456
this.key = key;
5557
this.complete = complete;
58+
this.sort = sort;
59+
}
60+
61+
/**
62+
* Constructs a new Candidate.
63+
*
64+
* @param value the value
65+
* @param displ the display string
66+
* @param group the group
67+
* @param descr the description
68+
* @param suffix the suffix
69+
* @param key the key
70+
* @param complete the complete flag
71+
*/
72+
public Candidate(String value, String displ, String group, String descr, String suffix, String key, boolean complete) {
73+
this(value, displ, group, descr, suffix, key, complete, 0);
5674
}
5775

5876
/**
@@ -133,9 +151,36 @@ public boolean complete() {
133151
return complete;
134152
}
135153

154+
/**
155+
* Integer used to override default sort logic.
156+
* @return the sort int
157+
*/
158+
public int sort() {
159+
return sort;
160+
}
161+
162+
136163
@Override
137164
public int compareTo(Candidate o) {
138-
return value.compareTo(o.value);
165+
// If both candidates have same sort, use default behavior
166+
if( sort == o.sort() ) {
167+
return value.compareTo(o.value);
168+
} else {
169+
return Integer.compare(sort, o.sort());
170+
}
171+
}
172+
173+
@Override
174+
public boolean equals(Object o) {
175+
if (this == o) return true;
176+
if (o == null || getClass() != o.getClass()) return false;
177+
Candidate candidate = (Candidate) o;
178+
return Objects.equals(value, candidate.value);
179+
}
180+
181+
@Override
182+
public int hashCode() {
183+
return Objects.hash(value);
139184
}
140185

141186
@Override

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/CompletingParsedLine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/**
1212
* An extension of {@link ParsedLine} that, being aware of the quoting and escaping rules
13-
* of the {@link org.jline.reader.Parser} that produced it, knows if and how a completion candidate
13+
* of the {@link jdk.internal.org.jline.reader.Parser} that produced it, knows if and how a completion candidate
1414
* should be escaped/quoted.
1515
*
1616
* @author Eric Bottard

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/CompletionMatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void compile(Map<LineReader.Option, Boolean> options, boolean prefix, Completing
2929
/**
3030
*
3131
* @param candidates list of candidates
32-
* @return a map of candidates that completion matcher matches
32+
* @return a list of candidates that completion matcher matches
3333
*/
3434
List<Candidate> matches(List<Candidate> candidates);
3535

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/Highlighter.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002-2019, the original author or authors.
2+
* Copyright (c) 2002-2021, the original author or authors.
33
*
44
* This software is distributable under the BSD license. See the terms of the
55
* BSD license in the documentation provided with this software.
@@ -14,7 +14,28 @@
1414

1515
public interface Highlighter {
1616

17+
/**
18+
* Highlight buffer
19+
* @param reader LineReader
20+
* @param buffer the buffer to be highlighted
21+
* @return highlighted buffer
22+
*/
1723
AttributedString highlight(LineReader reader, String buffer);
18-
public void setErrorPattern(Pattern errorPattern);
19-
public void setErrorIndex(int errorIndex);
24+
25+
/**
26+
* Refresh highlight configuration
27+
*/
28+
default void refresh(LineReader reader) {}
29+
30+
/**
31+
* Set error pattern to be highlighted
32+
* @param errorPattern error pattern to be highlighted
33+
*/
34+
void setErrorPattern(Pattern errorPattern);
35+
36+
/**
37+
* Set error index to be highlighted
38+
* @param errorIndex error index to be highlighted
39+
*/
40+
void setErrorIndex(int errorIndex);
2041
}

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/History.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ public interface History extends Iterable<History.Entry>
6161
void append(Path file, boolean incremental) throws IOException;
6262

6363
/**
64-
* Read history from the file. If incremental only the events that are not contained within the internal list are added.
64+
* Read history from the file. If checkDuplicates is <code>true</code> only the events that
65+
* are not contained within the internal list are added.
6566
* @param file History file
66-
* @param incremental If true incremental read operation is performed.
67+
* @param checkDuplicates If <code>true</code>, duplicate history entries will be discarded
6768
* @throws IOException if a problem occurs
6869
*/
69-
void read(Path file, boolean incremental) throws IOException;
70+
void read(Path file, boolean checkDuplicates) throws IOException;
7071

7172
/**
7273
* Purge history.

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/LineReader.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public interface LineReader {
352352
String AMBIGUOUS_BINDING = "ambiguous-binding";
353353

354354
/**
355-
* Columns separated list of patterns that will not be saved in history.
355+
* Colon separated list of patterns that will not be saved in history.
356356
*/
357357
String HISTORY_IGNORE = "history-ignore";
358358

@@ -467,6 +467,9 @@ enum Option {
467467

468468
/** Show command options tab completion candidates for zero length word */
469469
EMPTY_WORD_OPTIONS(true),
470+
471+
/** Disable the undo feature */
472+
DISABLE_UNDO
470473
;
471474

472475
private final boolean def;
@@ -699,7 +702,7 @@ enum SuggestionType {
699702
void runMacro(String macro);
700703

701704
/**
702-
* Read a mouse event when the {@link org.jline.utils.InfoCmp.Capability#key_mouse} sequence
705+
* Read a mouse event when the {@link jdk.internal.org.jline.utils.InfoCmp.Capability#key_mouse} sequence
703706
* has just been read on the input stream.
704707
* Compared to {@link Terminal#readMouseEvent()}, this method takes into account keys
705708
* that have been pushed back using {@link #runMacro(String)}.

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/LineReaderBuilder.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ public LineReader build() {
118118
throw new IOError(e);
119119
}
120120
}
121+
122+
String appName = this.appName;
123+
if (null == appName) {
124+
appName = terminal.getName();
125+
}
126+
121127
LineReaderImpl reader = new LineReaderImpl(terminal, appName, variables);
122128
if (history != null) {
123129
reader.setHistory(history);

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/Parser.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002-2020, the original author or authors.
2+
* Copyright (c) 2002-2021, the original author or authors.
33
*
44
* This software is distributable under the BSD license. See the terms of the
55
* BSD license in the documentation provided with this software.
@@ -12,8 +12,8 @@
1212
import java.util.regex.Pattern;
1313

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

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

@@ -34,7 +34,7 @@ default boolean validVariableName(String name) {
3434
}
3535

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

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

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/impl/CompletionMatcherImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public List<Candidate> matches(List<Candidate> candidates) {
5454
break;
5555
}
5656
}
57-
return !matching.isEmpty() ? matching.entrySet().stream().flatMap(e -> e.getValue().stream()).collect(Collectors.toList())
57+
return !matching.isEmpty() ? matching.entrySet().stream().flatMap(e -> e.getValue().stream()).distinct().collect(Collectors.toList())
5858
: new ArrayList<>();
5959
}
6060

0 commit comments

Comments
 (0)