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

Commit 7d292c8

Browse files
Ekaterina VergizovaYuri Nesterenko
Ekaterina Vergizova
authored and
Yuri Nesterenko
committed
8241598: Upgrade JLine to 3.14.0
Upgrading to JLine 3.14.0 Backport-of: f1ef83b
1 parent c229f3c commit 7d292c8

40 files changed

+1343
-237
lines changed

src/jdk.internal.le/share/classes/jdk/internal/org/jline/keymap/BindingReader.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,33 @@ public <T> T readBinding(KeyMap<T> keys, KeyMap<T> local, boolean block) {
117117
return null;
118118
}
119119

120+
public String readStringUntil(String sequence) {
121+
StringBuilder sb = new StringBuilder();
122+
if (!pushBackChar.isEmpty()) {
123+
pushBackChar.forEach(sb::appendCodePoint);
124+
}
125+
try {
126+
char[] buf = new char[64];
127+
while (true) {
128+
int idx = sb.indexOf(sequence, Math.max(0, sb.length() - buf.length - sequence.length()));
129+
if (idx >= 0) {
130+
String rem = sb.substring(idx + sequence.length());
131+
runMacro(rem);
132+
return sb.substring(0, idx);
133+
}
134+
int l = reader.readBuffered(buf);
135+
if (l < 0) {
136+
throw new ClosedException();
137+
}
138+
sb.append(buf, 0, l);
139+
}
140+
} catch (ClosedException e) {
141+
throw new EndOfFileException(e);
142+
} catch (IOException e) {
143+
throw new IOError(e);
144+
}
145+
}
146+
120147
/**
121148
* Read a codepoint from the terminal.
122149
*
@@ -144,6 +171,47 @@ public int readCharacter() {
144171
}
145172
}
146173

174+
public int readCharacterBuffered() {
175+
try {
176+
if (pushBackChar.isEmpty()) {
177+
char[] buf = new char[32];
178+
int l = reader.readBuffered(buf);
179+
if (l <= 0) {
180+
return -1;
181+
}
182+
int s = 0;
183+
for (int i = 0; i < l; ) {
184+
int c = buf[i++];
185+
if (Character.isHighSurrogate((char) c)) {
186+
s = c;
187+
if (i < l) {
188+
c = buf[i++];
189+
pushBackChar.addLast(Character.toCodePoint((char) s, (char) c));
190+
} else {
191+
break;
192+
}
193+
} else {
194+
s = 0;
195+
pushBackChar.addLast(c);
196+
}
197+
}
198+
if (s != 0) {
199+
int c = reader.read();
200+
if (c >= 0) {
201+
pushBackChar.addLast(Character.toCodePoint((char) s, (char) c));
202+
} else {
203+
return -1;
204+
}
205+
}
206+
}
207+
return pushBackChar.pop();
208+
} catch (ClosedException e) {
209+
throw new EndOfFileException(e);
210+
} catch (IOException e) {
211+
throw new IOError(e);
212+
}
213+
}
214+
147215
public int peekCharacter(long timeout) {
148216
if (!pushBackChar.isEmpty()) {
149217
return pushBackChar.peek();

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002-2018, the original author or authors.
2+
* Copyright (c) 2002-2019, 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.
@@ -46,9 +46,8 @@ public Candidate(String value) {
4646
* @param complete the complete flag
4747
*/
4848
public Candidate(String value, String displ, String group, String descr, String suffix, String key, boolean complete) {
49-
Objects.requireNonNull(value);
50-
this.value = value;
51-
this.displ = displ;
49+
this.value = Objects.requireNonNull(value);
50+
this.displ = Objects.requireNonNull(displ);
5251
this.group = group;
5352
this.descr = descr;
5453
this.suffix = suffix;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2002-2019, the original author or authors.
3+
*
4+
* This software is distributable under the BSD license. See the terms of the
5+
* BSD license in the documentation provided with this software.
6+
*
7+
* https://opensource.org/licenses/BSD-3-Clause
8+
*/
9+
package org.jline.reader;
10+
11+
import java.io.IOException;
12+
import java.nio.file.Path;
13+
14+
public class ConfigurationPath {
15+
private Path appConfig;
16+
private Path userConfig;
17+
18+
/**
19+
* Configuration class constructor.
20+
* @param appConfig Application configuration directory
21+
* @param userConfig User private configuration directory
22+
*/
23+
public ConfigurationPath(Path appConfig, Path userConfig) {
24+
this.appConfig = appConfig;
25+
this.userConfig = userConfig;
26+
}
27+
28+
/**
29+
* Search configuration file first from userConfig and then appConfig directory. Returns null if file is not found.
30+
* @param name Configuration file name.
31+
* @return Configuration file.
32+
*
33+
*/
34+
public Path getConfig(String name) {
35+
Path out = null;
36+
if (userConfig != null && userConfig.resolve(name).toFile().exists()) {
37+
out = userConfig.resolve(name);
38+
} else if (appConfig != null && appConfig.resolve(name).toFile().exists()) {
39+
out = appConfig.resolve(name);
40+
}
41+
return out;
42+
}
43+
44+
/**
45+
* Search configuration file from userConfig directory. Returns null if file is not found.
46+
* @param name Configuration file name.
47+
* @return Configuration file.
48+
* @throws IOException When we do not have read access to the file or directory.
49+
*
50+
*/
51+
public Path getUserConfig(String name) throws IOException {
52+
return getUserConfig(name, false);
53+
}
54+
55+
/**
56+
* Search configuration file from userConfig directory. Returns null if file is not found.
57+
* @param name Configuration file name
58+
* @param create When true configuration file is created if not found.
59+
* @return Configuration file.
60+
* @throws IOException When we do not have read/write access to the file or directory.
61+
*/
62+
public Path getUserConfig(String name, boolean create) throws IOException {
63+
Path out = null;
64+
if (userConfig != null) {
65+
if (!userConfig.resolve(name).toFile().exists() && create) {
66+
userConfig.resolve(name).toFile().createNewFile();
67+
}
68+
if (userConfig.resolve(name).toFile().exists()) {
69+
out = userConfig.resolve(name);
70+
}
71+
}
72+
return out;
73+
}
74+
75+
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,33 @@ public class EOFError extends SyntaxError {
2323
private static final long serialVersionUID = 1L;
2424

2525
private final String missing;
26+
private final int openBrackets;
27+
private final String nextClosingBracket;
2628

2729
public EOFError(int line, int column, String message) {
2830
this(line, column, message, null);
2931
}
3032

3133
public EOFError(int line, int column, String message, String missing) {
34+
this(line, column, message, missing, 0, null);
35+
}
36+
37+
public EOFError(int line, int column, String message, String missing, int openBrackets, String nextClosingBracket) {
3238
super(line, column, message);
3339
this.missing = missing;
40+
this.openBrackets = openBrackets;
41+
this.nextClosingBracket = nextClosingBracket;
3442
}
3543

3644
public String getMissing() {
3745
return missing;
3846
}
47+
48+
public int getOpenBrackets(){
49+
return openBrackets;
50+
}
51+
52+
public String getNextClosingBracket() {
53+
return nextClosingBracket;
54+
}
3955
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2002-2019, the original author or authors.
3+
*
4+
* This software is distributable under the BSD license. See the terms of the
5+
* BSD license in the documentation provided with this software.
6+
*
7+
* https://opensource.org/licenses/BSD-3-Clause
8+
*/
9+
package jdk.internal.org.jline.reader;
10+
11+
import java.io.IOException;
12+
import java.util.List;
13+
14+
public interface Editor {
15+
public void open(List<String> files) throws IOException;
16+
public void run() throws IOException;
17+
public void setRestricted(boolean restricted);
18+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002-2016, the original author or authors.
2+
* Copyright (c) 2002-2019, 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.
@@ -8,9 +8,13 @@
88
*/
99
package jdk.internal.org.jline.reader;
1010

11+
import java.util.regex.Pattern;
12+
1113
import jdk.internal.org.jline.utils.AttributedString;
1214

1315
public interface Highlighter {
1416

1517
AttributedString highlight(LineReader reader, String buffer);
18+
public void setErrorPattern(Pattern errorPattern);
19+
public void setErrorIndex(int errorIndex);
1620
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,25 @@ public interface History extends Iterable<History.Entry>
4545
/**
4646
* Write history to the file. If incremental only the events that are new since the last incremental operation to
4747
* the file are added.
48+
* @param file History file
49+
* @param incremental If true incremental write operation is performed.
4850
* @throws IOException if a problem occurs
4951
*/
5052
void write(Path file, boolean incremental) throws IOException;
5153

5254
/**
5355
* Append history to the file. If incremental only the events that are new since the last incremental operation to
5456
* the file are added.
57+
* @param file History file
58+
* @param incremental If true incremental append operation is performed.
5559
* @throws IOException if a problem occurs
5660
*/
5761
void append(Path file, boolean incremental) throws IOException;
5862

5963
/**
6064
* Read history from the file. If incremental only the events that are not contained within the internal list are added.
65+
* @param file History file
66+
* @param incremental If true incremental read operation is performed.
6167
* @throws IOException if a problem occurs
6268
*/
6369
void read(Path file, boolean incremental) throws IOException;
@@ -133,6 +139,11 @@ public boolean hasNext() {
133139
public Entry next() {
134140
return it.previous();
135141
}
142+
@Override
143+
public void remove() {
144+
it.remove();
145+
resetIndex();
146+
}
136147
};
137148
}
138149

@@ -191,4 +202,9 @@ public Entry next() {
191202
* all of the other iterator.
192203
*/
193204
void moveToEnd();
205+
206+
/**
207+
* Reset index after remove
208+
*/
209+
void resetIndex();
194210
}

0 commit comments

Comments
 (0)