Skip to content

Commit

Permalink
JNA/Jansi isWindowsConsole() method return true only if both input an…
Browse files Browse the repository at this point in the history
…d output streams are connected to a terminal
  • Loading branch information
mattirn committed Nov 5, 2020
1 parent 542bfb6 commit 1c9f16d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ public static JansiWinSysTerminal createTerminal(String name, String type, boole
}

public static boolean isWindowsConsole() {
long console = GetStdHandle(STD_OUTPUT_HANDLE);
long consoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
long consoleIn = GetStdHandle(STD_INPUT_HANDLE);
int[] mode = new int[1];
return Kernel32.GetConsoleMode(console, mode) == 0;
return Kernel32.GetConsoleMode(consoleOut, mode) != 0 && Kernel32.GetConsoleMode(consoleIn, mode) != 0;
}

JansiWinSysTerminal(Writer writer, String name, String type, Charset encoding, int codepage, boolean nativeSignals, SignalHandler signalHandler) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static boolean isWindowsConsole() {
try {
IntByReference mode = new IntByReference();
Kernel32.INSTANCE.GetConsoleMode(consoleOut, mode);
Kernel32.INSTANCE.GetConsoleMode(consoleIn, mode);
return true;
} catch (LastErrorException e) {
return false;
Expand Down

0 comments on commit 1c9f16d

Please sign in to comment.