--- jline2-jline-2.14.6/src/main/java/jline/AnsiWindowsTerminal.java 2022-05-13 06:20:11.713726341 +0200 +++ jline2-jline-2.14.6/src/main/java/jline/AnsiWindowsTerminal.java 2022-05-13 07:21:11.191259791 +0200 @@ -9,12 +9,17 @@ package jline; import jline.internal.Configuration; +import org.fusesource.jansi.AnsiColors; import org.fusesource.jansi.AnsiConsole; -import org.fusesource.jansi.AnsiOutputStream; -import org.fusesource.jansi.WindowsAnsiOutputStream; +import org.fusesource.jansi.AnsiMode; +import org.fusesource.jansi.AnsiType; + +import org.fusesource.jansi.io.AnsiOutputStream; +import org.fusesource.jansi.io.WindowsAnsiProcessor; import java.io.ByteArrayOutputStream; import java.io.OutputStream; +import java.nio.charset.Charset; /** * ANSI-supported {@link WindowsTerminal}. @@ -42,26 +47,26 @@ if (Configuration.isWindows()) { // On windows we know the console does not interpret ANSI codes.. try { - return new WindowsAnsiOutputStream(stream); + return new AnsiOutputStream(stream, null, AnsiMode.Default, new WindowsAnsiProcessor(stream), AnsiType.Emulation, AnsiColors.Colors16, Charset.defaultCharset(), null, null, false ); } catch (Throwable ignore) { // this happens when JNA is not in the path.. or // this happens when the stdout is being redirected to a file. } // Use the ANSIOutputStream to strip out the ANSI escape sequences. - return new AnsiOutputStream(stream); + return new AnsiOutputStream(stream, null, AnsiMode.Strip, null, AnsiType.Unsupported, AnsiColors.TrueColor, Charset.defaultCharset(), null, null, false); } return stream; } private static boolean detectAnsiSupport() { - OutputStream out = AnsiConsole.wrapOutputStream(new ByteArrayOutputStream()); try { - out.close(); + new WindowsAnsiProcessor(new ByteArrayOutputStream()); + return true; } catch (Exception e) { // ignore; } - return out instanceof WindowsAnsiOutputStream; + return false; } public AnsiWindowsTerminal() throws Exception { --- jline2-jline-2.14.6/src/main/java/jline/internal/Ansi.java 2022-05-13 06:20:11.749726581 +0200 +++ jline2-jline-2.14.6/src/main/java/jline/internal/Ansi.java 2022-05-13 06:20:28.793840511 +0200 @@ -10,8 +10,12 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.nio.charset.Charset; -import org.fusesource.jansi.AnsiOutputStream; +import org.fusesource.jansi.io.AnsiOutputStream; +import org.fusesource.jansi.AnsiColors; +import org.fusesource.jansi.AnsiMode; +import org.fusesource.jansi.AnsiType; /** * Ansi support. @@ -25,7 +29,18 @@ if (str == null) return ""; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - AnsiOutputStream aos = new AnsiOutputStream(baos); + AnsiOutputStream aos = new AnsiOutputStream( + baos, + null, + AnsiMode.Strip, + null, + AnsiType.Emulation, + AnsiColors.TrueColor, + Charset.defaultCharset(), + null, + null, + false + ); aos.write(str.getBytes()); aos.close(); return baos.toString(); --- jline2-jline-2.14.6/src/main/java/jline/WindowsTerminal.java 2022-05-13 06:20:11.717726368 +0200 +++ jline2-jline-2.14.6/src/main/java/jline/WindowsTerminal.java 2022-05-13 06:34:46.083425194 +0200 @@ -15,9 +15,10 @@ import jline.internal.Configuration; import jline.internal.Log; -import org.fusesource.jansi.internal.WindowsSupport; + import org.fusesource.jansi.internal.Kernel32; import static org.fusesource.jansi.internal.Kernel32.*; +import org.fusesource.jansi.internal.Kernel32.CONSOLE_SCREEN_BUFFER_INFO; import static jline.WindowsTerminal.ConsoleMode.ENABLE_ECHO_INPUT; import static jline.WindowsTerminal.ConsoleMode.ENABLE_LINE_INPUT; @@ -208,18 +209,34 @@ // Native Bits // private static int getConsoleMode() { - return WindowsSupport.getConsoleMode(); + long hConsole = GetStdHandle (STD_INPUT_HANDLE); + if (hConsole == INVALID_HANDLE_VALUE) + return -1; + int mode[] = new int[1]; + if (GetConsoleMode (hConsole, mode)==0) + return -1; + return mode[0]; } private static void setConsoleMode(int mode) { - WindowsSupport.setConsoleMode(mode); + long hConsole = GetStdHandle (STD_INPUT_HANDLE); + if (hConsole == INVALID_HANDLE_VALUE) + return; + SetConsoleMode (hConsole, mode); + } + + private static INPUT_RECORD[] readConsoleInput(int count) throws IOException { + long hConsole = GetStdHandle (STD_INPUT_HANDLE); + if (hConsole == INVALID_HANDLE_VALUE) + return null; + return readConsoleKeyInput(hConsole, count, false); } private byte[] readConsoleInput() { // XXX does how many events to read in one call matter? INPUT_RECORD[] events = null; try { - events = WindowsSupport.readConsoleInput(1); + events = readConsoleInput(1); } catch (IOException e) { Log.debug("read Windows console input error: ", e); } @@ -304,11 +321,17 @@ } private static int getWindowsTerminalWidth() { - return WindowsSupport.getWindowsTerminalWidth(); + long outputHandle = GetStdHandle (STD_OUTPUT_HANDLE); + CONSOLE_SCREEN_BUFFER_INFO info = new CONSOLE_SCREEN_BUFFER_INFO(); + GetConsoleScreenBufferInfo (outputHandle, info); + return info.windowWidth(); } private static int getWindowsTerminalHeight() { - return WindowsSupport.getWindowsTerminalHeight(); + long outputHandle = GetStdHandle (STD_OUTPUT_HANDLE); + CONSOLE_SCREEN_BUFFER_INFO info = new CONSOLE_SCREEN_BUFFER_INFO(); + GetConsoleScreenBufferInfo (outputHandle, info); + return info.windowHeight(); } /**