Skip to content

Commit

Permalink
Output of Jansi is corrupted in cygwin console on Windows 7, fixes #190
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jan 20, 2021
1 parent 6ace12e commit d8934d8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/java/org/fusesource/jansi/AnsiConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ private static AnsiPrintStream ansiStream(boolean stdout) {
else if (IS_WINDOWS) {
final long console = GetStdHandle(stdout ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);
final int[] mode = new int[1];
if (GetConsoleMode(console, mode) != 0
final boolean isConsole = GetConsoleMode(console, mode) != 0;
if (isConsole
&& SetConsoleMode(console, mode[0] | ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0) {
SetConsoleMode(console, mode[0]); // set it back for now, but we know it works
processor = null;
Expand All @@ -285,7 +286,7 @@ public void run() throws IOException {
}
};
}
else if (IS_CONEMU || IS_CYGWIN || IS_MSYSTEM) {
else if ((IS_CONEMU || IS_CYGWIN || IS_MSYSTEM) && !isConsole) {
// ANSI-enabled ConEmu, Cygwin or MSYS(2) on Windows...
processor = null;
type = AnsiType.Native;
Expand Down Expand Up @@ -406,7 +407,7 @@ else if (term != null && term.contains("-256color")) {

// If the jansi.noreset property is not set, reset the attributes
// when the stream is closed
boolean resetAtUninstall = !getBoolean(JANSI_NORESET);
boolean resetAtUninstall = type != AnsiType.Unsupported && !getBoolean(JANSI_NORESET);

Charset cs = Charset.defaultCharset();
if (enc != null) {
Expand Down

0 comments on commit d8934d8

Please sign in to comment.