Skip to content

Commit

Permalink
Merge pull request #45 from sschuberth/master
Browse files Browse the repository at this point in the history
Detect Cygwin, including the MSYS(2) forks
  • Loading branch information
chirino committed Apr 26, 2016
2 parents 704633f + 65d955b commit 236d35f
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 236d35f

Please sign in to comment.