Skip to content

Commit

Permalink
Update Jansi to 2.4.1 (#106)
Browse files Browse the repository at this point in the history
* Bump Jansi to 2.4.1

* Add workaround for jansi 2.4.1 Windows ARM64 issue

---------

Co-authored-by: Alex Archambault <alexandre.archambault@gmail.com>
  • Loading branch information
Friendseeker and alexarchambault authored Dec 17, 2024
1 parent 6b2b16e commit 9ecdcde
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ lazy val jni = project
shared,
name := "windows-ansi",
libraryDependencies ++= Seq(
"org.fusesource.jansi" % "jansi" % "1.18"
"org.fusesource.jansi" % "jansi" % "2.4.1",
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package io.github.alexarchambault.windowsansi;

import org.fusesource.jansi.internal.Kernel32;
import org.fusesource.jansi.internal.WindowsSupport;

import java.io.IOException;
import java.net.URL;
import java.util.Locale;
import java.util.Objects;

public final class WindowsAnsi {

static {
// Workaround while we can't benefit from https://github.com/fusesource/jansi/pull/292
String arch = System.getProperty("os.arch", "").toLowerCase(Locale.ROOT);
if (arch.equals("arm64") || arch.equals("aarch64")) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL dllUrl = cl.getResource("org/fusesource/jansi/internal/native/Windows/arm64/jansi.dll");
URL soUrl = cl.getResource("org/fusesource/jansi/internal/native/Windows/arm64/libjansi.so");
if (dllUrl == null && soUrl != null) {
System.setProperty("library.jansi.name", "libjansi.so");
}
}

// Make https://github.com/fusesource/hawtjni/blob/c14fec00b9976ff6b84e62e483d678594a7d3832/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime/Library.java#L167 happy
if (System.getProperty("com.ibm.vm.bitmode") == null)
System.setProperty("com.ibm.vm.bitmode", "64");
Expand All @@ -31,7 +43,7 @@ public static boolean setup() throws IOException {
long console = Kernel32.GetStdHandle(Kernel32.STD_OUTPUT_HANDLE);
int[] mode = new int[1];
if (Kernel32.GetConsoleMode(console, mode) == 0)
throw new IOException("Failed to get console mode: " + WindowsSupport.getLastErrorMessage());
throw new IOException("Failed to get console mode: " + Kernel32.getLastErrorMessage());
return Kernel32.SetConsoleMode(console, mode[0] | ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0;
}

Expand Down

0 comments on commit 9ecdcde

Please sign in to comment.