Skip to content

Commit

Permalink
Detect Cygwin, including the MSYS(2) forks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ylangisc authored and sschuberth committed Mar 3, 2016
1 parent 704633f commit 65d955b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen
}

String os = System.getProperty("os.name");
if( os.startsWith("Windows") ) {
if( os.startsWith("Windows") && !isCygwin() ) {

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

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

Expand All @@ -105,6 +105,11 @@ public void close() throws IOException {
};
}

private static boolean isCygwin() {
String term = System.getenv("TERM");
return term != null && term.equals("xterm");
}

/**
* If the standard out natively supports ANSI escape codes, then this just
* returns System.out, otherwise it will provide an ANSI aware PrintStream
Expand Down

0 comments on commit 65d955b

Please sign in to comment.