Skip to content

Commit d8934d8

Browse files
committedJan 20, 2021
Output of Jansi is corrupted in cygwin console on Windows 7, fixes #190
1 parent 6ace12e commit d8934d8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed
 

‎src/main/java/org/fusesource/jansi/AnsiConsole.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ private static AnsiPrintStream ansiStream(boolean stdout) {
264264
else if (IS_WINDOWS) {
265265
final long console = GetStdHandle(stdout ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);
266266
final int[] mode = new int[1];
267-
if (GetConsoleMode(console, mode) != 0
267+
final boolean isConsole = GetConsoleMode(console, mode) != 0;
268+
if (isConsole
268269
&& SetConsoleMode(console, mode[0] | ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0) {
269270
SetConsoleMode(console, mode[0]); // set it back for now, but we know it works
270271
processor = null;
@@ -285,7 +286,7 @@ public void run() throws IOException {
285286
}
286287
};
287288
}
288-
else if (IS_CONEMU || IS_CYGWIN || IS_MSYSTEM) {
289+
else if ((IS_CONEMU || IS_CYGWIN || IS_MSYSTEM) && !isConsole) {
289290
// ANSI-enabled ConEmu, Cygwin or MSYS(2) on Windows...
290291
processor = null;
291292
type = AnsiType.Native;
@@ -406,7 +407,7 @@ else if (term != null && term.contains("-256color")) {
406407

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

411412
Charset cs = Charset.defaultCharset();
412413
if (enc != null) {

0 commit comments

Comments
 (0)
Please sign in to comment.