newLines, int targetCursorPos, boolean
int lineIndex = 0;
int currentPos = 0;
- int numLines = Math.max(oldLines.size(), newLines.size());
+ int numLines = Math.min(rows, Math.max(oldLines.size(), newLines.size()));
boolean wrapNeeded = false;
while (lineIndex < numLines) {
AttributedString oldLine =
diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/InfoCmp.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/InfoCmp.java
index 68f77f638b7..23a76071486 100644
--- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/InfoCmp.java
+++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/InfoCmp.java
@@ -503,7 +503,7 @@ public enum Capability {
public String[] getNames() {
return getCapabilitiesByName().entrySet().stream()
.filter(e -> e.getValue() == this)
- .map(Map.Entry::getValue)
+ .map(Map.Entry::getKey)
.toArray(String[]::new);
}
diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlocking.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlocking.java
index 6d37a20083e..f8cb53489f9 100644
--- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlocking.java
+++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlocking.java
@@ -95,13 +95,9 @@ public void close() throws IOException {
@Override
public int read(long timeout, boolean isPeek) throws IOException {
- boolean isInfinite = (timeout <= 0L);
- while (!bytes.hasRemaining() && (isInfinite || timeout > 0L)) {
- long start = 0;
- if (!isInfinite) {
- start = System.currentTimeMillis();
- }
- int c = reader.read(timeout);
+ Timeout t = new Timeout(timeout);
+ while (!bytes.hasRemaining() && !t.elapsed()) {
+ int c = reader.read(t.timeout());
if (c == EOF) {
return EOF;
}
@@ -117,9 +113,6 @@ public int read(long timeout, boolean isPeek) throws IOException {
encoder.encode(chars, bytes, false);
bytes.flip();
}
- if (!isInfinite) {
- timeout -= System.currentTimeMillis() - start;
- }
}
if (bytes.hasRemaining()) {
if (isPeek) {
@@ -151,21 +144,17 @@ public NonBlockingInputStreamReader(NonBlockingInputStream inputStream, Charset
public NonBlockingInputStreamReader(NonBlockingInputStream input, CharsetDecoder decoder) {
this.input = input;
this.decoder = decoder;
- this.bytes = ByteBuffer.allocate(4);
- this.chars = CharBuffer.allocate(2);
+ this.bytes = ByteBuffer.allocate(2048);
+ this.chars = CharBuffer.allocate(1024);
this.bytes.limit(0);
this.chars.limit(0);
}
@Override
protected int read(long timeout, boolean isPeek) throws IOException {
- boolean isInfinite = (timeout <= 0L);
- while (!chars.hasRemaining() && (isInfinite || timeout > 0L)) {
- long start = 0;
- if (!isInfinite) {
- start = System.currentTimeMillis();
- }
- int b = input.read(timeout);
+ Timeout t = new Timeout(timeout);
+ while (!chars.hasRemaining() && !t.elapsed()) {
+ int b = input.read(t.timeout());
if (b == EOF) {
return EOF;
}
@@ -181,10 +170,6 @@ protected int read(long timeout, boolean isPeek) throws IOException {
decoder.decode(bytes, chars, false);
chars.flip();
}
-
- if (!isInfinite) {
- timeout -= System.currentTimeMillis() - start;
- }
}
if (chars.hasRemaining()) {
if (isPeek) {
@@ -198,46 +183,37 @@ protected int read(long timeout, boolean isPeek) throws IOException {
}
@Override
- public int readBuffered(char[] b) throws IOException {
+ public int readBuffered(char[] b, int off, int len, long timeout) throws IOException {
if (b == null) {
throw new NullPointerException();
- } else if (b.length == 0) {
+ } else if (off < 0 || len < 0 || off + len < b.length) {
+ throw new IllegalArgumentException();
+ } else if (len == 0) {
return 0;
+ } else if (chars.hasRemaining()) {
+ int r = Math.min(len, chars.remaining());
+ chars.get(b, off, r);
+ return r;
} else {
- if (chars.hasRemaining()) {
- int r = Math.min(b.length, chars.remaining());
- chars.get(b);
- return r;
- } else {
- byte[] buf = new byte[b.length];
- int l = input.readBuffered(buf);
- if (l < 0) {
- return l;
- } else {
- ByteBuffer currentBytes;
- if (bytes.hasRemaining()) {
- int transfer = bytes.remaining();
- byte[] newBuf = new byte[l + transfer];
- bytes.get(newBuf, 0, transfer);
- System.arraycopy(buf, 0, newBuf, transfer, l);
- currentBytes = ByteBuffer.wrap(newBuf);
- bytes.position(0);
- bytes.limit(0);
- } else {
- currentBytes = ByteBuffer.wrap(buf, 0, l);
- }
- CharBuffer chars = CharBuffer.wrap(b);
- decoder.decode(currentBytes, chars, false);
- chars.flip();
- if (currentBytes.hasRemaining()) {
- int pos = bytes.position();
- bytes.limit(bytes.limit() + currentBytes.remaining());
- bytes.put(currentBytes);
- bytes.position(pos);
- }
- return chars.remaining();
+ Timeout t = new Timeout(timeout);
+ while (!chars.hasRemaining() && !t.elapsed()) {
+ if (!bytes.hasRemaining()) {
+ bytes.position(0);
+ bytes.limit(0);
+ }
+ int nb = input.readBuffered(bytes.array(), bytes.limit(),
+ bytes.capacity() - bytes.limit(), t.timeout());
+ if (nb < 0) {
+ return nb;
}
+ bytes.limit(bytes.limit() + nb);
+ chars.clear();
+ decoder.decode(bytes, chars, false);
+ chars.flip();
}
+ int nb = Math.min(len, chars.remaining());
+ chars.get(b, off, nb);
+ return nb;
}
}
diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingInputStream.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingInputStream.java
index 1fb53bf5ef8..a4283eb7006 100644
--- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingInputStream.java
+++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingInputStream.java
@@ -79,12 +79,34 @@ public int read(byte b[], int off, int len) throws IOException {
}
public int readBuffered(byte[] b) throws IOException {
+ return readBuffered(b, 0L);
+ }
+
+ public int readBuffered(byte[] b, long timeout) throws IOException {
+ return readBuffered(b, 0, b.length, timeout);
+ }
+
+ public int readBuffered(byte[] b, int off, int len, long timeout) throws IOException {
if (b == null) {
throw new NullPointerException();
- } else if (b.length == 0) {
+ } else if (off < 0 || len < 0 || off + len < b.length) {
+ throw new IllegalArgumentException();
+ } else if (len == 0) {
return 0;
} else {
- return super.read(b, 0, b.length);
+ Timeout t = new Timeout(timeout);
+ int nb = 0;
+ while (!t.elapsed()) {
+ int r = read(nb > 0 ? 1 : t.timeout());
+ if (r < 0) {
+ return nb > 0 ? nb : r;
+ }
+ b[off + nb++] = (byte) r;
+ if (nb >= len || t.isInfinite()) {
+ break;
+ }
+ }
+ return nb;
}
}
diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingInputStreamImpl.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingInputStreamImpl.java
index 94c831c361d..680047fbe60 100644
--- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingInputStreamImpl.java
+++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingInputStreamImpl.java
@@ -123,20 +123,17 @@ else if (!isPeek && timeout <= 0L && !threadIsReading) {
notifyAll();
}
- boolean isInfinite = (timeout <= 0L);
-
/*
* So the thread is currently doing the reading for us. So
* now we play the waiting game.
*/
- while (isInfinite || timeout > 0L) {
- long start = System.currentTimeMillis ();
-
+ Timeout t = new Timeout(timeout);
+ while (!t.elapsed()) {
try {
if (Thread.interrupted()) {
throw new InterruptedException();
}
- wait(timeout);
+ wait(t.timeout());
}
catch (InterruptedException e) {
exception = (IOException) new InterruptedIOException().initCause(e);
@@ -155,10 +152,6 @@ else if (!isPeek && timeout <= 0L && !threadIsReading) {
assert exception == null;
break;
}
-
- if (!isInfinite) {
- timeout -= System.currentTimeMillis() - start;
- }
}
}
diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingPumpInputStream.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingPumpInputStream.java
index a48be007e24..5a361344350 100644
--- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingPumpInputStream.java
+++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingPumpInputStream.java
@@ -45,24 +45,17 @@ public OutputStream getOutputStream() {
}
private int wait(ByteBuffer buffer, long timeout) throws IOException {
- boolean isInfinite = (timeout <= 0L);
- long end = 0;
- if (!isInfinite) {
- end = System.currentTimeMillis() + timeout;
- }
- while (!closed && !buffer.hasRemaining() && (isInfinite || timeout > 0L)) {
+ Timeout t = new Timeout(timeout);
+ while (!closed && !buffer.hasRemaining() && !t.elapsed()) {
// Wake up waiting readers/writers
notifyAll();
try {
- wait(timeout);
+ wait(t.timeout());
checkIoException();
} catch (InterruptedException e) {
checkIoException();
throw new InterruptedIOException();
}
- if (!isInfinite) {
- timeout = end - System.currentTimeMillis();
- }
}
return buffer.hasRemaining()
? 0
@@ -107,17 +100,25 @@ public synchronized int read(long timeout, boolean isPeek) throws IOException {
}
@Override
- public synchronized int readBuffered(byte[] b) throws IOException {
- checkIoException();
- int res = wait(readBuffer, 0L);
- if (res >= 0) {
- res = 0;
- while (res < b.length && readBuffer.hasRemaining()) {
- b[res++] = (byte) (readBuffer.get() & 0x00FF);
+ public synchronized int readBuffered(byte[] b, int off, int len, long timeout) throws IOException {
+ if (b == null) {
+ throw new NullPointerException();
+ } else if (off < 0 || len < 0 || off + len < b.length) {
+ throw new IllegalArgumentException();
+ } else if (len == 0) {
+ return 0;
+ } else {
+ checkIoException();
+ int res = wait(readBuffer, timeout);
+ if (res >= 0) {
+ res = 0;
+ while (res < len && readBuffer.hasRemaining()) {
+ b[off + res++] = (byte) (readBuffer.get() & 0x00FF);
+ }
}
+ rewind(readBuffer, writeBuffer);
+ return res;
}
- rewind(readBuffer, writeBuffer);
- return res;
}
public synchronized void setIoException(IOException exception) {
diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingPumpReader.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingPumpReader.java
index 5f152c16e64..f36423f03b8 100644
--- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingPumpReader.java
+++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingPumpReader.java
@@ -106,10 +106,12 @@ protected int read(long timeout, boolean isPeek) throws IOException {
}
@Override
- public int readBuffered(char[] b) throws IOException {
+ public int readBuffered(char[] b, int off, int len, long timeout) throws IOException {
if (b == null) {
throw new NullPointerException();
- } else if (b.length == 0) {
+ } else if (off < 0 || len < 0 || off + len < b.length) {
+ throw new IllegalArgumentException();
+ } else if (len == 0) {
return 0;
} else {
final ReentrantLock lock = this.lock;
@@ -117,7 +119,13 @@ public int readBuffered(char[] b) throws IOException {
try {
if (!closed && count == 0) {
try {
- notEmpty.await();
+ if (timeout > 0) {
+ if (!notEmpty.await(timeout, TimeUnit.MILLISECONDS)) {
+ throw new IOException( "Timeout reading" );
+ }
+ } else {
+ notEmpty.await();
+ }
} catch (InterruptedException e) {
throw (IOException) new InterruptedIOException().initCause(e);
}
@@ -127,9 +135,9 @@ public int readBuffered(char[] b) throws IOException {
} else if (count == 0) {
return READ_EXPIRED;
} else {
- int r = Math.min(b.length, count);
+ int r = Math.min(len, count);
for (int i = 0; i < r; i++) {
- b[i] = buffer[read++];
+ b[off + i] = buffer[read++];
if (read == buffer.length) {
read = 0;
}
diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingReader.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingReader.java
index 0dd3a59e5b0..e2f664f2999 100644
--- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingReader.java
+++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingReader.java
@@ -85,7 +85,15 @@ public int read(char[] b, int off, int len) throws IOException {
return 1;
}
- public abstract int readBuffered(char[] b) throws IOException;
+ public int readBuffered(char[] b) throws IOException {
+ return readBuffered(b, 0L);
+ }
+
+ public int readBuffered(char[] b, long timeout) throws IOException {
+ return readBuffered(b, 0, b.length, timeout);
+ }
+
+ public abstract int readBuffered(char[] b, int off, int len, long timeout) throws IOException;
public int available() {
return 0;
diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingReaderImpl.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingReaderImpl.java
index 7a53d123e9c..d384cc9a0dc 100644
--- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingReaderImpl.java
+++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/NonBlockingReaderImpl.java
@@ -91,10 +91,12 @@ public synchronized boolean ready() throws IOException {
}
@Override
- public int readBuffered(char[] b) throws IOException {
+ public int readBuffered(char[] b, int off, int len, long timeout) throws IOException {
if (b == null) {
throw new NullPointerException();
- } else if (b.length == 0) {
+ } else if (off < 0 || len < 0 || off + len < b.length) {
+ throw new IllegalArgumentException();
+ } else if (len == 0) {
return 0;
} else if (exception != null) {
assert ch == READ_EXPIRED;
@@ -105,15 +107,16 @@ public int readBuffered(char[] b) throws IOException {
b[0] = (char) ch;
ch = READ_EXPIRED;
return 1;
- } else if (!threadIsReading) {
- return in.read(b);
+ } else if (!threadIsReading && timeout <= 0) {
+ return in.read(b, off, len);
} else {
- int c = read(-1, false);
+ // TODO: rework implementation to read as much as possible
+ int c = read(timeout, false);
if (c >= 0) {
- b[0] = (char) c;
+ b[off] = (char) c;
return 1;
} else {
- return -1;
+ return c;
}
}
}
@@ -158,20 +161,17 @@ else if (!isPeek && timeout <= 0L && !threadIsReading) {
notifyAll();
}
- boolean isInfinite = (timeout <= 0L);
-
/*
* So the thread is currently doing the reading for us. So
* now we play the waiting game.
*/
- while (isInfinite || timeout > 0L) {
- long start = System.currentTimeMillis ();
-
+ Timeout t = new Timeout(timeout);
+ while (!t.elapsed()) {
try {
if (Thread.interrupted()) {
throw new InterruptedException();
}
- wait(timeout);
+ wait(t.timeout());
}
catch (InterruptedException e) {
exception = (IOException) new InterruptedIOException().initCause(e);
@@ -190,10 +190,6 @@ else if (!isPeek && timeout <= 0L && !threadIsReading) {
assert exception == null;
break;
}
-
- if (!isInfinite) {
- timeout -= System.currentTimeMillis() - start;
- }
}
}
diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/OSUtils.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/OSUtils.java
index 839a08704f3..97487731852 100644
--- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/OSUtils.java
+++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/OSUtils.java
@@ -9,6 +9,8 @@
package jdk.internal.org.jline.utils;
import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Paths;
public class OSUtils {
@@ -28,6 +30,12 @@ public class OSUtils {
&& (System.getenv("MSYSTEM").startsWith("MINGW")
|| System.getenv("MSYSTEM").equals("MSYS"));
+ public static final boolean IS_WSL = System.getenv("WSL_DISTRO_NAME") != null;
+
+ public static final boolean IS_WSL1 = IS_WSL && System.getenv("WSL_INTEROP") == null;
+
+ public static final boolean IS_WSL2 = IS_WSL && !IS_WSL1;
+
public static final boolean IS_CONEMU = IS_WINDOWS
&& System.getenv("ConEmuPID") != null;
@@ -38,17 +46,20 @@ public class OSUtils {
public static String STTY_COMMAND;
public static String STTY_F_OPTION;
public static String INFOCMP_COMMAND;
+ public static String TEST_COMMAND;
static {
String tty;
String stty;
String sttyfopt;
String infocmp;
+ String test;
if (OSUtils.IS_CYGWIN || OSUtils.IS_MSYSTEM) {
- tty = "tty.exe";
- stty = "stty.exe";
+ tty = null;
+ stty = null;
sttyfopt = null;
- infocmp = "infocmp.exe";
+ infocmp = null;
+ test = null;
String path = System.getenv("PATH");
if (path != null) {
String[] paths = path.split(";");
@@ -62,23 +73,39 @@ public class OSUtils {
if (infocmp == null && new File(p, "infocmp.exe").exists()) {
infocmp = new File(p, "infocmp.exe").getAbsolutePath();
}
+ if (test == null && new File(p, "test.exe").exists()) {
+ test = new File(p, "test.exe").getAbsolutePath();
+ }
}
}
+ if (tty == null) {
+ tty = "tty.exe";
+ }
+ if (stty == null) {
+ stty = "stty.exe";
+ }
+ if (infocmp == null) {
+ infocmp = "infocmp.exe";
+ }
+ if (test == null) {
+ test = "test.exe";
+ }
} else {
tty = "tty";
- stty = "stty";
+ stty = IS_OSX ? "/bin/stty" : "stty";
+ sttyfopt = IS_OSX ? "-f" : "-F";
infocmp = "infocmp";
- if (IS_OSX) {
- sttyfopt = "-f";
- }
- else {
- sttyfopt = "-F";
- }
+ test = isTestCommandValid("/usr/bin/test") ? "/usr/bin/test"
+ : "/bin/test";
}
TTY_COMMAND = tty;
STTY_COMMAND = stty;
STTY_F_OPTION = sttyfopt;
INFOCMP_COMMAND = infocmp;
+ TEST_COMMAND = test;
}
+ private static boolean isTestCommandValid(String command) {
+ return Files.isExecutable(Paths.get(command));
+ }
}
diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/PumpReader.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/PumpReader.java
index fa40360a689..a6894e7672c 100644
--- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/PumpReader.java
+++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/PumpReader.java
@@ -36,7 +36,7 @@ public PumpReader() {
}
public PumpReader(int bufferSize) {
- char[] buf = new char[bufferSize];
+ char[] buf = new char[Math.max(bufferSize, 2)];
this.readBuffer = CharBuffer.wrap(buf);
this.writeBuffer = CharBuffer.wrap(buf);
this.writer = new Writer(this);
@@ -53,13 +53,27 @@ public java.io.InputStream createInputStream(Charset charset) {
return new InputStream(this, charset);
}
- private boolean wait(CharBuffer buffer) throws InterruptedIOException {
- if (closed) {
- return false;
+ /**
+ * Blocks until more input is available, even if {@link #readBuffer} already
+ * contains some chars; or until the reader is closed.
+ *
+ * @return true if more input is available, false if no additional input is
+ * available and the reader is closed
+ * @throws InterruptedIOException If {@link #wait()} is interrupted
+ */
+ private boolean waitForMoreInput() throws InterruptedIOException {
+ if (!writeBuffer.hasRemaining()) {
+ throw new AssertionError("No space in write buffer");
}
- while (!buffer.hasRemaining()) {
- // Wake up waiting readers/writers
+ int oldRemaining = readBuffer.remaining();
+
+ do {
+ if (closed) {
+ return false;
+ }
+
+ // Wake up waiting writers
notifyAll();
try {
@@ -67,19 +81,41 @@ private boolean wait(CharBuffer buffer) throws InterruptedIOException {
} catch (InterruptedException e) {
throw new InterruptedIOException();
}
+ } while (readBuffer.remaining() <= oldRemaining);
+
+ return true;
+ }
+ /**
+ * Waits until {@code buffer.hasRemaining() == true}, or it is false and
+ * the reader is {@link #closed}.
+ *
+ * @return true if {@code buffer.hasRemaining() == true}; false otherwise
+ * when reader is closed
+ */
+ private boolean wait(CharBuffer buffer) throws InterruptedIOException {
+ while (!buffer.hasRemaining()) {
if (closed) {
return false;
}
+
+ // Wake up waiting readers/writers
+ notifyAll();
+
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ throw new InterruptedIOException();
+ }
}
return true;
}
/**
- * Blocks until more input is available or the reader is closed.
+ * Blocks until input is available or the reader is closed.
*
- * @return true if more input is available, false if the reader is closed
+ * @return true if input is available, false if no input is available and the reader is closed
* @throws InterruptedIOException If {@link #wait()} is interrupted
*/
private boolean waitForInput() throws InterruptedIOException {
@@ -94,7 +130,8 @@ private boolean waitForInput() throws InterruptedIOException {
* @throws ClosedException If the reader was closed
*/
private void waitForBufferSpace() throws InterruptedIOException, ClosedException {
- if (!wait(writeBuffer)) {
+ // Check `closed` to throw even if writer buffer has space available
+ if (!wait(writeBuffer) || closed) {
throw new ClosedException();
}
}
@@ -122,7 +159,9 @@ private static boolean rewind(CharBuffer buffer, CharBuffer other) {
* @return If more input is available
*/
private boolean rewindReadBuffer() {
- return rewind(readBuffer, writeBuffer) && readBuffer.hasRemaining();
+ boolean rw = rewind(readBuffer, writeBuffer) && readBuffer.hasRemaining();
+ notifyAll();
+ return rw;
}
/**
@@ -131,6 +170,7 @@ private boolean rewindReadBuffer() {
*/
private void rewindWriteBuffer() {
rewind(writeBuffer, readBuffer);
+ notifyAll();
}
@Override
@@ -202,10 +242,33 @@ public synchronized int read(CharBuffer target) throws IOException {
}
private void encodeBytes(CharsetEncoder encoder, ByteBuffer output) throws IOException {
+ int oldPos = output.position();
CoderResult result = encoder.encode(readBuffer, output, false);
- if (rewindReadBuffer() && result.isUnderflow()) {
- encoder.encode(readBuffer, output, false);
+ int encodedCount = output.position() - oldPos;
+
+ if (result.isUnderflow()) {
+ boolean hasMoreInput = rewindReadBuffer();
+ boolean reachedEndOfInput = false;
+
+ // If encoding did not make any progress must block for more input
+ if (encodedCount == 0 && !hasMoreInput) {
+ reachedEndOfInput = !waitForMoreInput();
+ }
+
+ result = encoder.encode(readBuffer, output, reachedEndOfInput);
+ if (result.isError()) {
+ result.throwException();
+ }
+ if (!reachedEndOfInput && output.position() - oldPos == 0) {
+ throw new AssertionError("Failed to encode any chars");
+ }
rewindReadBuffer();
+ } else if (result.isOverflow()) {
+ if (encodedCount == 0) {
+ throw new AssertionError("Output buffer has not enough space");
+ }
+ } else {
+ result.throwException();
}
}
@@ -334,7 +397,7 @@ private InputStream(PumpReader reader, Charset charset) {
this.encoder = charset.newEncoder()
.onUnmappableCharacter(CodingErrorAction.REPLACE)
.onMalformedInput(CodingErrorAction.REPLACE);
- this.buffer = ByteBuffer.allocate((int) Math.ceil(encoder.maxBytesPerChar()));
+ this.buffer = ByteBuffer.allocate((int) Math.ceil(encoder.maxBytesPerChar() * 2));
// No input available after initialization
buffer.limit(0);
diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/StyleResolver.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/StyleResolver.java
index f2cc61e80a5..be1659957b4 100644
--- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/StyleResolver.java
+++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/StyleResolver.java
@@ -241,7 +241,7 @@ private AttributedStyle applyReference(final AttributedStyle style, final String
if (spec.length() == 1) {
// log.warning("Invalid style-reference; missing discriminator: " + spec);
} else {
- String name = spec.substring(1, spec.length());
+ String name = spec.substring(1);
String resolvedSpec = source.apply(name);
if (resolvedSpec != null) {
return apply(style, resolvedSpec);
diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/Timeout.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/Timeout.java
new file mode 100644
index 00000000000..edea89cf2d9
--- /dev/null
+++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/Timeout.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2002-2018, 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.utils;
+
+/**
+ * Helper class ti use during I/O operations with an eventual timeout.
+ */
+public class Timeout {
+
+ private final long timeout;
+ private long cur = 0;
+ private long end = Long.MAX_VALUE;
+
+ public Timeout(long timeout) {
+ this.timeout = timeout;
+ }
+
+ public boolean isInfinite() {
+ return timeout <= 0;
+ }
+
+ public boolean isFinite() {
+ return timeout > 0;
+ }
+
+ public boolean elapsed() {
+ if (timeout > 0) {
+ cur = System.currentTimeMillis();
+ if (end == Long.MAX_VALUE) {
+ end = cur + timeout;
+ }
+ return cur >= end;
+ } else {
+ return false;
+ }
+ }
+
+ public long timeout() {
+ return timeout > 0 ? Math.max(1, end - cur) : timeout;
+ }
+
+}
diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/WCWidth.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/WCWidth.java
index d20b2e89785..db3a8d3d990 100644
--- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/WCWidth.java
+++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/WCWidth.java
@@ -70,6 +70,7 @@ public static int wcwidth(int ucs)
(ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */
(ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */
(ucs >= 0xffe0 && ucs <= 0xffe6) ||
+ (ucs >= 0x1f000 && ucs <= 0x1feee) ||
(ucs >= 0x20000 && ucs <= 0x2fffd) ||
(ucs >= 0x30000 && ucs <= 0x3fffd))) ? 1 : 0);
}
@@ -123,8 +124,8 @@ public static int wcwidth(int ucs)
new Interval( 0x10A01, 0x10A03 ), new Interval( 0x10A05, 0x10A06 ), new Interval( 0x10A0C, 0x10A0F ),
new Interval( 0x10A38, 0x10A3A ), new Interval( 0x10A3F, 0x10A3F ), new Interval( 0x1D167, 0x1D169 ),
new Interval( 0x1D173, 0x1D182 ), new Interval( 0x1D185, 0x1D18B ), new Interval( 0x1D1AA, 0x1D1AD ),
- new Interval( 0x1D242, 0x1D244 ), new Interval( 0xE0001, 0xE0001 ), new Interval( 0xE0020, 0xE007F ),
- new Interval( 0xE0100, 0xE01EF )
+ new Interval( 0x1D242, 0x1D244 ), new Interval( 0x1F3FB, 0x1F3FF ), new Interval( 0xE0001, 0xE0001 ),
+ new Interval( 0xE0020, 0xE007F ), new Interval( 0xE0100, 0xE01EF )
};
private static class Interval {
diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/windows-vtp.caps b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/windows-vtp.caps
index 39e0623eef3..4ce80158751 100644
--- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/windows-vtp.caps
+++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/utils/windows-vtp.caps
@@ -2,7 +2,7 @@ windows-vtp|windows with virtual terminal processing,
am, mc5i, mir, msgr,
colors#256, cols#80, it#8, lines#24, ncv#3, pairs#64,
bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, clear=\E[H\E[J,
- cr=^M, cub=\E[%p1%dD, cub1=\E[D, cud=\E[%p1%dB, cud1=\E[B,
+ cr=^M, cub=\E[%p1%dD, cub1=\E[D, cud=\E[%p1%dB, cud1=\n,
cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH,
cuu=\E[%p1%dA, cuu1=\E[A,
il=\E[%p1%dL, il1=\E[L,
diff --git a/src/jdk.internal.le/share/classes/module-info.java b/src/jdk.internal.le/share/classes/module-info.java
index 1ece112f1e3..c51ca6ce5cd 100644
--- a/src/jdk.internal.le/share/classes/module-info.java
+++ b/src/jdk.internal.le/share/classes/module-info.java
@@ -56,8 +56,5 @@
exports jdk.internal.org.jline.terminal.spi to
jdk.scripting.nashorn.shell,
jdk.jshell;
-
- uses jdk.internal.org.jline.terminal.spi.JnaSupport;
-
}
diff --git a/src/jdk.internal.le/share/legal/jline.md b/src/jdk.internal.le/share/legal/jline.md
index dc3c460b7ea..4e5d344b4d1 100644
--- a/src/jdk.internal.le/share/legal/jline.md
+++ b/src/jdk.internal.le/share/legal/jline.md
@@ -1,4 +1,4 @@
-## JLine v3.20.0
+## JLine v3.22.0
### JLine License
@@ -41,10 +41,10 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
4th Party Dependency
=============
-org.fusesource.jansi version 1.17.1
-org.apache.sshd 2.1 to 3
-org.apache.felix.gogo.runtime 1.1.2
-org.apache.felix.gogo.jline 1.1.4
+org.fusesource.jansi version 2.4.0
+org.apache.sshd 2.9.2
+org.apache.felix.gogo.runtime 1.1.6
+org.apache.felix.gogo.jline 1.1.8
=============
Apache License
Version 2.0, January 2004
@@ -262,7 +262,7 @@ slf4j
SLF4J source code and binaries are distributed under the MIT license.
-Copyright (c) 2004-2017 QOS.ch
+Copyright (c) 2004-2023 QOS.ch
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining
diff --git a/src/jdk.internal.le/windows/classes/jdk/internal/org/jline/terminal/impl/jna/JnaSupportImpl.java b/src/jdk.internal.le/windows/classes/jdk/internal/org/jline/terminal/impl/jna/JnaSupportImpl.java
deleted file mode 100644
index 061952063cf..00000000000
--- a/src/jdk.internal.le/windows/classes/jdk/internal/org/jline/terminal/impl/jna/JnaSupportImpl.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2002-2019, 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.terminal.impl.jna;
-
-import jdk.internal.org.jline.terminal.Attributes;
-import jdk.internal.org.jline.terminal.Size;
-import jdk.internal.org.jline.terminal.Terminal;
-import jdk.internal.org.jline.terminal.impl.jna.win.JnaWinSysTerminal;
-import jdk.internal.org.jline.terminal.spi.JnaSupport;
-import jdk.internal.org.jline.terminal.spi.Pty;
-import jdk.internal.org.jline.utils.OSUtils;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-import java.util.function.Function;
-
-public class JnaSupportImpl implements JnaSupport {
- @Override
- public Pty current() throws IOException {
-// return JnaNativePty.current();
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Pty open(Attributes attributes, Size size) throws IOException {
-// return JnaNativePty.open(attributes, size);
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Terminal winSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, int codepage, boolean nativeSignals, Terminal.SignalHandler signalHandler) throws IOException {
- return winSysTerminal(name, type, ansiPassThrough, encoding, codepage, nativeSignals, signalHandler, false);
- }
-
- @Override
- public Terminal winSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, int codepage, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused) throws IOException {
- return winSysTerminal(name, type, ansiPassThrough, encoding, codepage, nativeSignals, signalHandler, paused, input -> input);
- }
-
- @Override
- public Terminal winSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, int codepage, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, Function inputStreamWrapper) throws IOException {
- return JnaWinSysTerminal.createTerminal(name, type, ansiPassThrough, encoding, codepage, nativeSignals, signalHandler, paused, inputStreamWrapper);
- }
-
- @Override
- public boolean isWindowsConsole() {
- return JnaWinSysTerminal.isWindowsConsole();
- }
-
- @Override
- public boolean isConsoleOutput() {
- if (OSUtils.IS_CYGWIN || OSUtils.IS_MSYSTEM) {
- throw new UnsupportedOperationException();
- } else if (OSUtils.IS_WINDOWS) {
- return JnaWinSysTerminal.isConsoleOutput();
- }
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean isConsoleInput() {
- if (OSUtils.IS_CYGWIN || OSUtils.IS_MSYSTEM) {
- throw new UnsupportedOperationException();
- } else if (OSUtils.IS_WINDOWS) {
- return JnaWinSysTerminal.isConsoleInput();
- }
- throw new UnsupportedOperationException();
- }
-
-}
diff --git a/src/jdk.internal.le/windows/classes/jdk/internal/org/jline/terminal/impl/jna/JnaTerminalProvider.java b/src/jdk.internal.le/windows/classes/jdk/internal/org/jline/terminal/impl/jna/JnaTerminalProvider.java
new file mode 100644
index 00000000000..b820ce2187e
--- /dev/null
+++ b/src/jdk.internal.le/windows/classes/jdk/internal/org/jline/terminal/impl/jna/JnaTerminalProvider.java
@@ -0,0 +1,106 @@
+/*
+ * 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.terminal.impl.jna;
+
+import jdk.internal.org.jline.terminal.Attributes;
+import jdk.internal.org.jline.terminal.Size;
+import jdk.internal.org.jline.terminal.Terminal;
+import jdk.internal.org.jline.terminal.impl.PosixPtyTerminal;
+import jdk.internal.org.jline.terminal.impl.PosixSysTerminal;
+import jdk.internal.org.jline.terminal.impl.jna.win.JnaWinSysTerminal;
+import jdk.internal.org.jline.terminal.spi.TerminalProvider;
+import jdk.internal.org.jline.terminal.spi.Pty;
+import jdk.internal.org.jline.utils.OSUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.Charset;
+import java.util.function.Function;
+
+public class JnaTerminalProvider implements TerminalProvider
+{
+ @Override
+ public String name() {
+ return "jna";
+ }
+
+// public Pty current(TerminalProvider.Stream console) throws IOException {
+// return JnaNativePty.current(console);
+// }
+//
+// public Pty open(Attributes attributes, Size size) throws IOException {
+// return JnaNativePty.open(attributes, size);
+// }
+
+ @Override
+ public Terminal sysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding,
+ boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused,
+ Stream consoleStream, Function inputStreamWrapper) throws IOException {
+ if (OSUtils.IS_WINDOWS) {
+ return winSysTerminal(name, type, ansiPassThrough, encoding, nativeSignals, signalHandler, paused, consoleStream, inputStreamWrapper );
+ } else {
+ return null;
+ }
+ }
+
+ public Terminal winSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding,
+ boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused,
+ Stream console, Function inputStreamWrapper) throws IOException {
+ return JnaWinSysTerminal.createTerminal(name, type, ansiPassThrough, encoding, nativeSignals, signalHandler, paused, console, inputStreamWrapper);
+ }
+
+// public Terminal posixSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding,
+// boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused,
+// Stream consoleStream) throws IOException {
+// Pty pty = current(consoleStream);
+// return new PosixSysTerminal(name, type, pty, encoding, nativeSignals, signalHandler);
+// }
+
+ @Override
+ public Terminal newTerminal(String name, String type, InputStream in, OutputStream out,
+ Charset encoding, Terminal.SignalHandler signalHandler, boolean paused,
+ Attributes attributes, Size size) throws IOException
+ {
+// Pty pty = open(attributes, size);
+// return new PosixPtyTerminal(name, type, pty, in, out, encoding, signalHandler, paused);
+ return null;
+ }
+
+ @Override
+ public boolean isSystemStream(Stream stream) {
+ try {
+ if (OSUtils.IS_WINDOWS) {
+ return isWindowsSystemStream(stream);
+ } else {
+// return isPosixSystemStream(stream);
+ return false;
+ }
+ } catch (Throwable t) {
+ return false;
+ }
+ }
+
+ public boolean isWindowsSystemStream(Stream stream) {
+ return JnaWinSysTerminal.isWindowsSystemStream(stream);
+ }
+
+// public boolean isPosixSystemStream(Stream stream) {
+// return JnaNativePty.isPosixSystemStream(stream);
+// }
+
+ @Override
+ public String systemStreamName(Stream stream) {
+// if (OSUtils.IS_WINDOWS) {
+ return null;
+// } else {
+// return JnaNativePty.posixSystemStreamName(stream);
+// }
+ }
+}
diff --git a/src/jdk.internal.le/windows/classes/jdk/internal/org/jline/terminal/impl/jna/win/JnaWinConsoleWriter.java b/src/jdk.internal.le/windows/classes/jdk/internal/org/jline/terminal/impl/jna/win/JnaWinConsoleWriter.java
index d2dc21286ac..a4469003c16 100644
--- a/src/jdk.internal.le/windows/classes/jdk/internal/org/jline/terminal/impl/jna/win/JnaWinConsoleWriter.java
+++ b/src/jdk.internal.le/windows/classes/jdk/internal/org/jline/terminal/impl/jna/win/JnaWinConsoleWriter.java
@@ -17,17 +17,17 @@
class JnaWinConsoleWriter extends AbstractWindowsConsoleWriter {
- private final Pointer consoleHandle;
+ private final Pointer console;
private final IntByReference writtenChars = new IntByReference();
- JnaWinConsoleWriter(Pointer consoleHandle) {
- this.consoleHandle = consoleHandle;
+ JnaWinConsoleWriter(Pointer console) {
+ this.console = console;
}
@Override
protected void writeConsole(char[] text, int len) throws IOException {
try {
- Kernel32.INSTANCE.WriteConsoleW(this.consoleHandle, text, len, this.writtenChars, null);
+ Kernel32.INSTANCE.WriteConsoleW(this.console, text, len, this.writtenChars, null);
} catch (LastErrorException e) {
throw new IOException("Failed to write to console", e);
}
diff --git a/src/jdk.internal.le/windows/classes/jdk/internal/org/jline/terminal/impl/jna/win/JnaWinSysTerminal.java b/src/jdk.internal.le/windows/classes/jdk/internal/org/jline/terminal/impl/jna/win/JnaWinSysTerminal.java
index 39e4d219f17..5ffc5d714ed 100644
--- a/src/jdk.internal.le/windows/classes/jdk/internal/org/jline/terminal/impl/jna/win/JnaWinSysTerminal.java
+++ b/src/jdk.internal.le/windows/classes/jdk/internal/org/jline/terminal/impl/jna/win/JnaWinSysTerminal.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002-2019, 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.
@@ -19,11 +19,10 @@
//import com.sun.jna.LastErrorException;
//import com.sun.jna.Pointer;
//import com.sun.jna.ptr.IntByReference;
-
import jdk.internal.org.jline.terminal.Cursor;
import jdk.internal.org.jline.terminal.Size;
-import jdk.internal.org.jline.terminal.Terminal;
import jdk.internal.org.jline.terminal.impl.AbstractWindowsTerminal;
+import jdk.internal.org.jline.terminal.spi.TerminalProvider;
import jdk.internal.org.jline.utils.InfoCmp;
import jdk.internal.org.jline.utils.OSUtils;
@@ -31,38 +30,50 @@ public class JnaWinSysTerminal extends AbstractWindowsTerminal {
private static final Pointer consoleIn = Kernel32.INSTANCE.GetStdHandle(Kernel32.STD_INPUT_HANDLE);
private static final Pointer consoleOut = Kernel32.INSTANCE.GetStdHandle(Kernel32.STD_OUTPUT_HANDLE);
-
- public static JnaWinSysTerminal createTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, int codepage, boolean nativeSignals, SignalHandler signalHandler, boolean paused, Function inputStreamWrapper) throws IOException {
+ private static final Pointer consoleErr = Kernel32.INSTANCE.GetStdHandle(Kernel32.STD_ERROR_HANDLE);
+
+ public static JnaWinSysTerminal createTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, boolean nativeSignals, SignalHandler signalHandler, boolean paused, TerminalProvider.Stream consoleStream, Function inputStreamWrapper) throws IOException {
+ Pointer console;
+ switch (consoleStream) {
+ case Output:
+ console = JnaWinSysTerminal.consoleOut;
+ break;
+ case Error:
+ console = JnaWinSysTerminal.consoleErr;
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupport stream for console: " + consoleStream);
+ }
Writer writer;
if (ansiPassThrough) {
if (type == null) {
type = OSUtils.IS_CONEMU ? TYPE_WINDOWS_CONEMU : TYPE_WINDOWS;
}
- writer = new JnaWinConsoleWriter(consoleOut);
+ writer = new JnaWinConsoleWriter(console);
} else {
IntByReference mode = new IntByReference();
- Kernel32.INSTANCE.GetConsoleMode(consoleOut, mode);
+ Kernel32.INSTANCE.GetConsoleMode(console, mode);
try {
- Kernel32.INSTANCE.SetConsoleMode(consoleOut, mode.getValue() | AbstractWindowsTerminal.ENABLE_VIRTUAL_TERMINAL_PROCESSING);
+ Kernel32.INSTANCE.SetConsoleMode(console, mode.getValue() | AbstractWindowsTerminal.ENABLE_VIRTUAL_TERMINAL_PROCESSING);
if (type == null) {
type = TYPE_WINDOWS_VTP;
}
- writer = new JnaWinConsoleWriter(consoleOut);
+ writer = new JnaWinConsoleWriter(console);
} catch (LastErrorException e) {
if (OSUtils.IS_CONEMU) {
if (type == null) {
type = TYPE_WINDOWS_CONEMU;
}
- writer = new JnaWinConsoleWriter(consoleOut);
+ writer = new JnaWinConsoleWriter(console);
} else {
if (type == null) {
type = TYPE_WINDOWS;
}
- writer = new WindowsAnsiWriter(new BufferedWriter(new JnaWinConsoleWriter(consoleOut)), consoleOut);
+ writer = new WindowsAnsiWriter(new BufferedWriter(new JnaWinConsoleWriter(console)), console);
}
}
}
- JnaWinSysTerminal terminal = new JnaWinSysTerminal(writer, name, type, encoding, codepage, nativeSignals, signalHandler, inputStreamWrapper);
+ JnaWinSysTerminal terminal = new JnaWinSysTerminal(writer, name, type, encoding, nativeSignals, signalHandler, inputStreamWrapper);
// Start input pump thread
if (!paused) {
terminal.resume();
@@ -70,39 +81,26 @@ public static JnaWinSysTerminal createTerminal(String name, String type, boolean
return terminal;
}
- public static boolean isWindowsConsole() {
+ public static boolean isWindowsSystemStream(TerminalProvider.Stream stream) {
try {
IntByReference mode = new IntByReference();
- Kernel32.INSTANCE.GetConsoleMode(consoleOut, mode);
- Kernel32.INSTANCE.GetConsoleMode(consoleIn, mode);
- return true;
- } catch (LastErrorException e) {
- return false;
- }
- }
-
- public static boolean isConsoleOutput() {
- try {
- IntByReference mode = new IntByReference();
- Kernel32.INSTANCE.GetConsoleMode(consoleOut, mode);
- return true;
- } catch (LastErrorException e) {
- return false;
- }
- }
-
- public static boolean isConsoleInput() {
- try {
- IntByReference mode = new IntByReference();
- Kernel32.INSTANCE.GetConsoleMode(consoleIn, mode);
+ Pointer console;
+ switch (stream) {
+ case Input: console = consoleIn; break;
+ case Output: console = consoleOut; break;
+ case Error: console = consoleErr; break;
+ default: return false;
+ }
+ Kernel32.INSTANCE.GetConsoleMode(console, mode);
return true;
} catch (LastErrorException e) {
return false;
}
}
- JnaWinSysTerminal(Writer writer, String name, String type, Charset encoding, int codepage, boolean nativeSignals, SignalHandler signalHandler, Function inputStreamWrapper) throws IOException {
- super(writer, name, type, encoding, codepage, nativeSignals, signalHandler, inputStreamWrapper);
+ JnaWinSysTerminal(Writer writer, String name, String type, Charset encoding, boolean nativeSignals, SignalHandler signalHandler,
+ Function inputStreamWrapper) throws IOException {
+ super(writer, name, type, encoding, nativeSignals, signalHandler, inputStreamWrapper);
strings.put(InfoCmp.Capability.key_mouse, "\\E[M");
}
diff --git a/test/jdk/jdk/internal/jline/AbstractWindowsTerminalTest.java b/test/jdk/jdk/internal/jline/AbstractWindowsTerminalTest.java
index fa4f44162db..d53c9b20309 100644
--- a/test/jdk/jdk/internal/jline/AbstractWindowsTerminalTest.java
+++ b/test/jdk/jdk/internal/jline/AbstractWindowsTerminalTest.java
@@ -56,7 +56,7 @@ public int read() throws IOException {
return is.read();
}
};
- var t = new AbstractWindowsTerminal(out, "test", "vt100", null, -1, false, SignalHandler.SIG_DFL, isWrapper) {
+ var t = new AbstractWindowsTerminal(out, "test", "vt100", null, false, SignalHandler.SIG_DFL, isWrapper) {
@Override
protected int getConsoleMode() {
return -1;
diff --git a/test/jdk/jdk/internal/jline/KeyConversionTest.java b/test/jdk/jdk/internal/jline/KeyConversionTest.java
index 4eadb9a1bf3..aed9a726715 100644
--- a/test/jdk/jdk/internal/jline/KeyConversionTest.java
+++ b/test/jdk/jdk/internal/jline/KeyConversionTest.java
@@ -59,7 +59,7 @@ void run() throws Exception {
void checkKeyConversion(KeyEvent event, String expected) throws IOException {
StringBuilder result = new StringBuilder();
new AbstractWindowsTerminal(new StringWriter(), "", "windows", Charset.forName("UTF-8"),
- 0, true, SignalHandler.SIG_DFL, in -> in) {
+ true, SignalHandler.SIG_DFL, in -> in) {
@Override
protected int getConsoleMode() {
return 0;
diff --git a/src/jdk.internal.le/windows/classes/module-info.java.extra b/test/jdk/jdk/internal/jline/OSUtilsTest.java
similarity index 53%
rename from src/jdk.internal.le/windows/classes/module-info.java.extra
rename to test/jdk/jdk/internal/jline/OSUtilsTest.java
index 3e791de0b36..0494ac24d90 100644
--- a/src/jdk.internal.le/windows/classes/module-info.java.extra
+++ b/test/jdk/jdk/internal/jline/OSUtilsTest.java
@@ -1,12 +1,10 @@
/*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
+ * published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -23,5 +21,32 @@
* questions.
*/
+/**
+ * @test
+ * @bug 8304498
+ * @summary Verify the OSUtils class is initialized properly
+ * @modules jdk.internal.le/jdk.internal.org.jline.utils
+ */
+
+import jdk.internal.org.jline.utils.OSUtils;
+
+public class OSUtilsTest {
+ public static void main(String... args) throws Exception {
+ new OSUtilsTest().run();
+ }
+
+ void run() throws Exception {
+ runTestTest();
+ }
+
+ void runTestTest() throws Exception {
+ if (OSUtils.IS_WINDOWS) {
+ return ; //skip on Windows
+ }
-provides jdk.internal.org.jline.terminal.spi.JnaSupport with jdk.internal.org.jline.terminal.impl.jna.JnaSupportImpl;
+ Process p = new ProcessBuilder(OSUtils.TEST_COMMAND, "-z", "").inheritIO().start();
+ if (p.waitFor() != 0) {
+ throw new AssertionError("Unexpected result!");
+ }
+ }
+}
diff --git a/test/langtools/jdk/jshell/ExecPtyGetFlagsToSetTest.java b/test/langtools/jdk/jshell/ExecPtyGetFlagsToSetTest.java
index 62eac6bd32f..36f96644961 100644
--- a/test/langtools/jdk/jshell/ExecPtyGetFlagsToSetTest.java
+++ b/test/langtools/jdk/jshell/ExecPtyGetFlagsToSetTest.java
@@ -27,6 +27,7 @@
* @summary Control Char check for pty
* @modules jdk.internal.le/jdk.internal.org.jline.terminal
* jdk.internal.le/jdk.internal.org.jline.terminal.impl
+ * jdk.internal.le/jdk.internal.org.jline.terminal.spi
* @requires (os.family == "linux") | (os.family == "aix")
*/
@@ -35,10 +36,11 @@
import jdk.internal.org.jline.terminal.Attributes.ControlChar;
import jdk.internal.org.jline.terminal.Attributes.LocalFlag;
import jdk.internal.org.jline.terminal.impl.ExecPty;
+import jdk.internal.org.jline.terminal.spi.TerminalProvider;
public class ExecPtyGetFlagsToSetTest extends ExecPty {
- public ExecPtyGetFlagsToSetTest(String name, boolean system) {
- super(name, system);
+ public ExecPtyGetFlagsToSetTest(String name, TerminalProvider.Stream stream) {
+ super(name, stream);
}
@Override
@@ -48,7 +50,7 @@ protected List getFlagsToSet(Attributes attr, Attributes current) {
public static void main(String[] args) {
ExecPtyGetFlagsToSetTest testPty =
- new ExecPtyGetFlagsToSetTest("stty", true);
+ new ExecPtyGetFlagsToSetTest("stty", TerminalProvider.Stream.Output);
Attributes attr = new Attributes();
Attributes current = new Attributes();