Skip to content

Commit 65d955b

Browse files
ylangiscsschuberth
authored andcommitted
Detect Cygwin, including the MSYS(2) forks
Cygwin's default terminal, mintty, is able to process ANSI sequences although it's running on Windows. So treat Cygwin as a Unix variant. Fixes #39.
1 parent 704633f commit 65d955b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen
6161
}
6262

6363
String os = System.getProperty("os.name");
64-
if( os.startsWith("Windows") ) {
64+
if( os.startsWith("Windows") && !isCygwin() ) {
6565

6666
// On windows we know the console does not interpret ANSI codes..
6767
try {
@@ -75,15 +75,15 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen
7575
return new AnsiOutputStream(stream);
7676
}
7777

78-
// We must be on some unix variant..
78+
// We must be on some Unix variant, including Cygwin or MSYS(2) on Windows...
7979
try {
8080
// If the jansi.force property is set, then we force to output
8181
// the ansi escapes for piping it into ansi color aware commands (e.g. less -r)
8282
boolean forceColored = Boolean.getBoolean("jansi.force");
8383
// If we can detect that stdout is not a tty.. then setup
8484
// to strip the ANSI sequences..
8585
int rc = isatty(fileno);
86-
if( !forceColored && rc==0 ) {
86+
if( !isCygwin() && !forceColored && rc == 0 ) {
8787
return new AnsiOutputStream(stream);
8888
}
8989

@@ -105,6 +105,11 @@ public void close() throws IOException {
105105
};
106106
}
107107

108+
private static boolean isCygwin() {
109+
String term = System.getenv("TERM");
110+
return term != null && term.equals("xterm");
111+
}
112+
108113
/**
109114
* If the standard out natively supports ANSI escape codes, then this just
110115
* returns System.out, otherwise it will provide an ANSI aware PrintStream

0 commit comments

Comments
 (0)