Skip to content

Commit

Permalink
Fix compatibility with jansi < 1.17 on windows, fix #369
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Apr 1, 2019
1 parent 4f100ba commit 1c850e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,28 @@ public class JansiSupportImpl implements JansiSupport {
JANSI_MINOR_VERSION = minor;
}

public static int getJansiMajorVersion() {
return JANSI_MAJOR_VERSION;
}

public static int getJansiMinorVersion() {
return JANSI_MINOR_VERSION;
}

public static boolean isAtLeast(int major, int minor) {
return JANSI_MAJOR_VERSION > major || JANSI_MAJOR_VERSION == major && JANSI_MINOR_VERSION >= minor;
}

@Override
public Pty current() throws IOException {
String osName = System.getProperty("os.name");
if (osName.startsWith("Linux")) {
if (JANSI_MAJOR_VERSION > 1 || JANSI_MAJOR_VERSION == 1 && JANSI_MINOR_VERSION >= 16) {
if (isAtLeast(1, 16)) {
return LinuxNativePty.current();
}
}
else if (osName.startsWith("Mac") || osName.startsWith("Darwin")) {
if (JANSI_MAJOR_VERSION > 1 || JANSI_MAJOR_VERSION == 1 && JANSI_MINOR_VERSION >= 12) {
if (isAtLeast(1, 12)) {
return OsXNativePty.current();
}
}
Expand All @@ -78,7 +90,7 @@ else if (osName.startsWith("Solaris") || osName.startsWith("SunOS")) {
// return SolarisNativePty.current();
}
else if (osName.startsWith("FreeBSD")) {
if (JANSI_MAJOR_VERSION > 1 || JANSI_MAJOR_VERSION == 1 && JANSI_MINOR_VERSION >= 16) {
if (isAtLeast(1, 16)) {
return FreeBsdNativePty.current();
}
}
Expand All @@ -87,7 +99,7 @@ else if (osName.startsWith("FreeBSD")) {

@Override
public Pty open(Attributes attributes, Size size) throws IOException {
if (JANSI_MAJOR_VERSION > 1 || JANSI_MAJOR_VERSION == 1 && JANSI_MINOR_VERSION >= 16) {
if (isAtLeast(1, 16)) {
String osName = System.getProperty("os.name");
if (osName.startsWith("Linux")) {
return LinuxNativePty.open(attributes, size);
Expand All @@ -113,9 +125,9 @@ public Terminal winSysTerminal(String name, String type, boolean ansiPassThrough

@Override
public Terminal winSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, int codepage, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused) throws IOException {
if (JANSI_MAJOR_VERSION > 1 || JANSI_MAJOR_VERSION == 1 && JANSI_MINOR_VERSION >= 12) {
if (isAtLeast(1, 12)) {
JansiWinSysTerminal terminal = JansiWinSysTerminal.createTerminal(name, type, ansiPassThrough, encoding, codepage, nativeSignals, signalHandler, paused);
if (JANSI_MAJOR_VERSION == 1 && JANSI_MINOR_VERSION < 16) {
if (!isAtLeast(1, 16)) {
terminal.disableScrolling();
}
return terminal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.jline.terminal.Size;
import org.jline.terminal.Terminal;
import org.jline.terminal.impl.AbstractWindowsTerminal;
import org.jline.terminal.impl.jansi.JansiSupportImpl;
import org.jline.utils.InfoCmp;

import static org.fusesource.jansi.internal.Kernel32.GetConsoleScreenBufferInfo;
Expand Down Expand Up @@ -106,7 +107,12 @@ public Size getBufferSize() {
}

protected boolean processConsoleInput() throws IOException {
INPUT_RECORD[] events = WindowsSupport.readConsoleInput(1, 100);
INPUT_RECORD[] events;
if (JansiSupportImpl.isAtLeast(1, 17)) {
events = WindowsSupport.readConsoleInput(1, 100);
} else {
events = WindowsSupport.readConsoleInput(1);
}
if (events == null) {
return false;
}
Expand Down

0 comments on commit 1c850e1

Please sign in to comment.